2022-08-23 11:21:48 +08:00
|
|
|
var a=wbuffer_create()
|
2021-01-05 17:55:24 +08:00
|
|
|
wbuffer_write_uint8(a, 0x10)
|
|
|
|
assert(wbuffer_get_cursor(a)==1)
|
|
|
|
wbuffer_write_uint16(a, 0x1122)
|
|
|
|
assert(wbuffer_get_cursor(a)==3)
|
|
|
|
wbuffer_write_uint32(a, 0x11223344)
|
|
|
|
assert(wbuffer_get_cursor(a)==7)
|
|
|
|
wbuffer_write_uint64(a, 0x1122334455667788)
|
|
|
|
assert(wbuffer_get_cursor(a)==15)
|
|
|
|
|
|
|
|
wbuffer_write_string(a, "hello");
|
|
|
|
assert(wbuffer_get_cursor(a)==21)
|
|
|
|
|
|
|
|
wbuffer_write_binary(a, "wolrd", 6);
|
|
|
|
assert(wbuffer_get_cursor(a)==27)
|
|
|
|
|
2022-08-23 11:21:48 +08:00
|
|
|
var b=rbuffer_create(wbuffer_get_data(a), wbuffer_get_cursor(a));
|
2021-01-05 17:55:24 +08:00
|
|
|
|
|
|
|
assert(rbuffer_get_cursor(b)==0)
|
|
|
|
assert(rbuffer_read_uint8(b)==0x10)
|
|
|
|
|
|
|
|
assert(rbuffer_get_cursor(b)==1)
|
|
|
|
assert(rbuffer_read_uint16(b)==0x1122)
|
|
|
|
|
|
|
|
assert(rbuffer_get_cursor(b)==3)
|
|
|
|
assert(rbuffer_read_uint32(b)==0x11223344)
|
|
|
|
|
|
|
|
assert(rbuffer_get_cursor(b)==7)
|
|
|
|
assert(rbuffer_read_uint64(b)==0x1122334455667788)
|
|
|
|
|
|
|
|
assert(rbuffer_get_cursor(b)==15)
|
|
|
|
assert(rbuffer_read_string(b)=="hello")
|
|
|
|
assert(rbuffer_get_cursor(b)==21)
|
2022-08-23 11:21:48 +08:00
|
|
|
var c = rbuffer_read_binary(b, 6)
|
2021-01-05 17:55:24 +08:00
|
|
|
assert(rbuffer_get_cursor(b)==27)
|
|
|
|
|
|
|
|
wbuffer_rewind(a);
|
|
|
|
assert(wbuffer_get_cursor(a)==0)
|
|
|
|
wbuffer_write_binary(a, c);
|
|
|
|
assert(wbuffer_get_cursor(a)==6)
|
|
|
|
|