blob: 25d619a288247530824659afe5ef30be21349f5c [file] [log] [blame]
khenaidooa46458b2021-12-15 16:50:44 -05001//go:build appengine || gopherjs || purego
2// +build appengine gopherjs purego
3
4// NB: other environments where unsafe is unappropriate should use "purego" build tag
5// https://github.com/golang/go/issues/23172
6
7package desc
8
9type jsonNameMap struct{}
10type memoizedDefault struct{}
11
12// FindFieldByJSONName finds the field with the given JSON field name. If no such
13// field exists then nil is returned. Only regular fields are returned, not
14// extensions.
15func (md *MessageDescriptor) FindFieldByJSONName(jsonName string) *FieldDescriptor {
16 // NB: With allowed use of unsafe, we use it to atomically define an index
17 // via atomic.LoadPointer/atomic.StorePointer. Without it, we skip the index
18 // and must do a linear scan of fields each time.
19 for _, f := range md.fields {
20 jn := f.GetJSONName()
21 if jn == jsonName {
22 return f
23 }
24 }
25 return nil
26}
27
28func (fd *FieldDescriptor) getDefaultValue() interface{} {
29 return fd.determineDefault()
30}