golang / protobuf

Go support for Google's protocol buffers
BSD 3-Clause "New" or "Revised" License
9.74k stars 1.58k forks source link

JSON encoding option for hexadecimal #1539

Closed cpacia closed 1 year ago

cpacia commented 1 year ago

Is your feature request related to a problem? Please describe. I think #1030 should be revisited. It's standard practice in at least the crypto industry, maybe others, to marshal byte slices to hexadecimal rather than base64. There are literally dozens of projects maintaining forks of this repo because the json encoding package does not support this. This would be a 3 or 4 line change. Obviously if the protobuf spec calls for base64 encoding you can leave the base64 the default. But there's no reason to not include a marshal option for hexadecimal.

Maintaining forks used to be at least be someone easy when the encoding was in the jsonpb package as the footprint was fairly small. Now with all the restructuring and heavy use of internal packages the only way to maintain a fork of the encoding package is to maintain a fork of the entire repository.

Describe the solution you'd like A EncodeBytesAsHex option in the MarshalOptions.

Describe alternatives you've considered

puellanivis commented 1 year ago

Nothing has changed to this situation from what was already said in https://github.com/golang/protobuf/issues/1030#issuecomment-583511554

If you think this is a valuable feature, then it needs to be brought up in the main protobuf package: https://github.com/protocolbuffers/protobuf/issues

While no one is arguing that this wouldn’t be a short 3–4 line change, we must strictly hold to the standards for compatibility reasons. If it’s not in the main protobuf spec, we cannot do anything about it.

puellanivis commented 1 year ago

Closing, as a duplicate of an existing closed ticket, and nothing has changed since.