-
Notifications
You must be signed in to change notification settings - Fork 52
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
Properly encode Uint8Array fields #23
Properly encode Uint8Array fields #23
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here with What to do if you already signed the CLAIndividual signers
Corporate signers
ℹ️ Googlers: Go here for more info. |
@googlebot I signed it! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I like the replacer idea. It helps base64 encoded the uint8array before transfer. It does cover the data going up to the server, however I believe the data coming back down from the server are also base64 encoded. It would be nice to have the other side covered too.
For this case I would like to see an integration test to ensure the encoding/decoding logic. Could you please add a test into the integration_test
folder? A simple bytes echo case should suffice. There's a README.md
file in the folder to get you started.
Again, your contribution is much appreciated.
Sorry for the late reply as well. |
Yep, sure. |
de8dd72
to
a0406df
Compare
I've added the tests, sorry for the delay. Regarding the I was looking at how you can get type fields at the compile time and got lost in So I won't make this change in this PR. At least |
Ugh, well. I was testing that more in my code and looks like |
I see where you could stuck when the information coming down from the server, it's hard to tell as you said it's a string. And even if you use some test library to test if it was a base64 encoded string, you couldn't tell whether the field was an uint8array or not. In this case you'll be looking for the compiler to generate some information to feed in the fetch call so that when the response comes back you can tell which field needs to be properly translate back to uint8array. Doing just on the way up it is fine for this PR but if the problem on the way down is not properly solved it might need the user to do some type casting or ts-ignore as the typescript is expecting the field to be an uint8array, which is not that nice. |
https://github.com/protobufjs/protobuf.js/blob/master/lib/base64/index.js#L42 |
a0406df
to
4cb959e
Compare
Fixes: grpc-ecosystem#22 Binary data should be represented as `base64` encoded string in the JSON encoded body. Use replacer to return `base64` encoded string when `Uint8Array` type is detected. Signed-off-by: Artem Chernyshev <artem.0xD2@gmail.com>
4cb959e
to
f6cb5af
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thank you for your contribution
I won't be making a release just yet until the receiver side's fixed. if you are interested to pick it up, let me know. |
I have plenty of other stuff on my plate already. The fix for the receiver side doesn't look simple while using typescript |
Fixes: #22
Binary data should be represented as
base64
encoded string in the JSONencoded body.
Use replacer to return
base64
encoded string whenUint8Array
type isdetected.
Signed-off-by: Artem Chernyshev artem.0xD2@gmail.com