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

all: byte => u8

This commit is contained in:
Alexander Medvednikov
2022-04-15 14:58:56 +03:00
parent b49d873217
commit d4a0d6f73c
221 changed files with 1365 additions and 1365 deletions

View File

@ -57,11 +57,11 @@ fn encode_from_buffer(dest &byte, src &byte, src_len int) int {
match remain {
2 {
b[di + 2] = etable[val >> 6 & 0x3F]
b[di + 3] = byte(`=`)
b[di + 3] = u8(`=`)
}
1 {
b[di + 2] = byte(`=`)
b[di + 3] = byte(`=`)
b[di + 2] = u8(`=`)
b[di + 3] = u8(`=`)
}
else {
panic('base64: This case should never occur.')
@ -125,9 +125,9 @@ fn decode_from_buffer(dest &byte, src &byte, src_len int) int {
for src_len - si >= 8 {
// Converting 8 bytes of input into 6 bytes of output. Storing these in the upper bytes of an u64.
datablock_64.data = assemble64(byte(index[d[si + 0]]), byte(index[d[si + 1]]),
byte(index[d[si + 2]]), byte(index[d[si + 3]]), byte(index[d[si + 4]]),
byte(index[d[si + 5]]), byte(index[d[si + 6]]), byte(index[d[si + 7]]))
datablock_64.data = assemble64(u8(index[d[si + 0]]), u8(index[d[si + 1]]),
u8(index[d[si + 2]]), u8(index[d[si + 3]]), u8(index[d[si + 4]]),
u8(index[d[si + 5]]), u8(index[d[si + 6]]), u8(index[d[si + 7]]))
// Reading out the individual bytes from the u64. Watch out with endianess.
$if little_endian {
@ -151,8 +151,8 @@ fn decode_from_buffer(dest &byte, src &byte, src_len int) int {
}
for src_len - si >= 4 {
datablock_32.data = assemble32(byte(index[d[si + 0]]), byte(index[d[si + 1]]),
byte(index[d[si + 2]]), byte(index[d[si + 3]]))
datablock_32.data = assemble32(u8(index[d[si + 0]]), u8(index[d[si + 1]]),
u8(index[d[si + 2]]), u8(index[d[si + 3]]))
$if little_endian {
b[n_decoded_bytes + 0] = datablock_32.data_byte[3]
b[n_decoded_bytes + 1] = datablock_32.data_byte[2]

View File

@ -111,23 +111,23 @@ fn test_url_decode_str() {
assert test == 'Hello Base64Url encoding!'
}
fn test_encode_null_byte() {
assert base64.encode([byte(`A`), 0, `C`]) == 'QQBD'
fn test_encode_null_u8() {
assert base64.encode([u8(`A`), 0, `C`]) == 'QQBD'
}
fn test_encode_null_byte_str() {
// While this works, bytestr() does a memcpy
s := [byte(`A`), 0, `C`].bytestr()
s := [u8(`A`), 0, `C`].bytestr()
assert base64.encode_str(s) == 'QQBD'
}
fn test_decode_null_byte() {
assert base64.decode('QQBD') == [byte(`A`), 0, `C`]
fn test_decode_null_u8() {
assert base64.decode('QQBD') == [u8(`A`), 0, `C`]
}
fn test_decode_null_byte_str() {
// While this works, bytestr() does a memcpy
s := [byte(`A`), 0, `C`].bytestr()
s := [u8(`A`), 0, `C`].bytestr()
assert base64.decode_str('QQBD') == s
}