proto.go 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  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 "github.com/golang/protobuf/proto".MessageV2.
  19. // To convert a v2 message to a v1 message,
  20. // use "github.com/golang/protobuf/proto".MessageV1.
  21. type Message = protoreflect.ProtoMessage
  22. // Error matches all errors produced by packages in the protobuf module.
  23. //
  24. // That is, errors.Is(err, Error) reports whether an error is produced
  25. // by this module.
  26. var Error error
  27. func init() {
  28. Error = errors.Error
  29. }
  30. // MessageName returns the full name of m.
  31. // If m is nil, it returns an empty string.
  32. func MessageName(m Message) protoreflect.FullName {
  33. if m == nil {
  34. return ""
  35. }
  36. return m.ProtoReflect().Descriptor().FullName()
  37. }