buf
Growable byte buffer for binary protocols and low-level I/O.
Import
import bufFunctions
buf.new(cap?: int) -> Buffer
Create a new buffer with optional initial capacity.
Write functions
buf.write_u8(b, v) - append one byte.buf.write_u16(b, v) - append 2-byte little-endian integer.buf.write_u32(b, v) - append 4-byte little-endian integer.buf.write_u64(b, v) - append 8-byte little-endian integer.buf.write_str(b, s) - append the raw bytes of a string.
Read functions
buf.read_u8(b), buf.read_u16(b), buf.read_u32(b), buf.read_u64(b) - read at the current cursor position, advancing the cursor.
buf.to_str(b: Buffer) -> str
Convert the buffer contents to a string.
buf.to_hex(b: Buffer) -> str
Return a hex dump of the buffer bytes.
buf.len(b: Buffer) -> int
Number of bytes written so far.
Examples
scratch.xs