blob: fe17ca78ec86e7a7db008c5e3176238d64e12b97 [file] [log] [blame]
Damien Neil0d3e8cc2019-04-01 13:31:55 -07001// 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
5package protoiface
6
7import (
8 "github.com/golang/protobuf/v2/internal/pragma"
9 "github.com/golang/protobuf/v2/reflect/protoreflect"
Joe Tsaidb38ddd2019-05-07 15:14:40 -070010 "github.com/golang/protobuf/v2/reflect/protoregistry"
Damien Neil0d3e8cc2019-04-01 13:31:55 -070011)
12
13// Methoder is an optional interface implemented by generated messages to
14// provide fast-path implementations of various operations.
15type Methoder interface {
16 XXX_Methods() *Methods // may return nil
17}
18
19// Methods is a set of optional fast-path implementations of various operations.
20type 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 Neil4686e232019-04-05 13:31:40 -070025 // It does not perform required field checks.
Damien Neil0d3e8cc2019-04-01 13:31:55 -070026 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 Neil0d3e8cc2019-04-01 13:31:55 -070031 // Unmarshal parses the wire-format message in b and places the result in m.
Damien Neil4686e232019-04-05 13:31:40 -070032 // It does not reset m or perform required field checks.
Damien Neil0d3e8cc2019-04-01 13:31:55 -070033 Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error
34
Damien Neil4686e232019-04-05 13:31:40 -070035 // IsInitialized returns an error if any required fields in m are not set.
36 IsInitialized func(m protoreflect.ProtoMessage) error
37
Damien Neil0d3e8cc2019-04-01 13:31:55 -070038 pragma.NoUnkeyedLiterals
39}
40
41// MethodFlag indicates support for optional fast-path features.
42type MethodFlag int64
43
44const (
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.
52type MarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070053 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070054 Deterministic bool
Damien Neil03e74862019-04-07 18:18:31 -070055 UseCachedSize bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070056
57 pragma.NoUnkeyedLiterals
58}
59
60// UnmarshalOptions configures the unmarshaler.
61//
62// This type is identical to the one in package proto.
63type UnmarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070064 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070065 DiscardUnknown bool
Joe Tsaidb38ddd2019-05-07 15:14:40 -070066 Resolver *protoregistry.Types
Damien Neil0d3e8cc2019-04-01 13:31:55 -070067
68 pragma.NoUnkeyedLiterals
69}