-
-
Notifications
You must be signed in to change notification settings - Fork 168
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Add read/write to stream with big endian ints.
- Move accidently hidden "wrap_bytes".
- Loading branch information
Showing
4 changed files
with
290 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
module std::io @test; | ||
|
||
fn void read_ushort_test() | ||
{ | ||
ByteReader reader = io::wrap_bytes({0x34, 0x8a}); | ||
assert(io::read_be_ushort(&reader)!! == 0x348a); | ||
} | ||
|
||
fn void read_uint_test() | ||
{ | ||
ByteReader reader = io::wrap_bytes({0x34, 0x8a, 0xef, 0xcc}); | ||
assert(io::read_be_uint(&reader)!! == 0x348aefcc); | ||
} | ||
|
||
fn void read_ulong_test() | ||
{ | ||
ByteReader reader = io::wrap_bytes({0x34, 0x8a, 0xef, 0xcc, 0x34, 0x8a, 0xef, 0xcc}); | ||
assert(io::read_be_ulong(&reader)!! == 0x348aefcc348aefcc); | ||
} | ||
|
||
fn void read_uint128_test() | ||
{ | ||
ByteReader reader = io::wrap_bytes({0x34, 0x8a, 0xef, 0xcc, 0x34, 0x8a, 0xef, 0xcc, 0x34, 0x8a, 0xef, 0xcc, 0x34, 0x8a, 0xef, 0xcc}); | ||
assert(io::read_be_uint128(&reader)!! == 0x348aefcc348aefcc348aefcc348aefcc); | ||
} | ||
|
||
fn void write_ushort_test() | ||
{ | ||
ByteWriter bw; | ||
bw.temp_init(); | ||
io::write_be_short(&bw, 0x348a)!!; | ||
assert(bw.str_view() == &&x'348a'); | ||
} | ||
|
||
fn void write_uint_test() | ||
{ | ||
ByteWriter bw; | ||
bw.temp_init(); | ||
io::write_be_int(&bw, 0x3421348a)!!; | ||
assert(bw.str_view() == &&x'3421348a'); | ||
} | ||
|
||
fn void write_ulong_test() | ||
{ | ||
ByteWriter bw; | ||
bw.temp_init(); | ||
io::write_be_long(&bw, 0xaabbccdd3421348a)!!; | ||
assert(bw.str_view() == &&x'aabbccdd3421348a'); | ||
} | ||
|
||
fn void write_uint128_test() | ||
{ | ||
ByteWriter bw; | ||
bw.temp_init(); | ||
io::write_be_int128(&bw, 0xaabbccdd3421348aaabbccdd3421348a)!!; | ||
assert(bw.str_view() == &&x'aabbccdd3421348aaabbccdd3421348a'); | ||
} | ||
|
||
fn void write_tiny_bytearray_test() | ||
{ | ||
ByteWriter bw; | ||
bw.temp_init(); | ||
io::write_tiny_bytearray(&bw, &&x"aabbcc00112233")!!; | ||
assert(bw.str_view() == &&x'07aabbcc00112233'); | ||
} | ||
|
||
fn void write_short_bytearray_test() | ||
{ | ||
ByteWriter bw; | ||
bw.temp_init(); | ||
io::write_short_bytearray(&bw, &&x"aabbcc00112233")!!; | ||
assert(bw.str_view() == &&x'0007aabbcc00112233'); | ||
} | ||
|
||
fn void read_tiny_bytearray_test() | ||
{ | ||
ByteReader reader = io::wrap_bytes(&&x'07aabbcc00112233'); | ||
char[] read = io::read_tiny_bytearray(&reader, allocator: allocator::heap())!; | ||
assert(read == &&x'aabbcc00112233'); | ||
} | ||
|
||
fn void read_short_bytearray_test() | ||
{ | ||
ByteReader reader = io::wrap_bytes(&&x'0007aabbcc00112233'); | ||
char[] read = io::read_short_bytearray(&reader, allocator: allocator::heap())!; | ||
assert(read == &&x'aabbcc00112233'); | ||
} |