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

Function deriveFileDescriptor

descriptor/descriptor.go:121–144  ·  view source on GitHub ↗

map[*byte]*descriptorpb.FileDescriptorProto

(rawDesc []byte)

Source from the content-addressed store, hash-verified

119var fileDescCache sync.Map // map[*byte]*descriptorpb.FileDescriptorProto
120
121func deriveFileDescriptor(rawDesc []byte) *descriptorpb.FileDescriptorProto {
122 // Fast-path: check whether descriptor protos are already cached.
123 if v, ok := fileDescCache.Load(&rawDesc[0]); ok {
124 return v.(*descriptorpb.FileDescriptorProto)
125 }
126
127 // Slow-path: derive the descriptor proto from the GZIP'd message.
128 zr, err := gzip.NewReader(bytes.NewReader(rawDesc))
129 if err != nil {
130 panic(err)
131 }
132 b, err := ioutil.ReadAll(zr)
133 if err != nil {
134 panic(err)
135 }
136 fd := new(descriptorpb.FileDescriptorProto)
137 if err := proto.Unmarshal(b, fd); err != nil {
138 panic(err)
139 }
140 if v, ok := fileDescCache.LoadOrStore(&rawDesc[0], fd); ok {
141 return v.(*descriptorpb.FileDescriptorProto)
142 }
143 return fd
144}
145
146// EnumDescriptorProto returns the file descriptor proto representing
147// the enum and the enum descriptor proto for the enum itself.

Callers 2

EnumDescriptorProtoFunction · 0.85
MessageDescriptorProtoFunction · 0.85

Calls 1

UnmarshalFunction · 0.92

Tested by

no test coverage detected