methods.go 2.1 KB

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