Skip to content

jsonpb: Adds support for other []byte types to be base64 encoded. #188

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

Closed
wants to merge 1 commit into from

Conversation

d4l3k
Copy link

@d4l3k d4l3k commented May 24, 2016

The proto3 spec encodes the bytes type to be a base64 encoded string
when marshalling to jsonpb. This adds support to jsonpb to correctly
encode go types in the format type Bytes []byte into base64 instead of
being represented as an uint8 array.

While these types won't be generated by the standard protobuf compiler,
they can be generated by others such as gogo protobuf.

@tamird
Copy link
Contributor

tamird commented May 25, 2016

cc @awalterschulze

@awalterschulze
Copy link

Yes it doesn't seem like this code will break any previous assumptions it just allows a very cases.

@@ -282,6 +282,18 @@ func init() {
}
}

// Bytes is used to test that []byte type aliases are serialized to base64.
type Bytes []byte
Copy link
Contributor

Choose a reason for hiding this comment

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

this test can be made slightly more complete with:

// Byte is used to test that []byte type aliases are base64-encoded.
type Byte byte

// Bytes is used to test that []byte type aliases are base64-encoded.
type Bytes []Byte

Copy link
Author

Choose a reason for hiding this comment

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

Done.

@d4l3k d4l3k force-pushed the byte-array-check branch from 26f968c to 5414c5d Compare May 26, 2016 16:12
@tamird
Copy link
Contributor

tamird commented May 26, 2016

@matloob @dsymonds could you take a look at this?

The proto3 spec encodes the bytes type to be a base64 encoded string
when marshalling to jsonpb. This adds support to jsonpb to correctly
encode go types in the format `type Bytes []byte` into base64 instead of
being represented as an uint8 array.

While these types won't be generated by the standard protobuf compiler,
they can be generated by others such as gogo protobuf.
@d4l3k
Copy link
Author

d4l3k commented May 31, 2016

Any update on this? This is blocking cockroachdb/cockroach#6973.

@matloob
Copy link
Contributor

matloob commented May 31, 2016

Hi!

I'm unfamiliar with gogoprotobuf and the bug this is blocking. Could you help fill us in on some of the details?

I wasn't able to figure out how cockroachdb/cockroach#6973 uses this change. Could you provide some more information? Is there a way to unblock that change without making this change?

It would also be really helpful to get some more context on gogoprotobuf. When do the other []byte types get generated? If they're only generated by gogoprotobuf, could this change be made the gogoprotobuf fork directly?

Thanks,
Michael

@tamird
Copy link
Contributor

tamird commented May 31, 2016

I wasn't able to figure out how cockroachdb/cockroach#6973 uses this change. Could you provide some more information?

That change wants to use jsonpb marshalling of messages which include aliases of []byte, so this correct reflection code is needed to do that correctly.

Is there a way to unblock that change without making this change?

No. This change has to be made - either here or in gogoprotobuf.

It would also be really helpful to get some more context on gogoprotobuf. When do the other []byte types get generated?

They are generated when a field is tagged with the gogoproto.casttype option.

If they're only generated by gogoprotobuf, could this change be made the gogoprotobuf fork directly?

Yes, this PR has been submitted to gogoprotobuf as well, but @awalterschulze would like to minimize drift.

I think this change is fine here -- it's subtle, but the proposed code is more correct.

@matloob
Copy link
Contributor

matloob commented May 31, 2016

Thanks!

I think we have a better understanding of the issue here. Please correct me if we got anything wrong.

If possible, it would be ideal for the change made in gogoprotobuf since the other []byte fields are generated by the gogoprotobuf code generator. We'd prefer to avoid adding a test case on a generated field type that the proto package doesn't produce.

Michael

@tamird
Copy link
Contributor

tamird commented May 31, 2016

I agree regarding the tests, but I don't know that there's any downside in accepting the slightly more correct reflection code. The upside is that it reduces the burden of maintainership downstream.

@matloob
Copy link
Contributor

matloob commented May 31, 2016

We understand the desire to reduce the burden of maintainership downstream, but doing so would increase the burden of maintainership upstream.

The test in this change enforces a new invariant in how the proto package handles generated structs. The upstream protobuf library would then implicitly support the 'gogoproto.casttype' option in the 'downstream' gogoprotobuf library.

@tamird
Copy link
Contributor

tamird commented May 31, 2016

Right, I was suggesting that the tests be backed out.
On May 31, 2016 18:58, "Michael Matloob" [email protected] wrote:

We understand the desire to reduce the burden of maintainership
downstream, but doing so would increase the burden of maintainership
upstream.

The test in this change enforces a new invariant in how the proto package
handles generated structs. The upstream protobuf library would then
implicitly support the 'gogoproto.casttype' option in the 'downstream'
gogoprotobuf library.


You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
#188 (comment), or mute
the thread
https://github.com/notifications/unsubscribe/ABdsPCOcLJL7O0MWPDDAWgXcVJ9DETyfks5qHL0XgaJpZM4Il_nD
.

@matloob
Copy link
Contributor

matloob commented May 31, 2016

Ah, sorry -- I misunderstood that!

In that case I don't see any issues in making this change. Let me double check, though. I'l get back to this thread tomorrow.

@matloob matloob closed this in 3b06fc7 Jun 1, 2016
@d4l3k
Copy link
Author

d4l3k commented Jun 2, 2016

@awalterschulze Any ETA on when 3b06fc7 will get merged into gogo/protobuf?

@awalterschulze
Copy link

I don't think this is the place. Lets discuss it here gogo/protobuf#183

@golang golang locked and limited conversation to collaborators Jun 26, 2020
chenyt9 pushed a commit to MotorolaMobilityLLC/external-golang-protobuf that referenced this pull request Jul 12, 2023
This is meant to fix golang/protobuf#188. There
are no tests because we don't guarantee that we're going to maintain
this behavior in the future.

Fixes #188
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants