1
0
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:
Alexander Medvednikov
2022-04-15 15:35:35 +03:00
parent 0527ac633e
commit fb192d949b
164 changed files with 533 additions and 533 deletions

View File

@ -31,7 +31,7 @@ fn test_integer_from_bytes() {
assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe, 0xba]).hex() == '1337cafeba'
assert big.integer_from_bytes([u8(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe]).hex() == '1337cafebabe'
mut bytes := []byte{cap: 1024}
mut bytes := []u8{cap: 1024}
mut expected := ''
for i := 0; i < bytes.cap; i++ {
bytes << u8(i)
@ -45,7 +45,7 @@ fn test_bytes() {
assert result1 == [u8(0x13), 0x37, 0xca, 0xfe, 0xba, 0xbe]
assert sign1 == 1
mut bytes := []byte{cap: 1024}
mut bytes := []u8{cap: 1024}
mut expected := ''
for i := 0; i < bytes.cap; i++ {
bytes << u8(i | 1)

View File

@ -108,13 +108,13 @@ pub struct IntegerConfig {
// integer_from_bytes creates a new `big.Integer` from the given byte array. By default, positive integers are assumed. If you want a negative integer, use in the following manner:
// `value := big.integer_from_bytes(bytes, signum: -1)`
pub fn integer_from_bytes(input []byte, config IntegerConfig) Integer {
pub fn integer_from_bytes(input []u8, config IntegerConfig) Integer {
// Thank you to Miccah (@mcastorina) for this implementation and relevant unit tests.
if input.len == 0 {
return integer_from_int(0)
}
// pad input
mut padded_input := []byte{len: ((input.len + 3) & ~0x3) - input.len, cap: (input.len + 3) & ~0x3, init: 0x0}
mut padded_input := []u8{len: ((input.len + 3) & ~0x3) - input.len, cap: (input.len + 3) & ~0x3, init: 0x0}
padded_input << input
mut digits := []u32{len: padded_input.len / 4}
// combine every 4 bytes into a u32 and insert into n.digits
@ -778,11 +778,11 @@ pub fn (a Integer) int() int {
// bytes returns the a byte representation of the integer a, along with the signum int.
// NOTE: The byte array returned is in big endian order.
pub fn (a Integer) bytes() ([]byte, int) {
pub fn (a Integer) bytes() ([]u8, int) {
if a.signum == 0 {
return []byte{len: 0}, 0
return []u8{len: 0}, 0
}
mut result := []byte{cap: a.digits.len * 4}
mut result := []u8{cap: a.digits.len * 4}
mut mask := u32(0xff000000)
mut offset := 24
mut non_zero_found := false

View File

@ -403,7 +403,7 @@ pub fn (u_ Uint128) str() string {
}
// put_bytes stores u in b in little-endian order
pub fn (u Uint128) put_bytes(mut b []byte) {
pub fn (u Uint128) put_bytes(mut b []u8) {
binary.little_endian_put_u64(mut b, u.lo)
binary.little_endian_put_u64(mut b, u.hi)
}