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 | |
Joe Tsai | 6650091 | 2019-05-22 15:53:35 -0400 | [diff] [blame^] | 5 | // Package protoiface contains types referenced or implemented by messages. |
| 6 | // |
| 7 | // WARNING: This package should only be imported by message implementations. |
| 8 | // The functionality found in this package should be accessed through |
| 9 | // higher-level abstractions provided by the proto package. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 10 | package protoiface |
| 11 | |
| 12 | import ( |
Damien Neil | e89e624 | 2019-05-13 23:55:40 -0700 | [diff] [blame] | 13 | "google.golang.org/protobuf/internal/pragma" |
| 14 | "google.golang.org/protobuf/reflect/protoreflect" |
| 15 | "google.golang.org/protobuf/reflect/protoregistry" |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 16 | ) |
| 17 | |
| 18 | // Methoder is an optional interface implemented by generated messages to |
| 19 | // provide fast-path implementations of various operations. |
| 20 | type Methoder interface { |
| 21 | XXX_Methods() *Methods // may return nil |
| 22 | } |
| 23 | |
| 24 | // Methods is a set of optional fast-path implementations of various operations. |
| 25 | type Methods struct { |
| 26 | // Flags indicate support for optional features. |
| 27 | Flags MethodFlag |
| 28 | |
| 29 | // 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] | 30 | // It does not perform required field checks. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 31 | MarshalAppend func(b []byte, m protoreflect.ProtoMessage, opts MarshalOptions) ([]byte, error) |
| 32 | |
| 33 | // Size returns the size in bytes of the wire-format encoding of m. |
| 34 | Size func(m protoreflect.ProtoMessage) int |
| 35 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 36 | // 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] | 37 | // It does not reset m or perform required field checks. |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 38 | Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error |
| 39 | |
Damien Neil | 4686e23 | 2019-04-05 13:31:40 -0700 | [diff] [blame] | 40 | // IsInitialized returns an error if any required fields in m are not set. |
| 41 | IsInitialized func(m protoreflect.ProtoMessage) error |
| 42 | |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 43 | pragma.NoUnkeyedLiterals |
| 44 | } |
| 45 | |
| 46 | // MethodFlag indicates support for optional fast-path features. |
| 47 | type MethodFlag int64 |
| 48 | |
| 49 | const ( |
| 50 | // MethodFlagDeterministicMarshal indicates support for deterministic marshaling. |
| 51 | MethodFlagDeterministicMarshal MethodFlag = 1 << iota |
| 52 | ) |
| 53 | |
| 54 | // MarshalOptions configure the marshaler. |
| 55 | // |
| 56 | // This type is identical to the one in package proto. |
| 57 | type MarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 58 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 59 | Deterministic bool |
Damien Neil | 03e7486 | 2019-04-07 18:18:31 -0700 | [diff] [blame] | 60 | UseCachedSize bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 61 | |
| 62 | pragma.NoUnkeyedLiterals |
| 63 | } |
| 64 | |
| 65 | // UnmarshalOptions configures the unmarshaler. |
| 66 | // |
| 67 | // This type is identical to the one in package proto. |
| 68 | type UnmarshalOptions struct { |
Damien Neil | 96c229a | 2019-04-03 12:17:24 -0700 | [diff] [blame] | 69 | AllowPartial bool |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 70 | DiscardUnknown bool |
Joe Tsai | 1c28304 | 2019-05-14 14:28:19 -0700 | [diff] [blame] | 71 | Resolver interface { |
| 72 | protoregistry.ExtensionTypeResolver |
| 73 | } |
Damien Neil | 0d3e8cc | 2019-04-01 13:31:55 -0700 | [diff] [blame] | 74 | |
| 75 | pragma.NoUnkeyedLiterals |
| 76 | } |