Skip to content

Commit e344383

Browse files
stpabhistapelberg
authored andcommitted
protoadapt: helper functions to convert v1 or v2 message to either v1 or v2 message.
Fixes golang/protobuf#1442 Change-Id: I7ec60982be81d5dc060094ccec51d819b17a3a8f Reviewed-on: https://go-review.googlesource.com/c/protobuf/+/449576 Reviewed-by: Michael Stapelberg <[email protected]> Reviewed-by: Damien Neil <[email protected]> Reviewed-by: Lasse Folger <[email protected]>
1 parent 32efccd commit e344383

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

protoadapt/convert.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
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.
6+
package protoadapt
7+
8+
import (
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.
15+
type MessageV1 = protoiface.MessageV1
16+
17+
// MessageV2 is the Message type used by the current google.golang.org/protobuf
18+
// module, adding support for reflection.
19+
type MessageV2 = proto.Message
20+
21+
// MessageV1Of converts a v2 message to a v1 message.
22+
// It returns nil if m is nil.
23+
func MessageV1Of(m MessageV2) protoiface.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.
29+
func MessageV2Of(m MessageV1) proto.Message {
30+
return protoimpl.X.ProtoMessageV2Of(m)
31+
}

0 commit comments

Comments
 (0)