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 [google.golang.org/protobuf/protoadapt.MessageV2Of].
22 // - To convert a v2 message to a v1 message,
23 // use [google.golang.org/protobuf/protoadapt.MessageV1Of].
24 type Message = protoreflect.ProtoMessage
25 26 // Error matches all errors produced by packages in the protobuf module
27 // according to [errors.Is].
28 //
29 // Example usage:
30 //
31 // if errors.Is(err, proto.Error) { ... }
32 var Error error
33 34 func init() {
35 Error = errors.Error
36 }
37 38 // MessageName returns the full name of m.
39 // If m is nil, it returns an empty string.
40 func MessageName(m Message) protoreflect.FullName {
41 if m == nil {
42 return ""
43 }
44 return m.ProtoReflect().Descriptor().FullName()
45 }
46