methods.go 2.4 KB

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