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"
|
|
|
|
"google.golang.org/protobuf/reflect/protoregistry"
|
2019-04-01 20:31:55 +00:00
|
|
|
)
|
|
|
|
|
2019-07-11 06:14:31 +00:00
|
|
|
// Methoder is an optional interface implemented by protoreflect.Message to
|
2019-04-01 20:31:55 +00:00
|
|
|
// provide fast-path implementations of various operations.
|
2019-07-12 20:37:59 +00:00
|
|
|
// The returned Methods struct must not be mutated.
|
2019-04-01 20:31:55 +00:00
|
|
|
type Methoder interface {
|
2019-07-11 06:14:31 +00:00
|
|
|
ProtoMethods() *Methods // may return nil
|
2019-04-01 20:31:55 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// Methods is a set of optional fast-path implementations of various operations.
|
|
|
|
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
|
|
|
|
|
|
|
// MarshalAppend appends the wire-format encoding of m to b, returning the result.
|
2019-07-12 20:37:59 +00:00
|
|
|
// Size must be provided if a custom MarshalAppend is provided.
|
|
|
|
// It must not perform required field checks.
|
2019-07-11 06:14:31 +00:00
|
|
|
MarshalAppend func(b []byte, m protoreflect.Message, opts MarshalOptions) ([]byte, error)
|
2019-04-01 20:31:55 +00:00
|
|
|
|
2019-07-12 20:37:59 +00:00
|
|
|
// Unmarshal parses the wire-format message in b and merges the result in m.
|
|
|
|
// It must not reset m or perform required field checks.
|
2019-07-11 06:14:31 +00:00
|
|
|
Unmarshal func(b []byte, m protoreflect.Message, opts UnmarshalOptions) 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
|
|
|
}
|
|
|
|
|
2019-07-12 20:37:59 +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
|
|
|
)
|
|
|
|
|
|
|
|
// MarshalOptions configure the marshaler.
|
|
|
|
//
|
|
|
|
// This type is identical to the one in package proto.
|
|
|
|
type MarshalOptions struct {
|
2019-07-12 20:37:59 +00:00
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
|
|
|
AllowPartial bool // must 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
|
|
|
}
|
|
|
|
|
|
|
|
// UnmarshalOptions configures the unmarshaler.
|
|
|
|
//
|
|
|
|
// This type is identical to the one in package proto.
|
|
|
|
type UnmarshalOptions struct {
|
2019-07-12 20:37:59 +00:00
|
|
|
pragma.NoUnkeyedLiterals
|
|
|
|
|
|
|
|
AllowPartial bool // must 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 {
|
|
|
|
protoregistry.ExtensionTypeResolver
|
|
|
|
}
|
2019-04-01 20:31:55 +00:00
|
|
|
}
|