Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 1 | // Copyright 2019 The Go Authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style |
| 3 | // license that can be found in the LICENSE file. |
| 4 | |
| 5 | package protoiface |
| 6 | |
| 7 | import ( |
| 8 | "github.com/golang/protobuf/v2/internal/pragma" |
| 9 | "github.com/golang/protobuf/v2/reflect/protoreflect" |
Joe Tsai | db38ddd | 2019-05-07 15:14:40 -0700 | [diff] [blame^] | 10 | "github.com/golang/protobuf/v2/reflect/protoregistry" |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 11 | ) |
| 12 | |
| 13 | // Methoder is an optional interface implemented by generated messages to |
| 14 | // provide fast-path implementations of various operations. |
| 15 | type Methoder interface { |
| 16 | XXX_Methods() *Methods // may return nil |
| 17 | } |
| 18 | |
| 19 | // Methods is a set of optional fast-path implementations of various operations. |
| 20 | type Methods struct { |
| 21 | // Flags indicate support for optional features. |
| 22 | Flags MethodFlag |
| 23 | |
| 24 | // MarshalAppend appends the wire-format encoding of m to b, returning the result. |
Damien Neil | 4686e23 | 2019-04-05 13:31:40 -0700 | [diff] [blame] | 25 | // It does not perform required field checks. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 26 | MarshalAppend func(b []byte, m protoreflect.ProtoMessage, opts MarshalOptions) ([]byte, error) |
| 27 | |
| 28 | // Size returns the size in bytes of the wire-format encoding of m. |
| 29 | Size func(m protoreflect.ProtoMessage) int |
| 30 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 31 | // Unmarshal parses the wire-format message in b and places the result in m. |
Damien Neil | 4686e23 | 2019-04-05 13:31:40 -0700 | [diff] [blame] | 32 | // It does not reset m or perform required field checks. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 33 | Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error |
| 34 | |
Damien Neil | 4686e23 | 2019-04-05 13:31:40 -0700 | [diff] [blame] | 35 | // IsInitialized returns an error if any required fields in m are not set. |
| 36 | IsInitialized func(m protoreflect.ProtoMessage) error |
| 37 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 38 | pragma.NoUnkeyedLiterals |
| 39 | } |
| 40 | |
| 41 | // MethodFlag indicates support for optional fast-path features. |
| 42 | type MethodFlag int64 |
| 43 | |
| 44 | const ( |
| 45 | // MethodFlagDeterministicMarshal indicates support for deterministic marshaling. |
| 46 | MethodFlagDeterministicMarshal MethodFlag = 1 << iota |
| 47 | ) |
| 48 | |
| 49 | // MarshalOptions configure the marshaler. |
| 50 | // |
| 51 | // This type is identical to the one in package proto. |
| 52 | type MarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 53 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 54 | Deterministic bool |
Damien Neil | 03e7486 | 2019-04-07 18:18:31 -0700 | [diff] [blame] | 55 | UseCachedSize bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 56 | |
| 57 | pragma.NoUnkeyedLiterals |
| 58 | } |
| 59 | |
| 60 | // UnmarshalOptions configures the unmarshaler. |
| 61 | // |
| 62 | // This type is identical to the one in package proto. |
| 63 | type UnmarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 64 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 65 | DiscardUnknown bool |
Joe Tsai | db38ddd | 2019-05-07 15:14:40 -0700 | [diff] [blame^] | 66 | Resolver *protoregistry.Types |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 67 | |
| 68 | pragma.NoUnkeyedLiterals |
| 69 | } |