2019-04-01 20:31:55 +00:00
|
|
|
// 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.
|
|
|
|
|
2019-05-22 19:53:35 +00:00
|
|
|
// Package protoiface contains types referenced or implemented by messages.
|
|
|
|
//
|
|
|
|
// WARNING: This package should only be imported by message implementations.
|
|
|
|
// The functionality found in this package should be accessed through
|
|
|
|
// higher-level abstractions provided by the proto package.
|
2019-04-01 20:31:55 +00:00
|
|
|
package protoiface
|
|
|
|
|
|
|
|
import (
|
2019-05-14 06:55:40 +00:00
|
|
|
"google.golang.org/protobuf/internal/pragma"
|
|
|
|
"google.golang.org/protobuf/reflect/protoreflect"
|
2019-04-01 20:31:55 +00:00
|
|
|
)
|
|
|
|
|
|
|
|
// Methods is a set of optional fast-path implementations of various operations.
|
2020-01-21 19:27:51 +00:00
|
|
|
type Methods = struct {
|
2019-07-12 20:37:59 +00:00
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
2019-04-01 20:31:55 +00:00
|
|
|
// Flags indicate support for optional features.
|
2019-07-12 20:37:59 +00:00
|
|
|
Flags SupportFlags
|
|
|
|
|
|
|
|
// Size returns the size in bytes of the wire-format encoding of m.
|
|
|
|
// MarshalAppend must be provided if a custom Size is provided.
|
|
|
|
Size func(m protoreflect.Message, opts MarshalOptions) int
|
2019-04-01 20:31:55 +00:00
|
|
|
|
2020-01-21 21:29:51 +00:00
|
|
|
// Marshal writes the wire-format encoding of m to the provided buffer.
|
2020-01-06 19:17:07 +00:00
|
|
|
// Size should be provided if a custom MarshalAppend is provided.
|
2020-01-21 23:00:33 +00:00
|
|
|
// It should not return an error for a partial message.
|
2020-01-22 18:28:16 +00:00
|
|
|
Marshal func(m protoreflect.Message, in MarshalInput, opts MarshalOptions) (MarshalOutput, error)
|
2019-04-01 20:31:55 +00:00
|
|
|
|
2020-01-21 21:29:51 +00:00
|
|
|
// Unmarshal parses the wire-format encoding of a message and merges the result to m.
|
2020-01-21 23:00:33 +00:00
|
|
|
// It should not reset the target message or return an error for a partial message.
|
2020-01-22 18:28:16 +00:00
|
|
|
Unmarshal func(m protoreflect.Message, in UnmarshalInput, opts UnmarshalOptions) (UnmarshalOutput, error)
|
2019-04-01 20:31:55 +00:00
|
|
|
|
2019-04-05 20:31:40 +00:00
|
|
|
// IsInitialized returns an error if any required fields in m are not set.
|
2019-07-11 06:14:31 +00:00
|
|
|
IsInitialized func(m protoreflect.Message) error
|
2019-04-01 20:31:55 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 19:27:51 +00:00
|
|
|
type SupportFlags = uint64
|
2019-04-01 20:31:55 +00:00
|
|
|
|
|
|
|
const (
|
2019-07-12 20:37:59 +00:00
|
|
|
// SupportMarshalDeterministic reports whether MarshalOptions.Deterministic is supported.
|
|
|
|
SupportMarshalDeterministic SupportFlags = 1 << iota
|
|
|
|
|
|
|
|
// SupportUnmarshalDiscardUnknown reports whether UnmarshalOptions.DiscardUnknown is supported.
|
|
|
|
SupportUnmarshalDiscardUnknown
|
2019-04-01 20:31:55 +00:00
|
|
|
)
|
|
|
|
|
2020-01-21 21:29:51 +00:00
|
|
|
// MarshalInput is input to the marshaler.
|
|
|
|
type MarshalInput = struct {
|
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
2020-01-22 18:28:16 +00:00
|
|
|
Buf []byte // output is appended to this buffer
|
2020-01-21 21:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// MarshalOutput is output from the marshaler.
|
|
|
|
type MarshalOutput = struct {
|
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
|
|
|
Buf []byte // contains marshaled message
|
|
|
|
}
|
|
|
|
|
2019-04-01 20:31:55 +00:00
|
|
|
// MarshalOptions configure the marshaler.
|
|
|
|
//
|
|
|
|
// This type is identical to the one in package proto.
|
2020-01-21 19:27:51 +00:00
|
|
|
type MarshalOptions = struct {
|
2019-07-12 20:37:59 +00:00
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
2020-01-22 18:28:16 +00:00
|
|
|
AllowPartial bool // may be treated as true by method implementations
|
2019-04-01 20:31:55 +00:00
|
|
|
Deterministic bool
|
2019-04-08 01:18:31 +00:00
|
|
|
UseCachedSize bool
|
2019-04-01 20:31:55 +00:00
|
|
|
}
|
|
|
|
|
2020-01-21 21:29:51 +00:00
|
|
|
// UnmarshalInput is input to the unmarshaler.
|
|
|
|
type UnmarshalInput = struct {
|
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
2020-01-22 18:28:16 +00:00
|
|
|
Buf []byte // input buffer
|
2020-01-21 21:29:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalOutput is output from the unmarshaler.
|
|
|
|
type UnmarshalOutput = struct {
|
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
2020-01-21 23:00:33 +00:00
|
|
|
// Initialized may be set on return if all required fields are known to be set.
|
|
|
|
// A value of false does not indicate that the message is uninitialized, only
|
|
|
|
// that its status could not be confirmed.
|
|
|
|
Initialized bool
|
2020-01-21 21:29:51 +00:00
|
|
|
}
|
|
|
|
|
2019-04-01 20:31:55 +00:00
|
|
|
// UnmarshalOptions configures the unmarshaler.
|
|
|
|
//
|
|
|
|
// This type is identical to the one in package proto.
|
2020-01-21 19:27:51 +00:00
|
|
|
type UnmarshalOptions = struct {
|
2019-07-12 20:37:59 +00:00
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
2020-01-22 18:28:16 +00:00
|
|
|
Merge bool // may be treated as true by method implementations
|
|
|
|
AllowPartial bool // may be treated as true by method implementations
|
2019-04-01 20:31:55 +00:00
|
|
|
DiscardUnknown bool
|
2019-05-14 21:28:19 +00:00
|
|
|
Resolver interface {
|
2020-01-21 19:27:51 +00:00
|
|
|
FindExtensionByName(field protoreflect.FullName) (protoreflect.ExtensionType, error)
|
|
|
|
FindExtensionByNumber(message protoreflect.FullName, field protoreflect.FieldNumber) (protoreflect.ExtensionType, error)
|
2019-05-14 21:28:19 +00:00
|
|
|
}
|
2019-04-01 20:31:55 +00:00
|
|
|
}
|