map[*byte]*descriptorpb.FileDescriptorProto
(rawDesc []byte)
| 119 | var fileDescCache sync.Map // map[*byte]*descriptorpb.FileDescriptorProto |
| 120 | |
| 121 | func 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. |
no test coverage detected