blob: e4a5157ed410c99fe2eb78d9f13a7e81c8cc288a [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
Joe Tsai66500912019-05-22 15:53:35 -04005// 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 Neil0d3e8cc2019-04-01 13:31:55 -070010package protoiface
11
12import (
Damien Neile89e6242019-05-13 23:55:40 -070013 "google.golang.org/protobuf/internal/pragma"
14 "google.golang.org/protobuf/reflect/protoreflect"
15 "google.golang.org/protobuf/reflect/protoregistry"
Damien Neil0d3e8cc2019-04-01 13:31:55 -070016)
17
18// Methoder is an optional interface implemented by generated messages to
19// provide fast-path implementations of various operations.
20type Methoder interface {
21 XXX_Methods() *Methods // may return nil
22}
23
24// Methods is a set of optional fast-path implementations of various operations.
25type 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 Neil4686e232019-04-05 13:31:40 -070030 // It does not perform required field checks.
Damien Neil0d3e8cc2019-04-01 13:31:55 -070031 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 Neil0d3e8cc2019-04-01 13:31:55 -070036 // Unmarshal parses the wire-format message in b and places the result in m.
Damien Neil4686e232019-04-05 13:31:40 -070037 // It does not reset m or perform required field checks.
Damien Neil0d3e8cc2019-04-01 13:31:55 -070038 Unmarshal func(b []byte, m protoreflect.ProtoMessage, opts UnmarshalOptions) error
39
Damien Neil4686e232019-04-05 13:31:40 -070040 // IsInitialized returns an error if any required fields in m are not set.
41 IsInitialized func(m protoreflect.ProtoMessage) error
42
Damien Neil0d3e8cc2019-04-01 13:31:55 -070043 pragma.NoUnkeyedLiterals
44}
45
46// MethodFlag indicates support for optional fast-path features.
47type MethodFlag int64
48
49const (
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.
57type MarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070058 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070059 Deterministic bool
Damien Neil03e74862019-04-07 18:18:31 -070060 UseCachedSize bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070061
62 pragma.NoUnkeyedLiterals
63}
64
65// UnmarshalOptions configures the unmarshaler.
66//
67// This type is identical to the one in package proto.
68type UnmarshalOptions struct {
Damien Neil96c229a2019-04-03 12:17:24 -070069 AllowPartial bool
Damien Neil0d3e8cc2019-04-01 13:31:55 -070070 DiscardUnknown bool
Joe Tsai1c283042019-05-14 14:28:19 -070071 Resolver interface {
72 protoregistry.ExtensionTypeResolver
73 }
Damien Neil0d3e8cc2019-04-01 13:31:55 -070074
75 pragma.NoUnkeyedLiterals
76}