-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Implement FromBase64 for &[u8]. #15810
Conversation
The algorithm was already based on bytes internally. Also use byte literals instead of casting u8 to char for matching.
This impl used to exist and was removed when that module was overhauled. (Not that that means that it couldn't be added back.) |
Yes this was an explicit decision because base64 encodes to a string and decodes to a stream of bytes, and the two halves provide a clear separation of what's on each side of each boundary. Is the impetus for this that the utf8 validation is too expensive to perform ahead of time? |
TL;DR: I think I came across this in Servo when "fetching" URLs in the Many network protocol and file formats designed before Unicode was considered universal use "bytes in an undetermined ASCII-compatible encoding" to represent text. This means that non-ASCII bytes are opaque (until the encoding is determined), but they’re not necessarily invalid and should be preserved. While I wish UTF-8 was everywhere and I advocate cleanly separating bytes and Unicode to avoid Mojibake, I don’t think we should be dogmatic and say that anything text-like must be Unicode. The new I suppose we could have |
I realize that "streaming" base64 might also be interested. Does it sound like something you’d want in libserialize? Should it be based on |
I have prototypes of streaming implementations of |
@sfackler What kind of stream do you use? |
It used |
@sfackler, why these two among the four possible combinations of writers/readers and encoding/decoding? |
Those seemed like the more common cases, but there's no reason that all 4 shouldn't be implemented. |
For reference, Apache Commons-Codec provides |
The algorithm was already based on bytes internally. Also use byte literals instead of casting u8 to char for matching. [breaking-change] The `InvalidBase64Character` variant of the `FromBase64Error` enum was renamed to `InvalidBase64Byte`, and contains a `u8` instead of a `char`. r? @alexcrichton
…eykril fix: assists panic when trying to edit usage inside macro When we try to make a syntax node mutable inside a macro to edit it, it seems like the edits aren't properly reflected and will cause a panic when trying to make another syntax node mutable. This PR changes `bool_to_enum` and `promote_local_to_const` to use the original syntax range instead to edit the original file instead of the macro file. I'm not sure how to do it for `inline_call` with the example I mentioned in the issue, so I've left it out for now. Fixes rust-lang#15807
The algorithm was already based on bytes internally.
Also use byte literals instead of casting u8 to char for matching.
[breaking-change] The
InvalidBase64Character
variant of theFromBase64Error
enum was renamed toInvalidBase64Byte
, and contains au8
instead of achar
.r? @alexcrichton