mirror of
https://github.com/c3lang/c3c.git
synced 2026-02-27 12:01:16 +00:00
Add bitorder functions store_le, load_le, store_be, store_le.
This commit is contained in:
@@ -33,6 +33,15 @@ fn void test_read()
|
||||
assert(bitorder::read(bytes[..], ULongLE) == 0x0807060504030201);
|
||||
}
|
||||
|
||||
fn void test_load()
|
||||
{
|
||||
char[*] bytes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
assert(bitorder::load_be((short*)&bytes) == 0x0102);
|
||||
assert(bitorder::load_le((short*)&bytes) == 0x0201);
|
||||
assert(bitorder::load_be((long*)&bytes) == 0x0102030405060708);
|
||||
assert(bitorder::load_le((long*)&bytes) == 0x0807060504030201);
|
||||
}
|
||||
|
||||
fn void test_write()
|
||||
{
|
||||
char[*] bytes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
@@ -49,4 +58,41 @@ fn void test_write()
|
||||
ulong x3 = bitorder::read(bytes, ULongBE);
|
||||
bitorder::write(x3, buf[..], ULongBE);
|
||||
assert(bitorder::read(buf, ULongBE) == x3);
|
||||
}
|
||||
|
||||
fn void test_store()
|
||||
{
|
||||
char[*] bytes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
char[8] buf;
|
||||
|
||||
ushort x1 = bitorder::load_be((ushort*)&bytes);
|
||||
bitorder::store_be(&buf, x1);
|
||||
assert(bitorder::read(buf, UShortBE) == x1);
|
||||
|
||||
uint x2 = bitorder::load_be((uint*)&bytes);
|
||||
bitorder::store_be(&buf, x2);
|
||||
assert(bitorder::read(buf, UIntBE) == x2);
|
||||
|
||||
ulong x3 = bitorder::load_be((ulong*)&bytes);
|
||||
bitorder::store_be(&buf, x3);
|
||||
assert(bitorder::read(buf, ULongBE) == x3);
|
||||
}
|
||||
|
||||
fn void test_store_le()
|
||||
{
|
||||
char[*] bytes = { 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08 };
|
||||
char[8] buf;
|
||||
|
||||
ushort x1 = bitorder::load_le((ushort*)&bytes);
|
||||
bitorder::store_le(&buf, x1);
|
||||
assert(bitorder::read(buf, UShortLE) == x1);
|
||||
|
||||
uint x2 = bitorder::load_le((uint*)&bytes);
|
||||
bitorder::store_le(&buf, x2);
|
||||
assert(bitorder::read(buf, UIntLE) == x2);
|
||||
|
||||
ulong x3 = bitorder::load_le((ulong*)&bytes);
|
||||
bitorder::store_le(&buf, x3);
|
||||
assert(bitorder::read(buf, ULongLE) == x3);
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user