xref: /aosp_15_r20/external/golang-protobuf/protoadapt/convert.go (revision 1c12ee1efe575feb122dbf939ff15148a3b3e8f2)
1*1c12ee1eSDan Willemsen// Copyright 2023 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 Willemsen// Package protoadapt bridges the original and new proto APIs.
6*1c12ee1eSDan Willemsenpackage protoadapt
7*1c12ee1eSDan Willemsen
8*1c12ee1eSDan Willemsenimport (
9*1c12ee1eSDan Willemsen	"google.golang.org/protobuf/proto"
10*1c12ee1eSDan Willemsen	"google.golang.org/protobuf/runtime/protoiface"
11*1c12ee1eSDan Willemsen	"google.golang.org/protobuf/runtime/protoimpl"
12*1c12ee1eSDan Willemsen)
13*1c12ee1eSDan Willemsen
14*1c12ee1eSDan Willemsen// MessageV1 is the original "github.com/golang/protobuf/proto".Message type.
15*1c12ee1eSDan Willemsentype MessageV1 = protoiface.MessageV1
16*1c12ee1eSDan Willemsen
17*1c12ee1eSDan Willemsen// MessageV2 is the Message type used by the current google.golang.org/protobuf
18*1c12ee1eSDan Willemsen// module, adding support for reflection.
19*1c12ee1eSDan Willemsentype MessageV2 = proto.Message
20*1c12ee1eSDan Willemsen
21*1c12ee1eSDan Willemsen// MessageV1Of converts a v2 message to a v1 message.
22*1c12ee1eSDan Willemsen// It returns nil if m is nil.
23*1c12ee1eSDan Willemsenfunc MessageV1Of(m MessageV2) protoiface.MessageV1 {
24*1c12ee1eSDan Willemsen	return protoimpl.X.ProtoMessageV1Of(m)
25*1c12ee1eSDan Willemsen}
26*1c12ee1eSDan Willemsen
27*1c12ee1eSDan Willemsen// MessageV2Of converts a v1 message to a v2 message.
28*1c12ee1eSDan Willemsen// It returns nil if m is nil.
29*1c12ee1eSDan Willemsenfunc MessageV2Of(m MessageV1) proto.Message {
30*1c12ee1eSDan Willemsen	return protoimpl.X.ProtoMessageV2Of(m)
31*1c12ee1eSDan Willemsen}
32