convert.go

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