1
0
mirror of https://github.com/vlang/v.git synced 2023-08-10 21:13:21 +03:00

encoding.base64: speed up encoding and decoding (#11055)

* add new function headers

* new encoding function

* rename to decode_micro and add helper functions

* implement new decoding function

* add test for buffer to buffer decoding

* - add notice to GO code
- v fmt base64.v

* implement new decoding function

* fix base64_memory_test.v by commenting a few lines

* vfmt base64.v

* add some more asserts to base64_memory_test.v

* remove unused decoding function

* add bounds check, when detecting the padding

* use union for storing the decoded data

Co-authored-by: Delyan Angelov <delian66@gmail.com>
This commit is contained in:
Sebastian Schicho
2021-08-06 23:09:55 +02:00
committed by GitHub
parent cf0767ad6c
commit 9995f6cca1
3 changed files with 198 additions and 75 deletions

View File

@@ -130,3 +130,21 @@ fn test_decode_null_byte_str() {
s := [byte(`A`), 0, `C`].bytestr()
assert base64.decode_str('QQBD') == s
}
fn test_decode_in_buffer_bytes() {
rfc4648_pairs := [
TestPair{'foob', 'Zm9vYg=='},
TestPair{'fooba', 'Zm9vYmE='},
TestPair{'foobar', 'Zm9vYmFy'},
]
mut src_dec_buf := []byte{len: 8}
mut src_enc_buf := []byte{len: 8}
mut out_buf := []byte{len: 8}
for p in rfc4648_pairs {
src_dec_buf = p.decoded.bytes()
src_enc_buf = p.encoded.bytes()
n := base64.decode_in_buffer_bytes(src_enc_buf, out_buf.data)
assert src_dec_buf == out_buf[..n]
}
}