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:
@@ -122,7 +122,7 @@ fn init() {
|
||||
C.atexit(deinit)
|
||||
}
|
||||
|
||||
fn read_32(mut rng PRNG, mut buf []byte) {
|
||||
fn read_32(mut rng PRNG, mut buf []u8) {
|
||||
p32 := unsafe { &u32(buf.data) }
|
||||
u32s := buf.len / 4
|
||||
for i in 0 .. u32s {
|
||||
@@ -135,7 +135,7 @@ fn read_32(mut rng PRNG, mut buf []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_64(mut rng PRNG, mut buf []byte) {
|
||||
fn read_64(mut rng PRNG, mut buf []u8) {
|
||||
p64 := unsafe { &u64(buf.data) }
|
||||
u64s := buf.len / 8
|
||||
for i in 0 .. u64s {
|
||||
@@ -148,7 +148,7 @@ fn read_64(mut rng PRNG, mut buf []byte) {
|
||||
}
|
||||
}
|
||||
|
||||
fn read_internal(mut rng PRNG, mut buf []byte) {
|
||||
fn read_internal(mut rng PRNG, mut buf []u8) {
|
||||
match rng.block_size() {
|
||||
32 {
|
||||
read_32(mut rng, mut buf)
|
||||
|
@@ -21,7 +21,7 @@ const (
|
||||
)
|
||||
|
||||
fn internal_ulid_at_millisecond(mut rng PRNG, unix_time_milli u64) string {
|
||||
mut buf := []byte{cap: 27}
|
||||
mut buf := []u8{cap: 27}
|
||||
mut t := unix_time_milli
|
||||
mut i := 9
|
||||
for i >= 0 {
|
||||
@@ -53,7 +53,7 @@ fn internal_ulid_at_millisecond(mut rng PRNG, unix_time_milli u64) string {
|
||||
return res
|
||||
}
|
||||
|
||||
fn read_internal(mut rng PRNG, mut buf []byte) {
|
||||
fn read_internal(mut rng PRNG, mut buf []u8) {
|
||||
for i in 0 .. buf.len {
|
||||
buf[i] = rng.u8()
|
||||
}
|
||||
|
@@ -26,19 +26,19 @@ mut:
|
||||
|
||||
// bytes returns a buffer of `bytes_needed` random bytes
|
||||
[inline]
|
||||
pub fn (mut rng PRNG) bytes(bytes_needed int) ?[]byte {
|
||||
pub fn (mut rng PRNG) bytes(bytes_needed int) ?[]u8 {
|
||||
if bytes_needed < 0 {
|
||||
return error('can not read < 0 random bytes')
|
||||
}
|
||||
|
||||
mut buffer := []byte{len: bytes_needed}
|
||||
mut buffer := []u8{len: bytes_needed}
|
||||
read_internal(mut rng, mut buffer)
|
||||
|
||||
return buffer
|
||||
}
|
||||
|
||||
// read fills in `buf` with a maximum of `buf.len` random bytes
|
||||
pub fn (mut rng PRNG) read(mut buf []byte) {
|
||||
pub fn (mut rng PRNG) read(mut buf []u8) {
|
||||
read_internal(mut rng, mut buf)
|
||||
}
|
||||
|
||||
@@ -490,12 +490,12 @@ pub fn f64_in_range(min f64, max f64) ?f64 {
|
||||
}
|
||||
|
||||
// bytes returns a buffer of `bytes_needed` random bytes
|
||||
pub fn bytes(bytes_needed int) ?[]byte {
|
||||
pub fn bytes(bytes_needed int) ?[]u8 {
|
||||
return default_rng.bytes(bytes_needed)
|
||||
}
|
||||
|
||||
// read fills in `buf` a maximum of `buf.len` random bytes
|
||||
pub fn read(mut buf []byte) {
|
||||
pub fn read(mut buf []u8) {
|
||||
read_internal(mut default_rng, mut buf)
|
||||
}
|
||||
|
||||
|
@@ -45,7 +45,7 @@ fn test_prng_rand_bytes() ? {
|
||||
|
||||
fn test_rand_read() ? {
|
||||
max := 50
|
||||
mut a := []byte{len: max}
|
||||
mut a := []u8{len: max}
|
||||
mut differences := 0
|
||||
for j in 1 .. max {
|
||||
start := '00'.repeat(j)
|
||||
@@ -74,7 +74,7 @@ fn test_rand_read() ? {
|
||||
|
||||
fn test_prng_rand_read() ? {
|
||||
max := 50
|
||||
mut a := []byte{len: max}
|
||||
mut a := []u8{len: max}
|
||||
mut differences := 0
|
||||
mut rng := rand.get_current_rng()
|
||||
for j in 1 .. max {
|
||||
|
@@ -180,7 +180,7 @@ fn test_rand_f64_in_range() {
|
||||
}
|
||||
|
||||
fn test_rand_u8() {
|
||||
mut all := []byte{}
|
||||
mut all := []u8{}
|
||||
for _ in 0 .. 256 {
|
||||
x := rand.u8()
|
||||
assert x >= 0
|
||||
|
Reference in New Issue
Block a user