10
"google.golang.org/protobuf/internal/errors"
11
"google.golang.org/protobuf/reflect/protoreflect"
12
"google.golang.org/protobuf/runtime/protoiface"
15
func (mi *MessageInfo) checkInitialized(in protoiface.CheckInitializedInput) (protoiface.CheckInitializedOutput, error) {
17
if ms, ok := in.Message.(*messageState); ok {
20
p = in.Message.(*messageReflectWrapper).pointer()
22
return protoiface.CheckInitializedOutput{}, mi.checkInitializedPointer(p)
25
func (mi *MessageInfo) checkInitializedPointer(p pointer) error {
27
if !mi.needsInitCheck {
31
for _, f := range mi.orderedCoderFields {
33
return errors.RequiredNotSet(string(mi.Desc.Fields().ByNumber(f.num).FullName()))
38
if mi.extensionOffset.IsValid() {
39
e := p.Apply(mi.extensionOffset).Extensions()
40
if err := mi.isInitExtensions(e); err != nil {
44
for _, f := range mi.orderedCoderFields {
45
if !f.isRequired && f.funcs.isInit == nil {
48
fptr := p.Apply(f.offset)
49
if f.isPointer && fptr.Elem().IsNil() {
51
return errors.RequiredNotSet(string(mi.Desc.Fields().ByNumber(f.num).FullName()))
55
if f.funcs.isInit == nil {
58
if err := f.funcs.isInit(fptr, f); err != nil {
65
func (mi *MessageInfo) isInitExtensions(ext *map[int32]ExtensionField) error {
69
for _, x := range *ext {
70
ei := getExtensionFieldInfo(x.Type())
71
if ei.funcs.isInit == nil {
78
if err := ei.funcs.isInit(v); err != nil {
86
needsInitCheckMu sync.Mutex
87
needsInitCheckMap sync.Map
93
func needsInitCheck(md protoreflect.MessageDescriptor) bool {
94
if v, ok := needsInitCheckMap.Load(md); ok {
95
if has, ok := v.(bool); ok {
99
needsInitCheckMu.Lock()
100
defer needsInitCheckMu.Unlock()
101
return needsInitCheckLocked(md)
104
func needsInitCheckLocked(md protoreflect.MessageDescriptor) (has bool) {
105
if v, ok := needsInitCheckMap.Load(md); ok {
119
needsInitCheckMap.Store(md, struct{}{})
121
needsInitCheckMap.Store(md, has)
123
if md.RequiredNumbers().Len() > 0 {
126
if md.ExtensionRanges().Len() > 0 {
129
for i := 0; i < md.Fields().Len(); i++ {
130
fd := md.Fields().Get(i)
136
if fmd != nil && needsInitCheckLocked(fmd) {