convert.go 1013 B

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