@@ -21,7 +21,7 @@ type DescriptorWrapper interface {
2121// WrapDescriptor wraps the given descriptor, returning a desc.Descriptor
2222// value that represents the same element.
2323func WrapDescriptor (d protoreflect.Descriptor ) (Descriptor , error ) {
24- return wrapDescriptor (d , noopCache {})
24+ return wrapDescriptor (d , mapCache {})
2525}
2626
2727func wrapDescriptor (d protoreflect.Descriptor , cache descriptorCache ) (Descriptor , error ) {
@@ -65,18 +65,21 @@ func WrapFiles(d []protoreflect.FileDescriptor) ([]*FileDescriptor, error) {
6565// WrapFile wraps the given file descriptor, returning a *desc.FileDescriptor
6666// value that represents the same file.
6767func WrapFile (d protoreflect.FileDescriptor ) (* FileDescriptor , error ) {
68- return wrapFile (d , noopCache {})
68+ return wrapFile (d , mapCache {})
6969}
7070
7171func wrapFile (d protoreflect.FileDescriptor , cache descriptorCache ) (* FileDescriptor , error ) {
72+ if res := cache .get (d ); res != nil {
73+ return res .(* FileDescriptor ), nil
74+ }
7275 fdp := protoutil .ProtoFromFileDescriptor (d )
7376 return convertFile (d , fdp , cache )
7477}
7578
7679// WrapMessage wraps the given message descriptor, returning a *desc.MessageDescriptor
7780// value that represents the same message.
7881func WrapMessage (d protoreflect.MessageDescriptor ) (* MessageDescriptor , error ) {
79- return wrapMessage (d , noopCache {})
82+ return wrapMessage (d , mapCache {})
8083}
8184
8285func wrapMessage (d protoreflect.MessageDescriptor , cache descriptorCache ) (* MessageDescriptor , error ) {
@@ -97,7 +100,7 @@ func wrapMessage(d protoreflect.MessageDescriptor, cache descriptorCache) (*Mess
97100// WrapField wraps the given field descriptor, returning a *desc.FieldDescriptor
98101// value that represents the same field.
99102func WrapField (d protoreflect.FieldDescriptor ) (* FieldDescriptor , error ) {
100- return wrapField (d , noopCache {})
103+ return wrapField (d , mapCache {})
101104}
102105
103106func wrapField (d protoreflect.FieldDescriptor , cache descriptorCache ) (* FieldDescriptor , error ) {
@@ -121,7 +124,7 @@ func wrapField(d protoreflect.FieldDescriptor, cache descriptorCache) (*FieldDes
121124// WrapOneOf wraps the given oneof descriptor, returning a *desc.OneOfDescriptor
122125// value that represents the same oneof.
123126func WrapOneOf (d protoreflect.OneofDescriptor ) (* OneOfDescriptor , error ) {
124- return wrapOneOf (d , noopCache {})
127+ return wrapOneOf (d , mapCache {})
125128}
126129
127130func wrapOneOf (d protoreflect.OneofDescriptor , cache descriptorCache ) (* OneOfDescriptor , error ) {
@@ -138,7 +141,7 @@ func wrapOneOf(d protoreflect.OneofDescriptor, cache descriptorCache) (*OneOfDes
138141// WrapEnum wraps the given enum descriptor, returning a *desc.EnumDescriptor
139142// value that represents the same enum.
140143func WrapEnum (d protoreflect.EnumDescriptor ) (* EnumDescriptor , error ) {
141- return wrapEnum (d , noopCache {})
144+ return wrapEnum (d , mapCache {})
142145}
143146
144147func wrapEnum (d protoreflect.EnumDescriptor , cache descriptorCache ) (* EnumDescriptor , error ) {
@@ -159,7 +162,7 @@ func wrapEnum(d protoreflect.EnumDescriptor, cache descriptorCache) (*EnumDescri
159162// WrapEnumValue wraps the given enum value descriptor, returning a *desc.EnumValueDescriptor
160163// value that represents the same enum value.
161164func WrapEnumValue (d protoreflect.EnumValueDescriptor ) (* EnumValueDescriptor , error ) {
162- return wrapEnumValue (d , noopCache {})
165+ return wrapEnumValue (d , mapCache {})
163166}
164167
165168func wrapEnumValue (d protoreflect.EnumValueDescriptor , cache descriptorCache ) (* EnumValueDescriptor , error ) {
@@ -176,7 +179,7 @@ func wrapEnumValue(d protoreflect.EnumValueDescriptor, cache descriptorCache) (*
176179// WrapService wraps the given service descriptor, returning a *desc.ServiceDescriptor
177180// value that represents the same service.
178181func WrapService (d protoreflect.ServiceDescriptor ) (* ServiceDescriptor , error ) {
179- return wrapService (d , noopCache {})
182+ return wrapService (d , mapCache {})
180183}
181184
182185func wrapService (d protoreflect.ServiceDescriptor , cache descriptorCache ) (* ServiceDescriptor , error ) {
@@ -193,7 +196,7 @@ func wrapService(d protoreflect.ServiceDescriptor, cache descriptorCache) (*Serv
193196// WrapMethod wraps the given method descriptor, returning a *desc.MethodDescriptor
194197// value that represents the same method.
195198func WrapMethod (d protoreflect.MethodDescriptor ) (* MethodDescriptor , error ) {
196- return wrapMethod (d , noopCache {})
199+ return wrapMethod (d , mapCache {})
197200}
198201
199202func wrapMethod (d protoreflect.MethodDescriptor , cache descriptorCache ) (* MethodDescriptor , error ) {
0 commit comments