@@ -25,6 +25,7 @@ import (
25
25
26
26
"google.golang.org/grpc/encoding"
27
27
"google.golang.org/protobuf/proto"
28
+ "google.golang.org/protobuf/protoadapt"
28
29
)
29
30
30
31
// Name is the name registered for the proto compressor.
@@ -38,21 +39,34 @@ func init() {
38
39
type codec struct {}
39
40
40
41
func (codec ) Marshal (v any ) ([]byte , error ) {
41
- vv , ok := v .(proto. Message )
42
- if ! ok {
42
+ vv := messageV2Of ( v )
43
+ if vv == nil {
43
44
return nil , fmt .Errorf ("failed to marshal, message is %T, want proto.Message" , v )
44
45
}
46
+
45
47
return proto .Marshal (vv )
46
48
}
47
49
48
50
func (codec ) Unmarshal (data []byte , v any ) error {
49
- vv , ok := v .(proto. Message )
50
- if ! ok {
51
- return fmt .Errorf ("failed to unmarshal , message is %T, want proto.Message" , v )
51
+ vv := messageV2Of ( v )
52
+ if vv == nil {
53
+ return fmt .Errorf ("failed to marshal , message is %T, want proto.Message" , v )
52
54
}
55
+
53
56
return proto .Unmarshal (data , vv )
54
57
}
55
58
59
+ func messageV2Of (v any ) proto.Message {
60
+ switch v := v .(type ) {
61
+ case protoadapt.MessageV1 :
62
+ return protoadapt .MessageV2Of (v )
63
+ case protoadapt.MessageV2 :
64
+ return v
65
+ }
66
+
67
+ return nil
68
+ }
69
+
56
70
func (codec ) Name () string {
57
71
return Name
58
72
}
0 commit comments