Source File
checkinit.go
Belonging Package
google.golang.org/protobuf/proto
// Copyright 2019 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.
package proto
import (
)
// CheckInitialized returns an error if any required fields in m are not set.
func ( Message) error {
// Treat a nil message interface as an "untyped" empty message,
// which we assume to have no required fields.
if == nil {
return nil
}
return checkInitialized(.ProtoReflect())
}
// CheckInitialized returns an error if any required fields in m are not set.
func ( protoreflect.Message) error {
if := protoMethods(); != nil && .CheckInitialized != nil {
, := .CheckInitialized(protoiface.CheckInitializedInput{
Message: ,
})
return
}
return checkInitializedSlow()
}
func ( protoreflect.Message) error {
:= .Descriptor()
:= .Fields()
for , := 0, .RequiredNumbers(); < .Len(); ++ {
:= .ByNumber(.Get())
if !.Has() {
return errors.RequiredNotSet(string(.FullName()))
}
}
var error
.Range(func( protoreflect.FieldDescriptor, protoreflect.Value) bool {
switch {
case .IsList():
if .Message() == nil {
return true
}
for , := 0, .List(); < .Len() && == nil; ++ {
= checkInitialized(.Get().Message())
}
case .IsMap():
if .MapValue().Message() == nil {
return true
}
.Map().Range(func( protoreflect.MapKey, protoreflect.Value) bool {
= checkInitialized(.Message())
return == nil
})
default:
if .Message() == nil {
return true
}
= checkInitialized(.Message())
}
return == nil
})
return
}
The pages are generated with Golds v0.4.9. (GOOS=linux GOARCH=amd64)