blob: 7543ee6b255d828c96e95c81dd91e6e911bf5a58 [file] [log] [blame]
Naveen Sampath04696f72022-06-13 15:19:14 +05301// 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.
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +053018// The v1 interface definition is [github.com/golang/protobuf/proto.Message].
Naveen Sampath04696f72022-06-13 15:19:14 +053019//
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +053020// - 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].
Naveen Sampath04696f72022-06-13 15:19:14 +053024type Message = protoreflect.ProtoMessage
25
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +053026// Error matches all errors produced by packages in the protobuf module
27// according to [errors.Is].
Naveen Sampath04696f72022-06-13 15:19:14 +053028//
Akash Reddy Kankanala105581b2024-09-11 05:20:38 +053029// Example usage:
30//
31// if errors.Is(err, proto.Error) { ... }
Naveen Sampath04696f72022-06-13 15:19:14 +053032var 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}