blob: d8e2df0e9d387c72896d50b9221d046430ca5188 [file] [log] [blame]
Zack Williamse940c7a2019-08-21 14:25:39 -07001//+build appengine
2// TODO: other build tags for environments where unsafe package is inappropriate
3
4package desc
5
6type jsonNameMap struct{}
7type memoizedDefault struct{}
8
9// FindFieldByJSONName finds the field with the given JSON field name. If no such
10// field exists then nil is returned. Only regular fields are returned, not
11// extensions.
12func (md *MessageDescriptor) FindFieldByJSONName(jsonName string) *FieldDescriptor {
13 // NB: With allowed use of unsafe, we use it to atomically define an index
14 // via atomic.LoadPointer/atomic.StorePointer. Without it, we skip the index
15 // and do an linear scan of fields each time.
16 for _, f := range md.fields {
17 jn := f.proto.GetJsonName()
18 if jn == "" {
19 jn = f.proto.GetName()
20 }
21 if jn == jsonName {
22 return f
23 }
24 }
25 return nil
26}
27
28func (fd *FieldDescriptor) getDefaultValue() interface{} {
29 return fd.determineDefault()
30}