-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
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
rework std.base64 api #621
Conversation
Now that i'm looking at it, i want to move the decode functions into the "Alphabet" structs, and rename the "Alphabet" structs to "Decoder". |
Looks good to me, feel free to merge. However I'd like to suggest not using "unsafe" to communicate that something could be an undefined value. "unsafe" usually communicates that something could be undefined behavior which is very different. |
would "unchecked" be better than "unsafe"? |
yes |
actually |
Ok sounds like it's good to merge then |
Do you have an opinion on this new OOP-looking API? Seems like the namespace is cleaner, and I like the new comptime asserts for encoding. |
* rename decode to decodeExactUnsafe. * add decodeExact, which checks for invalid chars and padding. * add decodeWithIgnore, which also allows ignoring chars. * alphabets are supplied to the decoders with their char-to-index mapping already built, which enables it to be done at comptime. * all decode/encode apis except decodeWithIgnore require dest to be the exactly correct length. This is calculated by a calc function corresponding to each api. These apis no longer return the dest parameter. * for decodeWithIgnore, an exact size cannot be known a priori. Instead, a calc function gives an upperbound, and a runtime error is returned in case of overflow. decodeWithIgnore returns the number of bytes written to dest. closes #611
I just started trying to write a simple base64 transform command line program using this api, and i've immediately run into a design limitation 😞. The existing API is hostile to streaming. New idea. Replace the Base64DecoderWithIgnore class with a streaming decoder. It's already behaving a lot like a streaming decoder internally anyway. That can be an improvement after this PR is merged though. And I probably won't have time to do that in the immediate future. |
char-to-index mapping already built, which enables it to be
done at comptime.
to be the exactly correct length. This is calculated by a
calc function corresponding to each api. These apis no longer
return the dest parameter.
Instead, a calc function gives an upperbound, and a runtime
error is returned in case of overflow. decodeWithIgnore
returns the number of bytes written to dest.
closes #611