Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deps: fix backwards compatibility with encoding #6965

Merged
merged 2 commits into from Feb 5, 2024
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
27 changes: 14 additions & 13 deletions encoding/proto/proto.go
Expand Up @@ -39,31 +39,32 @@ func init() {
type codec struct{}

func (codec) Marshal(v any) ([]byte, error) {
var vv proto.Message
switch v := v.(type) {
case protoadapt.MessageV1:
vv = protoadapt.MessageV2Of(v)
case protoadapt.MessageV2:
vv = v
default:
vv := messageV2Of(v)
if vv == nil {
return nil, fmt.Errorf("failed to marshal, message is %T, want proto.Message", v)
}

return proto.Marshal(vv)
}

func (codec) Unmarshal(data []byte, v any) error {
var vv proto.Message
vv := messageV2Of(v)
if vv == nil {
return fmt.Errorf("failed to marshal, message is %T, want proto.Message", v)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

*unmarshal

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

err... #6966 pls

}

return proto.Unmarshal(data, vv)
}

func messageV2Of(v any) proto.Message {
switch v := v.(type) {
case protoadapt.MessageV1:
vv = protoadapt.MessageV2Of(v)
return protoadapt.MessageV2Of(v)
case protoadapt.MessageV2:
vv = v
default:
return fmt.Errorf("failed to unmarshal, message is %T, want proto.Message", v)
return v
}

return proto.Unmarshal(data, vv)
return nil
}

func (codec) Name() string {
Expand Down