MCPcopy
hub / github.com/golang/protobuf / DiscardUnknown

Function DiscardUnknown

proto/discard.go:19–23  ·  view source on GitHub ↗

DiscardUnknown recursively discards all unknown fields from this message and all embedded messages. When unmarshaling a message with unrecognized fields, the tags and values of such fields are preserved in the Message. This allows a later call to marshal to be able to produce a message that continu

(m Message)

Source from the content-addressed store, hash-verified

17// unrecognized fields. To avoid this, DiscardUnknown is used to
18// explicitly clear the unknown fields after unmarshaling.
19func DiscardUnknown(m Message) {
20 if m != nil {
21 discardUnknown(MessageReflect(m))
22 }
23}
24
25func discardUnknown(m protoreflect.Message) {
26 m.Range(func(fd protoreflect.FieldDescriptor, val protoreflect.Value) bool {

Callers 3

TestDiscardUnknownFunction · 0.92
TestBadWireTypeUnknownFunction · 0.92
DiscardUnknownMethod · 0.85

Calls 2

discardUnknownFunction · 0.85
MessageReflectFunction · 0.85

Tested by 2

TestDiscardUnknownFunction · 0.74
TestBadWireTypeUnknownFunction · 0.74