proto.go 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  1. // Copyright 2018 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 proto
  5. import (
  6. "google.golang.org/protobuf/internal/errors"
  7. "google.golang.org/protobuf/reflect/protoreflect"
  8. )
  9. // Message is the top-level interface that all messages must implement.
  10. // It provides access to a reflective view of a message.
  11. // Any implementation of this interface may be used with all functions in the
  12. // protobuf module that accept a Message, except where otherwise specified.
  13. //
  14. // This is the v2 interface definition for protobuf messages.
  15. // The v1 interface definition is [github.com/golang/protobuf/proto.Message].
  16. //
  17. // - To convert a v1 message to a v2 message,
  18. // use [google.golang.org/protobuf/protoadapt.MessageV2Of].
  19. // - To convert a v2 message to a v1 message,
  20. // use [google.golang.org/protobuf/protoadapt.MessageV1Of].
  21. type Message = protoreflect.ProtoMessage
  22. // Error matches all errors produced by packages in the protobuf module
  23. // according to [errors.Is].
  24. //
  25. // Example usage:
  26. //
  27. // if errors.Is(err, proto.Error) { ... }
  28. var Error error
  29. func init() {
  30. Error = errors.Error
  31. }
  32. // MessageName returns the full name of m.
  33. // If m is nil, it returns an empty string.
  34. func MessageName(m Message) protoreflect.FullName {
  35. if m == nil {
  36. return ""
  37. }
  38. return m.ProtoReflect().Descriptor().FullName()
  39. }