mirror of
https://github.com/protocolbuffers/protobuf-go.git
synced 2025-01-07 12:56:47 +00:00
c600d6c086
Add a fast check for required fields to the fast path unmarshal. This is best-effort and will fail to detect some initialized messages: Messages with more than 64 required fields, messages split across multiple tags, possibly other cases. In the cases where it works (which is most of them in practice), this permits us to skip the IsInitialized check. Change-Id: I6b70953a333033a5e64fb7ca37a59786cb0f75a0 Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/215878 Reviewed-by: Joe Tsai <joetsai@google.com>
60 lines
1.6 KiB
Go
60 lines
1.6 KiB
Go
// Copyright 2020 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 protoreflect
|
|
|
|
import (
|
|
"google.golang.org/protobuf/internal/pragma"
|
|
)
|
|
|
|
// The following types are used by the fast-path Message.ProtoMethods method.
|
|
//
|
|
// To avoid polluting the public protoreflect API with types used only by
|
|
// low-level implementations, the canonical definitions of these types are
|
|
// in the runtime/protoiface package. The definitions here and in protoiface
|
|
// must be kept in sync.
|
|
type (
|
|
methods = struct {
|
|
pragma.NoUnkeyedLiterals
|
|
Flags supportFlags
|
|
Size func(Message, marshalOptions) int
|
|
Marshal func(Message, marshalInput, marshalOptions) (marshalOutput, error)
|
|
Unmarshal func(Message, unmarshalInput, unmarshalOptions) (unmarshalOutput, error)
|
|
IsInitialized func(Message) error
|
|
}
|
|
supportFlags = uint64
|
|
marshalInput = struct {
|
|
pragma.NoUnkeyedLiterals
|
|
Buf []byte
|
|
}
|
|
marshalOutput = struct {
|
|
pragma.NoUnkeyedLiterals
|
|
Buf []byte
|
|
}
|
|
marshalOptions = struct {
|
|
pragma.NoUnkeyedLiterals
|
|
AllowPartial bool
|
|
Deterministic bool
|
|
UseCachedSize bool
|
|
}
|
|
unmarshalInput = struct {
|
|
pragma.NoUnkeyedLiterals
|
|
Buf []byte
|
|
}
|
|
unmarshalOutput = struct {
|
|
pragma.NoUnkeyedLiterals
|
|
Initialized bool
|
|
}
|
|
unmarshalOptions = struct {
|
|
pragma.NoUnkeyedLiterals
|
|
Merge bool
|
|
AllowPartial bool
|
|
DiscardUnknown bool
|
|
Resolver interface {
|
|
FindExtensionByName(field FullName) (ExtensionType, error)
|
|
FindExtensionByNumber(message FullName, field FieldNumber) (ExtensionType, error)
|
|
}
|
|
}
|
|
)
|