xref: /aosp_15_r20/external/golang-protobuf/proto/proto.go (revision 1c12ee1efe575feb122dbf939ff15148a3b3e8f2)
1*1c12ee1eSDan Willemsen// Copyright 2018 The Go Authors. All rights reserved.
2*1c12ee1eSDan Willemsen// Use of this source code is governed by a BSD-style
3*1c12ee1eSDan Willemsen// license that can be found in the LICENSE file.
4*1c12ee1eSDan Willemsen
5*1c12ee1eSDan Willemsenpackage proto
6*1c12ee1eSDan Willemsen
7*1c12ee1eSDan Willemsenimport (
8*1c12ee1eSDan Willemsen	"google.golang.org/protobuf/internal/errors"
9*1c12ee1eSDan Willemsen	"google.golang.org/protobuf/reflect/protoreflect"
10*1c12ee1eSDan Willemsen)
11*1c12ee1eSDan Willemsen
12*1c12ee1eSDan Willemsen// Message is the top-level interface that all messages must implement.
13*1c12ee1eSDan Willemsen// It provides access to a reflective view of a message.
14*1c12ee1eSDan Willemsen// Any implementation of this interface may be used with all functions in the
15*1c12ee1eSDan Willemsen// protobuf module that accept a Message, except where otherwise specified.
16*1c12ee1eSDan Willemsen//
17*1c12ee1eSDan Willemsen// This is the v2 interface definition for protobuf messages.
18*1c12ee1eSDan Willemsen// The v1 interface definition is "github.com/golang/protobuf/proto".Message.
19*1c12ee1eSDan Willemsen//
20*1c12ee1eSDan Willemsen// To convert a v1 message to a v2 message,
21*1c12ee1eSDan Willemsen// use "github.com/golang/protobuf/proto".MessageV2.
22*1c12ee1eSDan Willemsen// To convert a v2 message to a v1 message,
23*1c12ee1eSDan Willemsen// use "github.com/golang/protobuf/proto".MessageV1.
24*1c12ee1eSDan Willemsentype Message = protoreflect.ProtoMessage
25*1c12ee1eSDan Willemsen
26*1c12ee1eSDan Willemsen// Error matches all errors produced by packages in the protobuf module.
27*1c12ee1eSDan Willemsen//
28*1c12ee1eSDan Willemsen// That is, errors.Is(err, Error) reports whether an error is produced
29*1c12ee1eSDan Willemsen// by this module.
30*1c12ee1eSDan Willemsenvar Error error
31*1c12ee1eSDan Willemsen
32*1c12ee1eSDan Willemsenfunc init() {
33*1c12ee1eSDan Willemsen	Error = errors.Error
34*1c12ee1eSDan Willemsen}
35*1c12ee1eSDan Willemsen
36*1c12ee1eSDan Willemsen// MessageName returns the full name of m.
37*1c12ee1eSDan Willemsen// If m is nil, it returns an empty string.
38*1c12ee1eSDan Willemsenfunc MessageName(m Message) protoreflect.FullName {
39*1c12ee1eSDan Willemsen	if m == nil {
40*1c12ee1eSDan Willemsen		return ""
41*1c12ee1eSDan Willemsen	}
42*1c12ee1eSDan Willemsen	return m.ProtoReflect().Descriptor().FullName()
43*1c12ee1eSDan Willemsen}
44