41 once uint32 // atomically set if L2 is valid |
41 once uint32 // atomically set if L2 is valid |
42 mu sync.Mutex // protects L2 |
42 mu sync.Mutex // protects L2 |
43 L2 *FileL2 |
43 L2 *FileL2 |
44 } |
44 } |
45 FileL1 struct { |
45 FileL1 struct { |
46 Syntax pref.Syntax |
46 Syntax protoreflect.Syntax |
47 Path string |
47 Path string |
48 Package pref.FullName |
48 Package protoreflect.FullName |
49 |
49 |
50 Enums Enums |
50 Enums Enums |
51 Messages Messages |
51 Messages Messages |
52 Extensions Extensions |
52 Extensions Extensions |
53 Services Services |
53 Services Services |
54 } |
54 } |
55 FileL2 struct { |
55 FileL2 struct { |
56 Options func() pref.ProtoMessage |
56 Options func() protoreflect.ProtoMessage |
57 Imports FileImports |
57 Imports FileImports |
58 Locations SourceLocations |
58 Locations SourceLocations |
59 } |
59 } |
60 ) |
60 ) |
61 |
61 |
62 func (fd *File) ParentFile() pref.FileDescriptor { return fd } |
62 func (fd *File) ParentFile() protoreflect.FileDescriptor { return fd } |
63 func (fd *File) Parent() pref.Descriptor { return nil } |
63 func (fd *File) Parent() protoreflect.Descriptor { return nil } |
64 func (fd *File) Index() int { return 0 } |
64 func (fd *File) Index() int { return 0 } |
65 func (fd *File) Syntax() pref.Syntax { return fd.L1.Syntax } |
65 func (fd *File) Syntax() protoreflect.Syntax { return fd.L1.Syntax } |
66 func (fd *File) Name() pref.Name { return fd.L1.Package.Name() } |
66 func (fd *File) Name() protoreflect.Name { return fd.L1.Package.Name() } |
67 func (fd *File) FullName() pref.FullName { return fd.L1.Package } |
67 func (fd *File) FullName() protoreflect.FullName { return fd.L1.Package } |
68 func (fd *File) IsPlaceholder() bool { return false } |
68 func (fd *File) IsPlaceholder() bool { return false } |
69 func (fd *File) Options() pref.ProtoMessage { |
69 func (fd *File) Options() protoreflect.ProtoMessage { |
70 if f := fd.lazyInit().Options; f != nil { |
70 if f := fd.lazyInit().Options; f != nil { |
71 return f() |
71 return f() |
72 } |
72 } |
73 return descopts.File |
73 return descopts.File |
74 } |
74 } |
75 func (fd *File) Path() string { return fd.L1.Path } |
75 func (fd *File) Path() string { return fd.L1.Path } |
76 func (fd *File) Package() pref.FullName { return fd.L1.Package } |
76 func (fd *File) Package() protoreflect.FullName { return fd.L1.Package } |
77 func (fd *File) Imports() pref.FileImports { return &fd.lazyInit().Imports } |
77 func (fd *File) Imports() protoreflect.FileImports { return &fd.lazyInit().Imports } |
78 func (fd *File) Enums() pref.EnumDescriptors { return &fd.L1.Enums } |
78 func (fd *File) Enums() protoreflect.EnumDescriptors { return &fd.L1.Enums } |
79 func (fd *File) Messages() pref.MessageDescriptors { return &fd.L1.Messages } |
79 func (fd *File) Messages() protoreflect.MessageDescriptors { return &fd.L1.Messages } |
80 func (fd *File) Extensions() pref.ExtensionDescriptors { return &fd.L1.Extensions } |
80 func (fd *File) Extensions() protoreflect.ExtensionDescriptors { return &fd.L1.Extensions } |
81 func (fd *File) Services() pref.ServiceDescriptors { return &fd.L1.Services } |
81 func (fd *File) Services() protoreflect.ServiceDescriptors { return &fd.L1.Services } |
82 func (fd *File) SourceLocations() pref.SourceLocations { return &fd.lazyInit().Locations } |
82 func (fd *File) SourceLocations() protoreflect.SourceLocations { return &fd.lazyInit().Locations } |
83 func (fd *File) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) } |
83 func (fd *File) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) } |
84 func (fd *File) ProtoType(pref.FileDescriptor) {} |
84 func (fd *File) ProtoType(protoreflect.FileDescriptor) {} |
85 func (fd *File) ProtoInternal(pragma.DoNotImplement) {} |
85 func (fd *File) ProtoInternal(pragma.DoNotImplement) {} |
86 |
86 |
87 func (fd *File) lazyInit() *FileL2 { |
87 func (fd *File) lazyInit() *FileL2 { |
88 if atomic.LoadUint32(&fd.once) == 0 { |
88 if atomic.LoadUint32(&fd.once) == 0 { |
89 fd.lazyInitOnce() |
89 fd.lazyInitOnce() |
90 } |
90 } |
117 } |
117 } |
118 EnumL1 struct { |
118 EnumL1 struct { |
119 eagerValues bool // controls whether EnumL2.Values is already populated |
119 eagerValues bool // controls whether EnumL2.Values is already populated |
120 } |
120 } |
121 EnumL2 struct { |
121 EnumL2 struct { |
122 Options func() pref.ProtoMessage |
122 Options func() protoreflect.ProtoMessage |
123 Values EnumValues |
123 Values EnumValues |
124 ReservedNames Names |
124 ReservedNames Names |
125 ReservedRanges EnumRanges |
125 ReservedRanges EnumRanges |
126 } |
126 } |
127 |
127 |
128 EnumValue struct { |
128 EnumValue struct { |
129 Base |
129 Base |
130 L1 EnumValueL1 |
130 L1 EnumValueL1 |
131 } |
131 } |
132 EnumValueL1 struct { |
132 EnumValueL1 struct { |
133 Options func() pref.ProtoMessage |
133 Options func() protoreflect.ProtoMessage |
134 Number pref.EnumNumber |
134 Number protoreflect.EnumNumber |
135 } |
135 } |
136 ) |
136 ) |
137 |
137 |
138 func (ed *Enum) Options() pref.ProtoMessage { |
138 func (ed *Enum) Options() protoreflect.ProtoMessage { |
139 if f := ed.lazyInit().Options; f != nil { |
139 if f := ed.lazyInit().Options; f != nil { |
140 return f() |
140 return f() |
141 } |
141 } |
142 return descopts.Enum |
142 return descopts.Enum |
143 } |
143 } |
144 func (ed *Enum) Values() pref.EnumValueDescriptors { |
144 func (ed *Enum) Values() protoreflect.EnumValueDescriptors { |
145 if ed.L1.eagerValues { |
145 if ed.L1.eagerValues { |
146 return &ed.L2.Values |
146 return &ed.L2.Values |
147 } |
147 } |
148 return &ed.lazyInit().Values |
148 return &ed.lazyInit().Values |
149 } |
149 } |
150 func (ed *Enum) ReservedNames() pref.Names { return &ed.lazyInit().ReservedNames } |
150 func (ed *Enum) ReservedNames() protoreflect.Names { return &ed.lazyInit().ReservedNames } |
151 func (ed *Enum) ReservedRanges() pref.EnumRanges { return &ed.lazyInit().ReservedRanges } |
151 func (ed *Enum) ReservedRanges() protoreflect.EnumRanges { return &ed.lazyInit().ReservedRanges } |
152 func (ed *Enum) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) } |
152 func (ed *Enum) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) } |
153 func (ed *Enum) ProtoType(pref.EnumDescriptor) {} |
153 func (ed *Enum) ProtoType(protoreflect.EnumDescriptor) {} |
154 func (ed *Enum) lazyInit() *EnumL2 { |
154 func (ed *Enum) lazyInit() *EnumL2 { |
155 ed.L0.ParentFile.lazyInit() // implicitly initializes L2 |
155 ed.L0.ParentFile.lazyInit() // implicitly initializes L2 |
156 return ed.L2 |
156 return ed.L2 |
157 } |
157 } |
158 |
158 |
159 func (ed *EnumValue) Options() pref.ProtoMessage { |
159 func (ed *EnumValue) Options() protoreflect.ProtoMessage { |
160 if f := ed.L1.Options; f != nil { |
160 if f := ed.L1.Options; f != nil { |
161 return f() |
161 return f() |
162 } |
162 } |
163 return descopts.EnumValue |
163 return descopts.EnumValue |
164 } |
164 } |
165 func (ed *EnumValue) Number() pref.EnumNumber { return ed.L1.Number } |
165 func (ed *EnumValue) Number() protoreflect.EnumNumber { return ed.L1.Number } |
166 func (ed *EnumValue) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) } |
166 func (ed *EnumValue) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, ed) } |
167 func (ed *EnumValue) ProtoType(pref.EnumValueDescriptor) {} |
167 func (ed *EnumValue) ProtoType(protoreflect.EnumValueDescriptor) {} |
168 |
168 |
169 type ( |
169 type ( |
170 Message struct { |
170 Message struct { |
171 Base |
171 Base |
172 L1 MessageL1 |
172 L1 MessageL1 |
178 Extensions Extensions |
178 Extensions Extensions |
179 IsMapEntry bool // promoted from google.protobuf.MessageOptions |
179 IsMapEntry bool // promoted from google.protobuf.MessageOptions |
180 IsMessageSet bool // promoted from google.protobuf.MessageOptions |
180 IsMessageSet bool // promoted from google.protobuf.MessageOptions |
181 } |
181 } |
182 MessageL2 struct { |
182 MessageL2 struct { |
183 Options func() pref.ProtoMessage |
183 Options func() protoreflect.ProtoMessage |
184 Fields Fields |
184 Fields Fields |
185 Oneofs Oneofs |
185 Oneofs Oneofs |
186 ReservedNames Names |
186 ReservedNames Names |
187 ReservedRanges FieldRanges |
187 ReservedRanges FieldRanges |
188 RequiredNumbers FieldNumbers // must be consistent with Fields.Cardinality |
188 RequiredNumbers FieldNumbers // must be consistent with Fields.Cardinality |
189 ExtensionRanges FieldRanges |
189 ExtensionRanges FieldRanges |
190 ExtensionRangeOptions []func() pref.ProtoMessage // must be same length as ExtensionRanges |
190 ExtensionRangeOptions []func() protoreflect.ProtoMessage // must be same length as ExtensionRanges |
191 } |
191 } |
192 |
192 |
193 Field struct { |
193 Field struct { |
194 Base |
194 Base |
195 L1 FieldL1 |
195 L1 FieldL1 |
196 } |
196 } |
197 FieldL1 struct { |
197 FieldL1 struct { |
198 Options func() pref.ProtoMessage |
198 Options func() protoreflect.ProtoMessage |
199 Number pref.FieldNumber |
199 Number protoreflect.FieldNumber |
200 Cardinality pref.Cardinality // must be consistent with Message.RequiredNumbers |
200 Cardinality protoreflect.Cardinality // must be consistent with Message.RequiredNumbers |
201 Kind pref.Kind |
201 Kind protoreflect.Kind |
202 StringName stringName |
202 StringName stringName |
203 IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto |
203 IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto |
204 IsWeak bool // promoted from google.protobuf.FieldOptions |
204 IsWeak bool // promoted from google.protobuf.FieldOptions |
205 HasPacked bool // promoted from google.protobuf.FieldOptions |
205 HasPacked bool // promoted from google.protobuf.FieldOptions |
206 IsPacked bool // promoted from google.protobuf.FieldOptions |
206 IsPacked bool // promoted from google.protobuf.FieldOptions |
207 HasEnforceUTF8 bool // promoted from google.protobuf.FieldOptions |
207 HasEnforceUTF8 bool // promoted from google.protobuf.FieldOptions |
208 EnforceUTF8 bool // promoted from google.protobuf.FieldOptions |
208 EnforceUTF8 bool // promoted from google.protobuf.FieldOptions |
209 Default defaultValue |
209 Default defaultValue |
210 ContainingOneof pref.OneofDescriptor // must be consistent with Message.Oneofs.Fields |
210 ContainingOneof protoreflect.OneofDescriptor // must be consistent with Message.Oneofs.Fields |
211 Enum pref.EnumDescriptor |
211 Enum protoreflect.EnumDescriptor |
212 Message pref.MessageDescriptor |
212 Message protoreflect.MessageDescriptor |
213 } |
213 } |
214 |
214 |
215 Oneof struct { |
215 Oneof struct { |
216 Base |
216 Base |
217 L1 OneofL1 |
217 L1 OneofL1 |
218 } |
218 } |
219 OneofL1 struct { |
219 OneofL1 struct { |
220 Options func() pref.ProtoMessage |
220 Options func() protoreflect.ProtoMessage |
221 Fields OneofFields // must be consistent with Message.Fields.ContainingOneof |
221 Fields OneofFields // must be consistent with Message.Fields.ContainingOneof |
222 } |
222 } |
223 ) |
223 ) |
224 |
224 |
225 func (md *Message) Options() pref.ProtoMessage { |
225 func (md *Message) Options() protoreflect.ProtoMessage { |
226 if f := md.lazyInit().Options; f != nil { |
226 if f := md.lazyInit().Options; f != nil { |
227 return f() |
227 return f() |
228 } |
228 } |
229 return descopts.Message |
229 return descopts.Message |
230 } |
230 } |
231 func (md *Message) IsMapEntry() bool { return md.L1.IsMapEntry } |
231 func (md *Message) IsMapEntry() bool { return md.L1.IsMapEntry } |
232 func (md *Message) Fields() pref.FieldDescriptors { return &md.lazyInit().Fields } |
232 func (md *Message) Fields() protoreflect.FieldDescriptors { return &md.lazyInit().Fields } |
233 func (md *Message) Oneofs() pref.OneofDescriptors { return &md.lazyInit().Oneofs } |
233 func (md *Message) Oneofs() protoreflect.OneofDescriptors { return &md.lazyInit().Oneofs } |
234 func (md *Message) ReservedNames() pref.Names { return &md.lazyInit().ReservedNames } |
234 func (md *Message) ReservedNames() protoreflect.Names { return &md.lazyInit().ReservedNames } |
235 func (md *Message) ReservedRanges() pref.FieldRanges { return &md.lazyInit().ReservedRanges } |
235 func (md *Message) ReservedRanges() protoreflect.FieldRanges { return &md.lazyInit().ReservedRanges } |
236 func (md *Message) RequiredNumbers() pref.FieldNumbers { return &md.lazyInit().RequiredNumbers } |
236 func (md *Message) RequiredNumbers() protoreflect.FieldNumbers { return &md.lazyInit().RequiredNumbers } |
237 func (md *Message) ExtensionRanges() pref.FieldRanges { return &md.lazyInit().ExtensionRanges } |
237 func (md *Message) ExtensionRanges() protoreflect.FieldRanges { return &md.lazyInit().ExtensionRanges } |
238 func (md *Message) ExtensionRangeOptions(i int) pref.ProtoMessage { |
238 func (md *Message) ExtensionRangeOptions(i int) protoreflect.ProtoMessage { |
239 if f := md.lazyInit().ExtensionRangeOptions[i]; f != nil { |
239 if f := md.lazyInit().ExtensionRangeOptions[i]; f != nil { |
240 return f() |
240 return f() |
241 } |
241 } |
242 return descopts.ExtensionRange |
242 return descopts.ExtensionRange |
243 } |
243 } |
244 func (md *Message) Enums() pref.EnumDescriptors { return &md.L1.Enums } |
244 func (md *Message) Enums() protoreflect.EnumDescriptors { return &md.L1.Enums } |
245 func (md *Message) Messages() pref.MessageDescriptors { return &md.L1.Messages } |
245 func (md *Message) Messages() protoreflect.MessageDescriptors { return &md.L1.Messages } |
246 func (md *Message) Extensions() pref.ExtensionDescriptors { return &md.L1.Extensions } |
246 func (md *Message) Extensions() protoreflect.ExtensionDescriptors { return &md.L1.Extensions } |
247 func (md *Message) ProtoType(pref.MessageDescriptor) {} |
247 func (md *Message) ProtoType(protoreflect.MessageDescriptor) {} |
248 func (md *Message) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) } |
248 func (md *Message) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) } |
249 func (md *Message) lazyInit() *MessageL2 { |
249 func (md *Message) lazyInit() *MessageL2 { |
250 md.L0.ParentFile.lazyInit() // implicitly initializes L2 |
250 md.L0.ParentFile.lazyInit() // implicitly initializes L2 |
251 return md.L2 |
251 return md.L2 |
252 } |
252 } |
253 |
253 |
258 // removed in the future without warning. |
258 // removed in the future without warning. |
259 func (md *Message) IsMessageSet() bool { |
259 func (md *Message) IsMessageSet() bool { |
260 return md.L1.IsMessageSet |
260 return md.L1.IsMessageSet |
261 } |
261 } |
262 |
262 |
263 func (fd *Field) Options() pref.ProtoMessage { |
263 func (fd *Field) Options() protoreflect.ProtoMessage { |
264 if f := fd.L1.Options; f != nil { |
264 if f := fd.L1.Options; f != nil { |
265 return f() |
265 return f() |
266 } |
266 } |
267 return descopts.Field |
267 return descopts.Field |
268 } |
268 } |
269 func (fd *Field) Number() pref.FieldNumber { return fd.L1.Number } |
269 func (fd *Field) Number() protoreflect.FieldNumber { return fd.L1.Number } |
270 func (fd *Field) Cardinality() pref.Cardinality { return fd.L1.Cardinality } |
270 func (fd *Field) Cardinality() protoreflect.Cardinality { return fd.L1.Cardinality } |
271 func (fd *Field) Kind() pref.Kind { return fd.L1.Kind } |
271 func (fd *Field) Kind() protoreflect.Kind { return fd.L1.Kind } |
272 func (fd *Field) HasJSONName() bool { return fd.L1.StringName.hasJSON } |
272 func (fd *Field) HasJSONName() bool { return fd.L1.StringName.hasJSON } |
273 func (fd *Field) JSONName() string { return fd.L1.StringName.getJSON(fd) } |
273 func (fd *Field) JSONName() string { return fd.L1.StringName.getJSON(fd) } |
274 func (fd *Field) TextName() string { return fd.L1.StringName.getText(fd) } |
274 func (fd *Field) TextName() string { return fd.L1.StringName.getText(fd) } |
275 func (fd *Field) HasPresence() bool { |
275 func (fd *Field) HasPresence() bool { |
276 return fd.L1.Cardinality != pref.Repeated && (fd.L0.ParentFile.L1.Syntax == pref.Proto2 || fd.L1.Message != nil || fd.L1.ContainingOneof != nil) |
276 return fd.L1.Cardinality != protoreflect.Repeated && (fd.L0.ParentFile.L1.Syntax == protoreflect.Proto2 || fd.L1.Message != nil || fd.L1.ContainingOneof != nil) |
277 } |
277 } |
278 func (fd *Field) HasOptionalKeyword() bool { |
278 func (fd *Field) HasOptionalKeyword() bool { |
279 return (fd.L0.ParentFile.L1.Syntax == pref.Proto2 && fd.L1.Cardinality == pref.Optional && fd.L1.ContainingOneof == nil) || fd.L1.IsProto3Optional |
279 return (fd.L0.ParentFile.L1.Syntax == protoreflect.Proto2 && fd.L1.Cardinality == protoreflect.Optional && fd.L1.ContainingOneof == nil) || fd.L1.IsProto3Optional |
280 } |
280 } |
281 func (fd *Field) IsPacked() bool { |
281 func (fd *Field) IsPacked() bool { |
282 if !fd.L1.HasPacked && fd.L0.ParentFile.L1.Syntax != pref.Proto2 && fd.L1.Cardinality == pref.Repeated { |
282 if !fd.L1.HasPacked && fd.L0.ParentFile.L1.Syntax != protoreflect.Proto2 && fd.L1.Cardinality == protoreflect.Repeated { |
283 switch fd.L1.Kind { |
283 switch fd.L1.Kind { |
284 case pref.StringKind, pref.BytesKind, pref.MessageKind, pref.GroupKind: |
284 case protoreflect.StringKind, protoreflect.BytesKind, protoreflect.MessageKind, protoreflect.GroupKind: |
285 default: |
285 default: |
286 return true |
286 return true |
287 } |
287 } |
288 } |
288 } |
289 return fd.L1.IsPacked |
289 return fd.L1.IsPacked |
290 } |
290 } |
291 func (fd *Field) IsExtension() bool { return false } |
291 func (fd *Field) IsExtension() bool { return false } |
292 func (fd *Field) IsWeak() bool { return fd.L1.IsWeak } |
292 func (fd *Field) IsWeak() bool { return fd.L1.IsWeak } |
293 func (fd *Field) IsList() bool { return fd.Cardinality() == pref.Repeated && !fd.IsMap() } |
293 func (fd *Field) IsList() bool { return fd.Cardinality() == protoreflect.Repeated && !fd.IsMap() } |
294 func (fd *Field) IsMap() bool { return fd.Message() != nil && fd.Message().IsMapEntry() } |
294 func (fd *Field) IsMap() bool { return fd.Message() != nil && fd.Message().IsMapEntry() } |
295 func (fd *Field) MapKey() pref.FieldDescriptor { |
295 func (fd *Field) MapKey() protoreflect.FieldDescriptor { |
296 if !fd.IsMap() { |
296 if !fd.IsMap() { |
297 return nil |
297 return nil |
298 } |
298 } |
299 return fd.Message().Fields().ByNumber(genid.MapEntry_Key_field_number) |
299 return fd.Message().Fields().ByNumber(genid.MapEntry_Key_field_number) |
300 } |
300 } |
301 func (fd *Field) MapValue() pref.FieldDescriptor { |
301 func (fd *Field) MapValue() protoreflect.FieldDescriptor { |
302 if !fd.IsMap() { |
302 if !fd.IsMap() { |
303 return nil |
303 return nil |
304 } |
304 } |
305 return fd.Message().Fields().ByNumber(genid.MapEntry_Value_field_number) |
305 return fd.Message().Fields().ByNumber(genid.MapEntry_Value_field_number) |
306 } |
306 } |
307 func (fd *Field) HasDefault() bool { return fd.L1.Default.has } |
307 func (fd *Field) HasDefault() bool { return fd.L1.Default.has } |
308 func (fd *Field) Default() pref.Value { return fd.L1.Default.get(fd) } |
308 func (fd *Field) Default() protoreflect.Value { return fd.L1.Default.get(fd) } |
309 func (fd *Field) DefaultEnumValue() pref.EnumValueDescriptor { return fd.L1.Default.enum } |
309 func (fd *Field) DefaultEnumValue() protoreflect.EnumValueDescriptor { return fd.L1.Default.enum } |
310 func (fd *Field) ContainingOneof() pref.OneofDescriptor { return fd.L1.ContainingOneof } |
310 func (fd *Field) ContainingOneof() protoreflect.OneofDescriptor { return fd.L1.ContainingOneof } |
311 func (fd *Field) ContainingMessage() pref.MessageDescriptor { |
311 func (fd *Field) ContainingMessage() protoreflect.MessageDescriptor { |
312 return fd.L0.Parent.(pref.MessageDescriptor) |
312 return fd.L0.Parent.(protoreflect.MessageDescriptor) |
313 } |
313 } |
314 func (fd *Field) Enum() pref.EnumDescriptor { |
314 func (fd *Field) Enum() protoreflect.EnumDescriptor { |
315 return fd.L1.Enum |
315 return fd.L1.Enum |
316 } |
316 } |
317 func (fd *Field) Message() pref.MessageDescriptor { |
317 func (fd *Field) Message() protoreflect.MessageDescriptor { |
318 if fd.L1.IsWeak { |
318 if fd.L1.IsWeak { |
319 if d, _ := protoregistry.GlobalFiles.FindDescriptorByName(fd.L1.Message.FullName()); d != nil { |
319 if d, _ := protoregistry.GlobalFiles.FindDescriptorByName(fd.L1.Message.FullName()); d != nil { |
320 return d.(pref.MessageDescriptor) |
320 return d.(protoreflect.MessageDescriptor) |
321 } |
321 } |
322 } |
322 } |
323 return fd.L1.Message |
323 return fd.L1.Message |
324 } |
324 } |
325 func (fd *Field) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) } |
325 func (fd *Field) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, fd) } |
326 func (fd *Field) ProtoType(pref.FieldDescriptor) {} |
326 func (fd *Field) ProtoType(protoreflect.FieldDescriptor) {} |
327 |
327 |
328 // EnforceUTF8 is a pseudo-internal API to determine whether to enforce UTF-8 |
328 // EnforceUTF8 is a pseudo-internal API to determine whether to enforce UTF-8 |
329 // validation for the string field. This exists for Google-internal use only |
329 // validation for the string field. This exists for Google-internal use only |
330 // since proto3 did not enforce UTF-8 validity prior to the open-source release. |
330 // since proto3 did not enforce UTF-8 validity prior to the open-source release. |
331 // If this method does not exist, the default is to enforce valid UTF-8. |
331 // If this method does not exist, the default is to enforce valid UTF-8. |
334 // removed in the future without warning. |
334 // removed in the future without warning. |
335 func (fd *Field) EnforceUTF8() bool { |
335 func (fd *Field) EnforceUTF8() bool { |
336 if fd.L1.HasEnforceUTF8 { |
336 if fd.L1.HasEnforceUTF8 { |
337 return fd.L1.EnforceUTF8 |
337 return fd.L1.EnforceUTF8 |
338 } |
338 } |
339 return fd.L0.ParentFile.L1.Syntax == pref.Proto3 |
339 return fd.L0.ParentFile.L1.Syntax == protoreflect.Proto3 |
340 } |
340 } |
341 |
341 |
342 func (od *Oneof) IsSynthetic() bool { |
342 func (od *Oneof) IsSynthetic() bool { |
343 return od.L0.ParentFile.L1.Syntax == pref.Proto3 && len(od.L1.Fields.List) == 1 && od.L1.Fields.List[0].HasOptionalKeyword() |
343 return od.L0.ParentFile.L1.Syntax == protoreflect.Proto3 && len(od.L1.Fields.List) == 1 && od.L1.Fields.List[0].HasOptionalKeyword() |
344 } |
344 } |
345 func (od *Oneof) Options() pref.ProtoMessage { |
345 func (od *Oneof) Options() protoreflect.ProtoMessage { |
346 if f := od.L1.Options; f != nil { |
346 if f := od.L1.Options; f != nil { |
347 return f() |
347 return f() |
348 } |
348 } |
349 return descopts.Oneof |
349 return descopts.Oneof |
350 } |
350 } |
351 func (od *Oneof) Fields() pref.FieldDescriptors { return &od.L1.Fields } |
351 func (od *Oneof) Fields() protoreflect.FieldDescriptors { return &od.L1.Fields } |
352 func (od *Oneof) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, od) } |
352 func (od *Oneof) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, od) } |
353 func (od *Oneof) ProtoType(pref.OneofDescriptor) {} |
353 func (od *Oneof) ProtoType(protoreflect.OneofDescriptor) {} |
354 |
354 |
355 type ( |
355 type ( |
356 Extension struct { |
356 Extension struct { |
357 Base |
357 Base |
358 L1 ExtensionL1 |
358 L1 ExtensionL1 |
359 L2 *ExtensionL2 // protected by fileDesc.once |
359 L2 *ExtensionL2 // protected by fileDesc.once |
360 } |
360 } |
361 ExtensionL1 struct { |
361 ExtensionL1 struct { |
362 Number pref.FieldNumber |
362 Number protoreflect.FieldNumber |
363 Extendee pref.MessageDescriptor |
363 Extendee protoreflect.MessageDescriptor |
364 Cardinality pref.Cardinality |
364 Cardinality protoreflect.Cardinality |
365 Kind pref.Kind |
365 Kind protoreflect.Kind |
366 } |
366 } |
367 ExtensionL2 struct { |
367 ExtensionL2 struct { |
368 Options func() pref.ProtoMessage |
368 Options func() protoreflect.ProtoMessage |
369 StringName stringName |
369 StringName stringName |
370 IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto |
370 IsProto3Optional bool // promoted from google.protobuf.FieldDescriptorProto |
371 IsPacked bool // promoted from google.protobuf.FieldOptions |
371 IsPacked bool // promoted from google.protobuf.FieldOptions |
372 Default defaultValue |
372 Default defaultValue |
373 Enum pref.EnumDescriptor |
373 Enum protoreflect.EnumDescriptor |
374 Message pref.MessageDescriptor |
374 Message protoreflect.MessageDescriptor |
375 } |
375 } |
376 ) |
376 ) |
377 |
377 |
378 func (xd *Extension) Options() pref.ProtoMessage { |
378 func (xd *Extension) Options() protoreflect.ProtoMessage { |
379 if f := xd.lazyInit().Options; f != nil { |
379 if f := xd.lazyInit().Options; f != nil { |
380 return f() |
380 return f() |
381 } |
381 } |
382 return descopts.Field |
382 return descopts.Field |
383 } |
383 } |
384 func (xd *Extension) Number() pref.FieldNumber { return xd.L1.Number } |
384 func (xd *Extension) Number() protoreflect.FieldNumber { return xd.L1.Number } |
385 func (xd *Extension) Cardinality() pref.Cardinality { return xd.L1.Cardinality } |
385 func (xd *Extension) Cardinality() protoreflect.Cardinality { return xd.L1.Cardinality } |
386 func (xd *Extension) Kind() pref.Kind { return xd.L1.Kind } |
386 func (xd *Extension) Kind() protoreflect.Kind { return xd.L1.Kind } |
387 func (xd *Extension) HasJSONName() bool { return xd.lazyInit().StringName.hasJSON } |
387 func (xd *Extension) HasJSONName() bool { return xd.lazyInit().StringName.hasJSON } |
388 func (xd *Extension) JSONName() string { return xd.lazyInit().StringName.getJSON(xd) } |
388 func (xd *Extension) JSONName() string { return xd.lazyInit().StringName.getJSON(xd) } |
389 func (xd *Extension) TextName() string { return xd.lazyInit().StringName.getText(xd) } |
389 func (xd *Extension) TextName() string { return xd.lazyInit().StringName.getText(xd) } |
390 func (xd *Extension) HasPresence() bool { return xd.L1.Cardinality != pref.Repeated } |
390 func (xd *Extension) HasPresence() bool { return xd.L1.Cardinality != protoreflect.Repeated } |
391 func (xd *Extension) HasOptionalKeyword() bool { |
391 func (xd *Extension) HasOptionalKeyword() bool { |
392 return (xd.L0.ParentFile.L1.Syntax == pref.Proto2 && xd.L1.Cardinality == pref.Optional) || xd.lazyInit().IsProto3Optional |
392 return (xd.L0.ParentFile.L1.Syntax == protoreflect.Proto2 && xd.L1.Cardinality == protoreflect.Optional) || xd.lazyInit().IsProto3Optional |
393 } |
393 } |
394 func (xd *Extension) IsPacked() bool { return xd.lazyInit().IsPacked } |
394 func (xd *Extension) IsPacked() bool { return xd.lazyInit().IsPacked } |
395 func (xd *Extension) IsExtension() bool { return true } |
395 func (xd *Extension) IsExtension() bool { return true } |
396 func (xd *Extension) IsWeak() bool { return false } |
396 func (xd *Extension) IsWeak() bool { return false } |
397 func (xd *Extension) IsList() bool { return xd.Cardinality() == pref.Repeated } |
397 func (xd *Extension) IsList() bool { return xd.Cardinality() == protoreflect.Repeated } |
398 func (xd *Extension) IsMap() bool { return false } |
398 func (xd *Extension) IsMap() bool { return false } |
399 func (xd *Extension) MapKey() pref.FieldDescriptor { return nil } |
399 func (xd *Extension) MapKey() protoreflect.FieldDescriptor { return nil } |
400 func (xd *Extension) MapValue() pref.FieldDescriptor { return nil } |
400 func (xd *Extension) MapValue() protoreflect.FieldDescriptor { return nil } |
401 func (xd *Extension) HasDefault() bool { return xd.lazyInit().Default.has } |
401 func (xd *Extension) HasDefault() bool { return xd.lazyInit().Default.has } |
402 func (xd *Extension) Default() pref.Value { return xd.lazyInit().Default.get(xd) } |
402 func (xd *Extension) Default() protoreflect.Value { return xd.lazyInit().Default.get(xd) } |
403 func (xd *Extension) DefaultEnumValue() pref.EnumValueDescriptor { return xd.lazyInit().Default.enum } |
403 func (xd *Extension) DefaultEnumValue() protoreflect.EnumValueDescriptor { |
404 func (xd *Extension) ContainingOneof() pref.OneofDescriptor { return nil } |
404 return xd.lazyInit().Default.enum |
405 func (xd *Extension) ContainingMessage() pref.MessageDescriptor { return xd.L1.Extendee } |
405 } |
406 func (xd *Extension) Enum() pref.EnumDescriptor { return xd.lazyInit().Enum } |
406 func (xd *Extension) ContainingOneof() protoreflect.OneofDescriptor { return nil } |
407 func (xd *Extension) Message() pref.MessageDescriptor { return xd.lazyInit().Message } |
407 func (xd *Extension) ContainingMessage() protoreflect.MessageDescriptor { return xd.L1.Extendee } |
408 func (xd *Extension) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, xd) } |
408 func (xd *Extension) Enum() protoreflect.EnumDescriptor { return xd.lazyInit().Enum } |
409 func (xd *Extension) ProtoType(pref.FieldDescriptor) {} |
409 func (xd *Extension) Message() protoreflect.MessageDescriptor { return xd.lazyInit().Message } |
410 func (xd *Extension) ProtoInternal(pragma.DoNotImplement) {} |
410 func (xd *Extension) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, xd) } |
|
411 func (xd *Extension) ProtoType(protoreflect.FieldDescriptor) {} |
|
412 func (xd *Extension) ProtoInternal(pragma.DoNotImplement) {} |
411 func (xd *Extension) lazyInit() *ExtensionL2 { |
413 func (xd *Extension) lazyInit() *ExtensionL2 { |
412 xd.L0.ParentFile.lazyInit() // implicitly initializes L2 |
414 xd.L0.ParentFile.lazyInit() // implicitly initializes L2 |
413 return xd.L2 |
415 return xd.L2 |
414 } |
416 } |
415 |
417 |
419 L1 ServiceL1 |
421 L1 ServiceL1 |
420 L2 *ServiceL2 // protected by fileDesc.once |
422 L2 *ServiceL2 // protected by fileDesc.once |
421 } |
423 } |
422 ServiceL1 struct{} |
424 ServiceL1 struct{} |
423 ServiceL2 struct { |
425 ServiceL2 struct { |
424 Options func() pref.ProtoMessage |
426 Options func() protoreflect.ProtoMessage |
425 Methods Methods |
427 Methods Methods |
426 } |
428 } |
427 |
429 |
428 Method struct { |
430 Method struct { |
429 Base |
431 Base |
430 L1 MethodL1 |
432 L1 MethodL1 |
431 } |
433 } |
432 MethodL1 struct { |
434 MethodL1 struct { |
433 Options func() pref.ProtoMessage |
435 Options func() protoreflect.ProtoMessage |
434 Input pref.MessageDescriptor |
436 Input protoreflect.MessageDescriptor |
435 Output pref.MessageDescriptor |
437 Output protoreflect.MessageDescriptor |
436 IsStreamingClient bool |
438 IsStreamingClient bool |
437 IsStreamingServer bool |
439 IsStreamingServer bool |
438 } |
440 } |
439 ) |
441 ) |
440 |
442 |
441 func (sd *Service) Options() pref.ProtoMessage { |
443 func (sd *Service) Options() protoreflect.ProtoMessage { |
442 if f := sd.lazyInit().Options; f != nil { |
444 if f := sd.lazyInit().Options; f != nil { |
443 return f() |
445 return f() |
444 } |
446 } |
445 return descopts.Service |
447 return descopts.Service |
446 } |
448 } |
447 func (sd *Service) Methods() pref.MethodDescriptors { return &sd.lazyInit().Methods } |
449 func (sd *Service) Methods() protoreflect.MethodDescriptors { return &sd.lazyInit().Methods } |
448 func (sd *Service) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, sd) } |
450 func (sd *Service) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, sd) } |
449 func (sd *Service) ProtoType(pref.ServiceDescriptor) {} |
451 func (sd *Service) ProtoType(protoreflect.ServiceDescriptor) {} |
450 func (sd *Service) ProtoInternal(pragma.DoNotImplement) {} |
452 func (sd *Service) ProtoInternal(pragma.DoNotImplement) {} |
451 func (sd *Service) lazyInit() *ServiceL2 { |
453 func (sd *Service) lazyInit() *ServiceL2 { |
452 sd.L0.ParentFile.lazyInit() // implicitly initializes L2 |
454 sd.L0.ParentFile.lazyInit() // implicitly initializes L2 |
453 return sd.L2 |
455 return sd.L2 |
454 } |
456 } |
455 |
457 |
456 func (md *Method) Options() pref.ProtoMessage { |
458 func (md *Method) Options() protoreflect.ProtoMessage { |
457 if f := md.L1.Options; f != nil { |
459 if f := md.L1.Options; f != nil { |
458 return f() |
460 return f() |
459 } |
461 } |
460 return descopts.Method |
462 return descopts.Method |
461 } |
463 } |
462 func (md *Method) Input() pref.MessageDescriptor { return md.L1.Input } |
464 func (md *Method) Input() protoreflect.MessageDescriptor { return md.L1.Input } |
463 func (md *Method) Output() pref.MessageDescriptor { return md.L1.Output } |
465 func (md *Method) Output() protoreflect.MessageDescriptor { return md.L1.Output } |
464 func (md *Method) IsStreamingClient() bool { return md.L1.IsStreamingClient } |
466 func (md *Method) IsStreamingClient() bool { return md.L1.IsStreamingClient } |
465 func (md *Method) IsStreamingServer() bool { return md.L1.IsStreamingServer } |
467 func (md *Method) IsStreamingServer() bool { return md.L1.IsStreamingServer } |
466 func (md *Method) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) } |
468 func (md *Method) Format(s fmt.State, r rune) { descfmt.FormatDesc(s, r, md) } |
467 func (md *Method) ProtoType(pref.MethodDescriptor) {} |
469 func (md *Method) ProtoType(protoreflect.MethodDescriptor) {} |
468 func (md *Method) ProtoInternal(pragma.DoNotImplement) {} |
470 func (md *Method) ProtoInternal(pragma.DoNotImplement) {} |
469 |
471 |
470 // Surrogate files are can be used to create standalone descriptors |
472 // Surrogate files are can be used to create standalone descriptors |
471 // where the syntax is only information derived from the parent file. |
473 // where the syntax is only information derived from the parent file. |
472 var ( |
474 var ( |
473 SurrogateProto2 = &File{L1: FileL1{Syntax: pref.Proto2}, L2: &FileL2{}} |
475 SurrogateProto2 = &File{L1: FileL1{Syntax: protoreflect.Proto2}, L2: &FileL2{}} |
474 SurrogateProto3 = &File{L1: FileL1{Syntax: pref.Proto3}, L2: &FileL2{}} |
476 SurrogateProto3 = &File{L1: FileL1{Syntax: protoreflect.Proto3}, L2: &FileL2{}} |
475 ) |
477 ) |
476 |
478 |
477 type ( |
479 type ( |
478 Base struct { |
480 Base struct { |
479 L0 BaseL0 |
481 L0 BaseL0 |
480 } |
482 } |
481 BaseL0 struct { |
483 BaseL0 struct { |
482 FullName pref.FullName // must be populated |
484 FullName protoreflect.FullName // must be populated |
483 ParentFile *File // must be populated |
485 ParentFile *File // must be populated |
484 Parent pref.Descriptor |
486 Parent protoreflect.Descriptor |
485 Index int |
487 Index int |
486 } |
488 } |
487 ) |
489 ) |
488 |
490 |
489 func (d *Base) Name() pref.Name { return d.L0.FullName.Name() } |
491 func (d *Base) Name() protoreflect.Name { return d.L0.FullName.Name() } |
490 func (d *Base) FullName() pref.FullName { return d.L0.FullName } |
492 func (d *Base) FullName() protoreflect.FullName { return d.L0.FullName } |
491 func (d *Base) ParentFile() pref.FileDescriptor { |
493 func (d *Base) ParentFile() protoreflect.FileDescriptor { |
492 if d.L0.ParentFile == SurrogateProto2 || d.L0.ParentFile == SurrogateProto3 { |
494 if d.L0.ParentFile == SurrogateProto2 || d.L0.ParentFile == SurrogateProto3 { |
493 return nil // surrogate files are not real parents |
495 return nil // surrogate files are not real parents |
494 } |
496 } |
495 return d.L0.ParentFile |
497 return d.L0.ParentFile |
496 } |
498 } |
497 func (d *Base) Parent() pref.Descriptor { return d.L0.Parent } |
499 func (d *Base) Parent() protoreflect.Descriptor { return d.L0.Parent } |
498 func (d *Base) Index() int { return d.L0.Index } |
500 func (d *Base) Index() int { return d.L0.Index } |
499 func (d *Base) Syntax() pref.Syntax { return d.L0.ParentFile.Syntax() } |
501 func (d *Base) Syntax() protoreflect.Syntax { return d.L0.ParentFile.Syntax() } |
500 func (d *Base) IsPlaceholder() bool { return false } |
502 func (d *Base) IsPlaceholder() bool { return false } |
501 func (d *Base) ProtoInternal(pragma.DoNotImplement) {} |
503 func (d *Base) ProtoInternal(pragma.DoNotImplement) {} |
502 |
504 |
503 type stringName struct { |
505 type stringName struct { |
504 hasJSON bool |
506 hasJSON bool |
531 s.nameJSON = strs.JSONCamelCase(string(fd.Name())) |
533 s.nameJSON = strs.JSONCamelCase(string(fd.Name())) |
532 } |
534 } |
533 |
535 |
534 // Format the text name. |
536 // Format the text name. |
535 s.nameText = string(fd.Name()) |
537 s.nameText = string(fd.Name()) |
536 if fd.Kind() == pref.GroupKind { |
538 if fd.Kind() == protoreflect.GroupKind { |
537 s.nameText = string(fd.Message().Name()) |
539 s.nameText = string(fd.Message().Name()) |
538 } |
540 } |
539 } |
541 } |
540 }) |
542 }) |
541 return s |
543 return s |
542 } |
544 } |
543 |
545 |
544 func (s *stringName) getJSON(fd pref.FieldDescriptor) string { return s.lazyInit(fd).nameJSON } |
546 func (s *stringName) getJSON(fd protoreflect.FieldDescriptor) string { return s.lazyInit(fd).nameJSON } |
545 func (s *stringName) getText(fd pref.FieldDescriptor) string { return s.lazyInit(fd).nameText } |
547 func (s *stringName) getText(fd protoreflect.FieldDescriptor) string { return s.lazyInit(fd).nameText } |
546 |
548 |
547 func DefaultValue(v pref.Value, ev pref.EnumValueDescriptor) defaultValue { |
549 func DefaultValue(v protoreflect.Value, ev protoreflect.EnumValueDescriptor) defaultValue { |
548 dv := defaultValue{has: v.IsValid(), val: v, enum: ev} |
550 dv := defaultValue{has: v.IsValid(), val: v, enum: ev} |
549 if b, ok := v.Interface().([]byte); ok { |
551 if b, ok := v.Interface().([]byte); ok { |
550 // Store a copy of the default bytes, so that we can detect |
552 // Store a copy of the default bytes, so that we can detect |
551 // accidental mutations of the original value. |
553 // accidental mutations of the original value. |
552 dv.bytes = append([]byte(nil), b...) |
554 dv.bytes = append([]byte(nil), b...) |
553 } |
555 } |
554 return dv |
556 return dv |
555 } |
557 } |
556 |
558 |
557 func unmarshalDefault(b []byte, k pref.Kind, pf *File, ed pref.EnumDescriptor) defaultValue { |
559 func unmarshalDefault(b []byte, k protoreflect.Kind, pf *File, ed protoreflect.EnumDescriptor) defaultValue { |
558 var evs pref.EnumValueDescriptors |
560 var evs protoreflect.EnumValueDescriptors |
559 if k == pref.EnumKind { |
561 if k == protoreflect.EnumKind { |
560 // If the enum is declared within the same file, be careful not to |
562 // If the enum is declared within the same file, be careful not to |
561 // blindly call the Values method, lest we bind ourselves in a deadlock. |
563 // blindly call the Values method, lest we bind ourselves in a deadlock. |
562 if e, ok := ed.(*Enum); ok && e.L0.ParentFile == pf { |
564 if e, ok := ed.(*Enum); ok && e.L0.ParentFile == pf { |
563 evs = &e.L2.Values |
565 evs = &e.L2.Values |
564 } else { |
566 } else { |
565 evs = ed.Values() |
567 evs = ed.Values() |
566 } |
568 } |
567 |
569 |
568 // If we are unable to resolve the enum dependency, use a placeholder |
570 // If we are unable to resolve the enum dependency, use a placeholder |
569 // enum value since we will not be able to parse the default value. |
571 // enum value since we will not be able to parse the default value. |
570 if ed.IsPlaceholder() && pref.Name(b).IsValid() { |
572 if ed.IsPlaceholder() && protoreflect.Name(b).IsValid() { |
571 v := pref.ValueOfEnum(0) |
573 v := protoreflect.ValueOfEnum(0) |
572 ev := PlaceholderEnumValue(ed.FullName().Parent().Append(pref.Name(b))) |
574 ev := PlaceholderEnumValue(ed.FullName().Parent().Append(protoreflect.Name(b))) |
573 return DefaultValue(v, ev) |
575 return DefaultValue(v, ev) |
574 } |
576 } |
575 } |
577 } |
576 |
578 |
577 v, ev, err := defval.Unmarshal(string(b), k, evs, defval.Descriptor) |
579 v, ev, err := defval.Unmarshal(string(b), k, evs, defval.Descriptor) |
581 return DefaultValue(v, ev) |
583 return DefaultValue(v, ev) |
582 } |
584 } |
583 |
585 |
584 type defaultValue struct { |
586 type defaultValue struct { |
585 has bool |
587 has bool |
586 val pref.Value |
588 val protoreflect.Value |
587 enum pref.EnumValueDescriptor |
589 enum protoreflect.EnumValueDescriptor |
588 bytes []byte |
590 bytes []byte |
589 } |
591 } |
590 |
592 |
591 func (dv *defaultValue) get(fd pref.FieldDescriptor) pref.Value { |
593 func (dv *defaultValue) get(fd protoreflect.FieldDescriptor) protoreflect.Value { |
592 // Return the zero value as the default if unpopulated. |
594 // Return the zero value as the default if unpopulated. |
593 if !dv.has { |
595 if !dv.has { |
594 if fd.Cardinality() == pref.Repeated { |
596 if fd.Cardinality() == protoreflect.Repeated { |
595 return pref.Value{} |
597 return protoreflect.Value{} |
596 } |
598 } |
597 switch fd.Kind() { |
599 switch fd.Kind() { |
598 case pref.BoolKind: |
600 case protoreflect.BoolKind: |
599 return pref.ValueOfBool(false) |
601 return protoreflect.ValueOfBool(false) |
600 case pref.Int32Kind, pref.Sint32Kind, pref.Sfixed32Kind: |
602 case protoreflect.Int32Kind, protoreflect.Sint32Kind, protoreflect.Sfixed32Kind: |
601 return pref.ValueOfInt32(0) |
603 return protoreflect.ValueOfInt32(0) |
602 case pref.Int64Kind, pref.Sint64Kind, pref.Sfixed64Kind: |
604 case protoreflect.Int64Kind, protoreflect.Sint64Kind, protoreflect.Sfixed64Kind: |
603 return pref.ValueOfInt64(0) |
605 return protoreflect.ValueOfInt64(0) |
604 case pref.Uint32Kind, pref.Fixed32Kind: |
606 case protoreflect.Uint32Kind, protoreflect.Fixed32Kind: |
605 return pref.ValueOfUint32(0) |
607 return protoreflect.ValueOfUint32(0) |
606 case pref.Uint64Kind, pref.Fixed64Kind: |
608 case protoreflect.Uint64Kind, protoreflect.Fixed64Kind: |
607 return pref.ValueOfUint64(0) |
609 return protoreflect.ValueOfUint64(0) |
608 case pref.FloatKind: |
610 case protoreflect.FloatKind: |
609 return pref.ValueOfFloat32(0) |
611 return protoreflect.ValueOfFloat32(0) |
610 case pref.DoubleKind: |
612 case protoreflect.DoubleKind: |
611 return pref.ValueOfFloat64(0) |
613 return protoreflect.ValueOfFloat64(0) |
612 case pref.StringKind: |
614 case protoreflect.StringKind: |
613 return pref.ValueOfString("") |
615 return protoreflect.ValueOfString("") |
614 case pref.BytesKind: |
616 case protoreflect.BytesKind: |
615 return pref.ValueOfBytes(nil) |
617 return protoreflect.ValueOfBytes(nil) |
616 case pref.EnumKind: |
618 case protoreflect.EnumKind: |
617 if evs := fd.Enum().Values(); evs.Len() > 0 { |
619 if evs := fd.Enum().Values(); evs.Len() > 0 { |
618 return pref.ValueOfEnum(evs.Get(0).Number()) |
620 return protoreflect.ValueOfEnum(evs.Get(0).Number()) |
619 } |
621 } |
620 return pref.ValueOfEnum(0) |
622 return protoreflect.ValueOfEnum(0) |
621 } |
623 } |
622 } |
624 } |
623 |
625 |
624 if len(dv.bytes) > 0 && !bytes.Equal(dv.bytes, dv.val.Bytes()) { |
626 if len(dv.bytes) > 0 && !bytes.Equal(dv.bytes, dv.val.Bytes()) { |
625 // TODO: Avoid panic if we're running with the race detector |
627 // TODO: Avoid panic if we're running with the race detector |