blob: 7543ee6b255d828c96e95c81dd91e6e911bf5a58 [file] [log] [blame]
khenaidoo106c61a2021-08-11 18:05:46 -04001// 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
5package proto
6
7import (
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.
Abhay Kumara61c5222025-11-10 07:32:50 +000018// The v1 interface definition is [github.com/golang/protobuf/proto.Message].
khenaidoo106c61a2021-08-11 18:05:46 -040019//
Abhay Kumara61c5222025-11-10 07:32:50 +000020// - 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].
khenaidoo106c61a2021-08-11 18:05:46 -040024type Message = protoreflect.ProtoMessage
25
Abhay Kumara61c5222025-11-10 07:32:50 +000026// Error matches all errors produced by packages in the protobuf module
27// according to [errors.Is].
khenaidoo106c61a2021-08-11 18:05:46 -040028//
Abhay Kumara61c5222025-11-10 07:32:50 +000029// Example usage:
30//
31// if errors.Is(err, proto.Error) { ... }
khenaidoo106c61a2021-08-11 18:05:46 -040032var Error error
33
34func 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.
40func MessageName(m Message) protoreflect.FullName {
41 if m == nil {
42 return ""
43 }
44 return m.ProtoReflect().Descriptor().FullName()
45}