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

Function RegisteredExtensions

proto/registry.go:292–317  ·  view source on GitHub ↗

map[messageName]extensionsByNumber RegisteredExtensions returns a map of the registered extensions for the provided protobuf message, indexed by the extension field number. Deprecated: Use protoregistry.GlobalTypes.RangeExtensionsByMessage instead.

(m Message)

Source from the content-addressed store, hash-verified

290//
291// Deprecated: Use protoregistry.GlobalTypes.RangeExtensionsByMessage instead.
292func RegisteredExtensions(m Message) extensionsByNumber {
293 // Check whether the cache is stale. If the number of extensions for
294 // the given message differs, then it means that some extensions were
295 // recently registered upstream that we do not know about.
296 s := MessageName(m)
297 v, _ := extensionCache.Load(s)
298 xs, _ := v.(extensionsByNumber)
299 if protoregistry.GlobalTypes.NumExtensionsByMessage(protoreflect.FullName(s)) == len(xs) {
300 return xs // cache is up-to-date
301 }
302
303 // Cache is stale, re-compute the extensions map.
304 xs = make(extensionsByNumber)
305 protoregistry.GlobalTypes.RangeExtensionsByMessage(protoreflect.FullName(s), func(xt protoreflect.ExtensionType) bool {
306 if xd, ok := xt.(*ExtensionDesc); ok {
307 xs[int32(xt.TypeDescriptor().Number())] = xd
308 } else {
309 // TODO: This implies that the protoreflect.ExtensionType is a
310 // custom type not generated by protoc-gen-go. We could try and
311 // convert the type to an ExtensionDesc.
312 }
313 return true
314 })
315 extensionCache.Store(s, xs)
316 return xs
317}

Callers 1

initFunction · 0.92

Calls 1

MessageNameFunction · 0.85

Tested by 1

initFunction · 0.74