std/binary
Binary formats read and written: ByteReader and ByteWriter for numbers of every width in either byte order,
IEEE 754 floats, LEB128 integers, runs of bytes and text; BitReader and BitWriter for numbers packed into bits in
either BitOrder. What std/dns, std/compression and std/archive read their formats with
(docs/design/BINARY.md).
A read never panics. Every read answers a Result whose failure is a ReadError that names the byte and what was
expected there, so bytes from a file or the network are read without a check in front of every read; a format turns
it into its own error through From, and ? does the rest. A write never fails: the signatures take width
types, so a value that does not fit a field is refused where the caller narrows it, with tryInto().
Ordinary TorbScript over List<UInt8>, with no native.
Modules
std/binary/bits[BitReader] and [BitWriter]: numbers of any width up to 56 bits, packed into bytes in a [BitOrder].std/binary/error[ReadError]: why a read of aByteReaderor aBitReaderdid not answer a value.std/binary/reader[ByteReader]: typed reads from a cursor over bytes, each of which answers a [ReadError] where the bytes end.std/binary/writer[ByteWriter]: typed writes into a growable buffer, and [Mark] for a length that is written after what it counts.
Everything
- type
BitOrderWhich bit of a byte comes first, and so which bit of a number read from several of them is its lowest. - type
BitReaderThe bits of bytes, read as numbers of 0 to 56 bits in a [BitOrder] - most significant first unless it was made with another. - type
BitWriterNumbers of 0 to 56 bits packed into bytes in a [BitOrder], most significant first unless it was made with another. - type
ByteReaderA cursor over bytes that reads numbers, runs of bytes and text from them, and answers a [ReadError] instead of reading past the end: bytes from a file or the network cannot make it panic. - type
ByteWriterA growable buffer that numbers, bytes and text are written into, in the writer's byte order - big endian unless it was made with another - or in the one a write names. - type
MarkWhere a [ByteWriter] left room for a number ofWidth- aUInt16or aUInt32- that is written later with [ByteWriter.patch]: a length that is known only after what it counts. - type
ReadErrorWhy a read failed, and the byte where it happened. - type
SignedEncodingHow a variable-length integer with a sign is written.