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