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" |
| 10 | ) |
| 11 | |
| 12 | // Methoder is an optional interface implemented by generated messages to |
| 13 | // provide fast-path implementations of various operations. |
| 14 | type Methoder interface { |
| 15 | XXX_Methods() *Methods // may return nil |
| 16 | } |
| 17 | |
| 18 | // Methods is a set of optional fast-path implementations of various operations. |
| 19 | type Methods struct { |
| 20 | // Flags indicate support for optional features. |
| 21 | Flags MethodFlag |
| 22 | |
| 23 | // 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] | 24 | // It does not perform required field checks. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 25 | MarshalAppend func(b []byte, m protoreflect.ProtoMessage, opts MarshalOptions) ([]byte, error) |
| 26 | |
| 27 | // Size returns the size in bytes of the wire-format encoding of m. |
| 28 | Size func(m protoreflect.ProtoMessage) int |
| 29 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 30 | // 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] | 31 | // It does not reset m or perform required field checks. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 32 | Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error |
| 33 | |
Damien Neil | 4686e23 | 2019-04-05 13:31:40 -0700 | [diff] [blame] | 34 | // IsInitialized returns an error if any required fields in m are not set. |
| 35 | IsInitialized func(m protoreflect.ProtoMessage) error |
| 36 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 37 | pragma.NoUnkeyedLiterals |
| 38 | } |
| 39 | |
| 40 | // MethodFlag indicates support for optional fast-path features. |
| 41 | type MethodFlag int64 |
| 42 | |
| 43 | const ( |
| 44 | // MethodFlagDeterministicMarshal indicates support for deterministic marshaling. |
| 45 | MethodFlagDeterministicMarshal MethodFlag = 1 << iota |
| 46 | ) |
| 47 | |
| 48 | // MarshalOptions configure the marshaler. |
| 49 | // |
| 50 | // This type is identical to the one in package proto. |
| 51 | type MarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 52 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 53 | Deterministic bool |
Damien Neil | 03e7486 | 2019-04-07 18:18:31 -0700 | [diff] [blame] | 54 | UseCachedSize bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 55 | |
| 56 | pragma.NoUnkeyedLiterals |
| 57 | } |
| 58 | |
| 59 | // UnmarshalOptions configures the unmarshaler. |
| 60 | // |
| 61 | // This type is identical to the one in package proto. |
| 62 | type UnmarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 63 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 64 | DiscardUnknown bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 65 | |
| 66 | pragma.NoUnkeyedLiterals |
| 67 | } |