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

returning bytes as a utf8-encoded string #103

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

DianaSuvorova
Copy link
Contributor

Currently bytes are returned as an array of bytes, which gets transferred as an array of numbers in Json.
Before

This pr changes so the input and the output for Bytes is expected to be utf-8 encoded string

After

@sheepdreamofandroids
Copy link
Contributor

Bytes are just small integer numbers, why would you assume that an array of them is a String? In UTF-8 even, why not ASCII?
I could understand if this were an array of characters.
Am I missing something?

@DianaSuvorova
Copy link
Contributor Author

@sheepdreamofandroids you are correct, bytes are just small numbers. In case when you communicate over Json, there is no such type as byte, so byte array will be transferred as an array of integers. So normally if you need to transfer byteArray via Json you'd convert it to string, most commonly using base64. In this particular example, I thought using utf-8 is ok, because these bytes are from proto's byteString which I thought already is using utf-8. internally, but I might be totally wrong, and it may need other decoder.

@sheepdreamofandroids
Copy link
Contributor

I see, you simply want a more compact encoding of the bytes.
In that case I think that base64 is much safer than a straightforward conversion to text because you avoid all kinds of transformations based on encodings.
On the other hand, if that kind of efficiency is important to you, why not use protobuf or another binary encoding on the client side as well? Nobody forces you to use JSON.

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.

None yet

2 participants