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

Protobuf API V2: compatibility fixes #94

Merged
merged 3 commits into from
Aug 20, 2021

Conversation

seena-stripe
Copy link
Collaborator

Summary

Two fixes to maintain compatibility with the old implementation

  • Add json module members for compat (852f982):
    json.marshal became json.encode. Added these aliases back like we do for yamlModule
  • Allow constructing message maps with None (416b96c):
    Skycfg previously allowed setting proto2 message values with None, effectively unsetting them. For maps, this set them to be nil, so
# skycfg
msg.map_submsg = { 
  "a": None
}

became

&pb.MessageV2{
  map_submsg: map[string]*pb.MessageV2{
    "a": nil,
  }
}

With protoreflect, map.Set only accepts a protoreflect.Value https://pkg.go.dev/google.golang.org/protobuf/reflect/protoreflect#Map.Set (a struct, cannot be nil) so my two options are 1) create an empty &pb.MessageV2{} or treat None as not setting the key. I went with the latter, to make it behave like protoMessage but neither option seems great

Tests

I added a test for compatibility

}
// Pre 1.0 compatibility allowed maps to be constructed with None in proto2
// with the value treated as nil. protoreflect does not allow setting
// with a value of nil, so instead treat it as an unset
Copy link
Collaborator

Choose a reason for hiding this comment

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

thanks for including this comment!

go/protomodule/protomodule_message_test.go Show resolved Hide resolved
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants