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. |
| 24 | MarshalAppend func(b []byte, m protoreflect.ProtoMessage, opts MarshalOptions) ([]byte, error) |
| 25 | |
| 26 | // Size returns the size in bytes of the wire-format encoding of m. |
| 27 | Size func(m protoreflect.ProtoMessage) int |
| 28 | |
| 29 | // CachedSize returns the result of the last call to Size. |
| 30 | // It must not be called if the message has been changed since the last call to Size. |
| 31 | CachedSize func(m protoreflect.ProtoMessage) int |
| 32 | |
| 33 | // Unmarshal parses the wire-format message in b and places the result in m. |
| 34 | // It does not reset m. |
| 35 | Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error |
| 36 | |
| 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 { |
| 52 | Deterministic bool |
| 53 | Reflection bool |
| 54 | |
| 55 | pragma.NoUnkeyedLiterals |
| 56 | } |
| 57 | |
| 58 | // UnmarshalOptions configures the unmarshaler. |
| 59 | // |
| 60 | // This type is identical to the one in package proto. |
| 61 | type UnmarshalOptions struct { |
| 62 | DiscardUnknown bool |
| 63 | Reflection bool |
| 64 | |
| 65 | pragma.NoUnkeyedLiterals |
| 66 | } |