diff options
author | Abhilash Pallerlamudi <stp.abhi@gmail.com> | 2022-11-10 16:10:49 -0800 |
---|---|---|
committer | Michael Stapelberg <stapelberg@google.com> | 2023-03-15 15:17:00 +0000 |
commit | e344383da66ac9cf11000f824674793a77fc7d7e (patch) | |
tree | fad4063695bd3e1588ec81f15f57b66d12e07576 | |
parent | 32efccd1582255f0ef48bcc3942484e81985c76b (diff) | |
download | golang-protobuf-e344383da66ac9cf11000f824674793a77fc7d7e.tar.gz |
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 <stapelberg@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Reviewed-by: Lasse Folger <lassefolger@google.com>
-rw-r--r-- | protoadapt/convert.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/protoadapt/convert.go b/protoadapt/convert.go new file mode 100644 index 00000000..ce172386 --- /dev/null +++ b/protoadapt/convert.go @@ -0,0 +1,31 @@ +// Copyright 2023 The Go Authors. All rights reserved. +// Use of this source code is governed by a BSD-style +// license that can be found in the LICENSE file. + +// Package protoadapt bridges the original and new proto APIs. +package protoadapt + +import ( + "google.golang.org/protobuf/proto" + "google.golang.org/protobuf/runtime/protoiface" + "google.golang.org/protobuf/runtime/protoimpl" +) + +// MessageV1 is the original "github.com/golang/protobuf/proto".Message type. +type MessageV1 = protoiface.MessageV1 + +// MessageV2 is the Message type used by the current google.golang.org/protobuf +// module, adding support for reflection. +type MessageV2 = proto.Message + +// MessageV1Of converts a v2 message to a v1 message. +// It returns nil if m is nil. +func MessageV1Of(m MessageV2) protoiface.MessageV1 { + return protoimpl.X.ProtoMessageV1Of(m) +} + +// MessageV2Of converts a v1 message to a v2 message. +// It returns nil if m is nil. +func MessageV2Of(m MessageV1) proto.Message { + return protoimpl.X.ProtoMessageV2Of(m) +} |