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 | |
| 30 | // CachedSize returns the result of the last call to Size. |
| 31 | // It must not be called if the message has been changed since the last call to Size. |
| 32 | CachedSize func(m protoreflect.ProtoMessage) int |
| 33 | |
| 34 | // 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^] | 35 | // It does not reset m or perform required field checks. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 36 | Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error |
| 37 | |
Damien Neil | 4686e23 | 2019-04-05 13:31:40 -0700 | [diff] [blame^] | 38 | // IsInitialized returns an error if any required fields in m are not set. |
| 39 | IsInitialized func(m protoreflect.ProtoMessage) error |
| 40 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 41 | pragma.NoUnkeyedLiterals |
| 42 | } |
| 43 | |
| 44 | // MethodFlag indicates support for optional fast-path features. |
| 45 | type MethodFlag int64 |
| 46 | |
| 47 | const ( |
| 48 | // MethodFlagDeterministicMarshal indicates support for deterministic marshaling. |
| 49 | MethodFlagDeterministicMarshal MethodFlag = 1 << iota |
| 50 | ) |
| 51 | |
| 52 | // MarshalOptions configure the marshaler. |
| 53 | // |
| 54 | // This type is identical to the one in package proto. |
| 55 | type MarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 56 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 57 | Deterministic bool |
| 58 | Reflection bool |
| 59 | |
| 60 | pragma.NoUnkeyedLiterals |
| 61 | } |
| 62 | |
| 63 | // UnmarshalOptions configures the unmarshaler. |
| 64 | // |
| 65 | // This type is identical to the one in package proto. |
| 66 | type UnmarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 67 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 68 | DiscardUnknown bool |
| 69 | Reflection bool |
| 70 | |
| 71 | pragma.NoUnkeyedLiterals |
| 72 | } |