-
Notifications
You must be signed in to change notification settings - Fork 243
Encoders extensions with base64 encode/decode support #373
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
Conversation
Closes #374 |
ext/README.md
Outdated
|
||
### Base64.Decode | ||
|
||
Decodes a base64-encoded string to an unencoded string value. |
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 guess I'm showing my age - I first read that as "uuencoded", which seemed like an odd choice.
Base64 decodes to arbitrary binary data, so this should be bytes. If it's actually ASCII or UTF8 data, the call can be wrapped with string()
.
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.
Fair enough, I'll decode to bytes
ext/README.md
Outdated
|
||
### Base64.Encode | ||
|
||
Encodes a bytes or string input to a base64-encoded string. |
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.
Specify that the string-accepting version converts to utf-8 bytes first. Consider accepting only bytes input and rely composition with explicit bytes()
conversion, as this might be less error-prone.
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 think I'll still provide functions for both string
and bytes
inputs for simplicity on the encoding side since the composition would suffer from the same issues as the string
based overload.
4887fc4
to
907991f
Compare
PTAL |
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.
Looks good modulo some doc/comment improvements. While the CEL language gives utf8 the preferred treatment in the library for the standard string-to-bytes and bytes-to-string conversions, it's not necessarily true that the runtime representation of strings will be utf8 in all CEL implementations.
This function will return an error if the UTF-8 string input is not | ||
base64-encoded. | ||
|
||
base64.decode(<bytes>) -> <bytes> |
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.
Specify that the bytes are interpreted as a utf8-encoded string.
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.
Actually, the bytes
are just treated as a raw byte
sequence with no assumptions of utf-8 encoding.
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.
Then how do you interpret the sequence of bytes as characters without assuming the character encoding? What if I give it some base64-encoded text, using utf16 as the text-to-binary encoding? If the Go library decodes a sequence of bytes, it must do it by assuming a text encoding. That's the assumption that must be surfaced.
Encodes a bytes or string input to base64-encoded bytes. | ||
|
||
base64.encode(<bytes>) -> <bytes> | ||
base6 8000 4.encode(<string>) -> <bytes> |
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.
Specify the the string is converted to bytes via utf8, then encoded.
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.
Done.
// | ||
// This function will return an error if the UTF-8 string input is not base64-encoded. | ||
// | ||
// base64.decode(<bytes>) -> <bytes> |
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.
Same comments from the Readme apply here.
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.
Done.
Extensions for base64 encoding and decoding strings and, as appropriate, bytes.