mirror of
https://github.com/vlang/v.git
synced 2023-08-10 21:13:21 +03:00
all: replace []byte with []u8
This commit is contained in:
@@ -215,7 +215,7 @@ pub fn decode_str(data string) string {
|
||||
}
|
||||
}
|
||||
|
||||
// encode encodes the `[]byte` value passed in `data` to base64.
|
||||
// encode encodes the `[]u8` value passed in `data` to base64.
|
||||
// Please note: base64 encoding returns a `string` that is ~ 4/3 larger than the input.
|
||||
// Please note: If you need to encode many strings repeatedly, take a look at `encode_in_buffer`.
|
||||
// Example: assert base64.encode('V in base 64') == 'ViBpbiBiYXNlIDY0'
|
||||
|
||||
@@ -17,7 +17,7 @@ const (
|
||||
|
||||
// url_decode returns a decoded URL `string` version of
|
||||
// the a base64 url encoded `string` passed in `data`.
|
||||
pub fn url_decode(data string) []byte {
|
||||
pub fn url_decode(data string) []u8 {
|
||||
mut result := data.replace_each(['-', '+', '_', '/'])
|
||||
match result.len % 4 {
|
||||
// Pad with trailing '='s
|
||||
@@ -42,7 +42,7 @@ pub fn url_decode_str(data string) string {
|
||||
|
||||
// url_encode returns a base64 URL encoded `string` version
|
||||
// of the value passed in `data`.
|
||||
pub fn url_encode(data []byte) string {
|
||||
pub fn url_encode(data []u8) string {
|
||||
return encode(data).replace_each(['+', '-', '/', '_', '=', ''])
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ fn test_long_encoding() {
|
||||
repeats := 1000
|
||||
input_size := 3000
|
||||
|
||||
s_original := []byte{len: input_size, init: `a`}
|
||||
s_original := []u8{len: input_size, init: `a`}
|
||||
s_encoded := base64.encode(s_original)
|
||||
s_encoded_bytes := s_encoded.bytes()
|
||||
s_decoded := base64.decode(s_encoded)
|
||||
@@ -20,7 +20,7 @@ fn test_long_encoding() {
|
||||
}
|
||||
//
|
||||
encoded_size := base64.encode_in_buffer(s_original, ebuffer)
|
||||
mut encoded_in_buf := []byte{len: encoded_size}
|
||||
mut encoded_in_buf := []u8{len: encoded_size}
|
||||
unsafe { C.memcpy(encoded_in_buf.data, ebuffer, encoded_size) }
|
||||
assert input_size * 4 / 3 == encoded_size
|
||||
assert encoded_in_buf[0] == `Y`
|
||||
@@ -37,7 +37,7 @@ fn test_long_encoding() {
|
||||
|
||||
decoded_size := base64.decode_in_buffer(s_encoded, dbuffer)
|
||||
assert decoded_size == input_size
|
||||
mut decoded_in_buf := []byte{len: decoded_size}
|
||||
mut decoded_in_buf := []u8{len: decoded_size}
|
||||
unsafe { C.memcpy(decoded_in_buf.data, dbuffer, decoded_size) }
|
||||
assert decoded_in_buf == s_original
|
||||
|
||||
|
||||
@@ -137,9 +137,9 @@ fn test_decode_in_buffer_bytes() {
|
||||
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}
|
||||
mut src_dec_buf := []u8{len: 8}
|
||||
mut src_enc_buf := []u8{len: 8}
|
||||
mut out_buf := []u8{len: 8}
|
||||
|
||||
for p in rfc4648_pairs {
|
||||
src_dec_buf = p.decoded.bytes()
|
||||
|
||||
Reference in New Issue
Block a user