mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-01 03:14:16 +00:00
4686e239b6
Move all checks for required fields into a proto.IsInitialized function. Initial testing makes me confident that we can provide a fast-path implementation of IsInitialized which will perform more than acceptably. (In the degenerate-but-common case where a message transitively contains no required fields, this check can be nearly zero cost.) Unifying checks into a single function provides consistent behavior between the wire, text, and json codecs. Performing the check after decoding eliminates the wire decoder bug where a split message is incorrectly seen as missing required fields. Performing the check after decoding also provides consistent and arguably more correct behavior when the target message was partially prepopulated. Change-Id: I9478b7bebb263af00c0d9f66a1f26e31ff553522 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/170787 Reviewed-by: Herbie Ong <herbie@google.com>
25 lines
761 B
Go
25 lines
761 B
Go
// Copyright 2018 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 (
|
|
"github.com/golang/protobuf/v2/internal/errors"
|
|
"github.com/golang/protobuf/v2/reflect/protoreflect"
|
|
"github.com/golang/protobuf/v2/runtime/protoiface"
|
|
)
|
|
|
|
// Message is the top-level interface that all messages must implement.
|
|
type Message = protoreflect.ProtoMessage
|
|
|
|
// errInternalNoFast indicates that fast-path operations are not available for a message.
|
|
var errInternalNoFast = errors.New("BUG: internal error (errInternalNoFast)")
|
|
|
|
func protoMethods(m Message) *protoiface.Methods {
|
|
if x, ok := m.(protoiface.Methoder); ok {
|
|
return x.XXX_Methods()
|
|
}
|
|
return nil
|
|
}
|