blob: 42832de0d897ef8ac8eb7595f3bd5d719174dd08 [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"
10)
11
12// Methoder is an optional interface implemented by generated messages to
13// provide fast-path implementations of various operations.
14type Methoder interface {
15 XXX_Methods() *Methods // may return nil
16}
17
18// Methods is a set of optional fast-path implementations of various operations.
19type 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 Neil4686e232019-04-05 13:31:40 -070024 // It does not perform required field checks.
Damien Neil0d3e8cc2019-04-01 13:31:55 -070025 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 Neil0d3e8cc2019-04-01 13:31:55 -070030 // Unmarshal parses the wire-format message in b and places the result in m.
Damien Neil4686e232019-04-05 13:31:40 -070031 // It does not reset m or perform required field checks.
Damien Neil0d3e8cc2019-04-01 13:31:55 -070032 Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error
33
Damien Neil4686e232019-04-05 13:31:40 -070034 // IsInitialized returns an error if any required fields in m are not set.
35 IsInitialized func(m protoreflect.ProtoMessage) error
36
Damien Neil0d3e8cc2019-04-01 13:31:55 -070037 pragma.NoUnkeyedLiterals
38}
39
40// MethodFlag indicates support for optional fast-path features.
41type MethodFlag int64
42
43const (
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.
51type MarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070052 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070053 Deterministic bool
Damien Neil03e74862019-04-07 18:18:31 -070054 UseCachedSize bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070055
56 pragma.NoUnkeyedLiterals
57}
58
59// UnmarshalOptions configures the unmarshaler.
60//
61// This type is identical to the one in package proto.
62type UnmarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070063 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070064 DiscardUnknown bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070065
66 pragma.NoUnkeyedLiterals
67}