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

Function ClearExtension

proto/extensions.go:73–92  ·  view source on GitHub ↗

ClearExtension removes the extension field from m either as an explicitly populated field or as an unknown field.

(m Message, xt *ExtensionDesc)

Source from the content-addressed store, hash-verified

71// ClearExtension removes the extension field from m
72// either as an explicitly populated field or as an unknown field.
73func ClearExtension(m Message, xt *ExtensionDesc) {
74 mr := MessageReflect(m)
75 if mr == nil || !mr.IsValid() {
76 return
77 }
78
79 xtd := xt.TypeDescriptor()
80 if isValidExtension(mr.Descriptor(), xtd) {
81 mr.Clear(xtd)
82 } else {
83 mr.Range(func(fd protoreflect.FieldDescriptor, _ protoreflect.Value) bool {
84 if int32(fd.Number()) == xt.Field {
85 mr.Clear(fd)
86 return false
87 }
88 return true
89 })
90 }
91 clearUnknown(mr, fieldNum(xt.Field))
92}
93
94// ClearAllExtensions clears all extensions from m.
95// This includes populated fields and unknown fields in the extension range.

Callers 4

TestGetExtensionDefaultsFunction · 0.92
TestNilMessageFunction · 0.92
TestExtensionsRoundTripFunction · 0.92
SetRawExtensionFunction · 0.85

Calls 5

MessageReflectFunction · 0.85
isValidExtensionFunction · 0.85
clearUnknownFunction · 0.85
fieldNumTypeAlias · 0.85
DescriptorMethod · 0.65

Tested by 3

TestGetExtensionDefaultsFunction · 0.74
TestNilMessageFunction · 0.74
TestExtensionsRoundTripFunction · 0.74

Used in the wild real call sites across dependent graphs

searching dependent graphs…