Skip to content

Commit

Permalink
minimize diffs
Browse files Browse the repository at this point in the history
  • Loading branch information
dfawley committed Aug 23, 2024
1 parent a83f106 commit 0ede3f6
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions encoding/proto/proto.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,6 @@ func init() {
// gRPC.
type codecV2 struct{}

var _ encoding.CodecV2 = (*codecV2)(nil)

func (c *codecV2) Marshal(v any) (data mem.BufferSlice, err error) {
vv := messageV2Of(v)
if vv == nil {
Expand All @@ -68,17 +66,6 @@ func (c *codecV2) Marshal(v any) (data mem.BufferSlice, err error) {
return data, nil
}

func messageV2Of(v any) proto.Message {
switch v := v.(type) {
case protoadapt.MessageV1:
return protoadapt.MessageV2Of(v)
case protoadapt.MessageV2:
return v
}

return nil
}

func (c *codecV2) Unmarshal(data mem.BufferSlice, v any) (err error) {
vv := messageV2Of(v)
if vv == nil {
Expand All @@ -93,6 +80,17 @@ func (c *codecV2) Unmarshal(data mem.BufferSlice, v any) (err error) {
return proto.Unmarshal(buf.ReadOnlyData(), vv)
}

func messageV2Of(v any) proto.Message {
switch v := v.(type) {
case protoadapt.MessageV1:
return protoadapt.MessageV2Of(v)
case protoadapt.MessageV2:
return v
}

return nil
}

func (c *codecV2) Name() string {
return Name
}

0 comments on commit 0ede3f6

Please sign in to comment.