blob: dda5e4919fe3d868ce39f5fc3e389a3754f7db5c [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
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 Neil4686e232019-04-05 13:31:40 -070035 // It does not reset m or perform required field checks.
Damien Neil0d3e8cc2019-04-01 13:31:55 -070036 Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error
37
Damien Neil4686e232019-04-05 13:31:40 -070038 // IsInitialized returns an error if any required fields in m are not set.
39 IsInitialized func(m protoreflect.ProtoMessage) error
40
Damien Neil0d3e8cc2019-04-01 13:31:55 -070041 pragma.NoUnkeyedLiterals
42}
43
44// MethodFlag indicates support for optional fast-path features.
45type MethodFlag int64
46
47const (
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.
55type MarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070056 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070057 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.
66type UnmarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070067 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070068 DiscardUnknown bool
69 Reflection bool
70
71 pragma.NoUnkeyedLiterals
72}