Documentation
¶
Index ¶
- Constants
- func IsLittleEndian() bool
- func ReadAny(reader *bufio.Reader) any
- func ReadByte(reader *bufio.Reader) byte
- func ReadBytes(reader *bufio.Reader, buffer []byte) error
- func ReadUint16(reader *bufio.Reader) uint16
- func ReadUint32(reader *bufio.Reader) uint32
- func ReadVarInt(reader *bufio.Reader) (uint, uint, error)
- func ReadVarString(reader *bufio.Reader) string
- func ReadVarUint(reader *bufio.Reader) uint
- func ReadVarUint8Array(reader *bufio.Reader) []byte
- func ReadVarUint8ArrayAsReader(reader *bufio.Reader) *bufio.Reader
- func ReadVarUint8ArrayAsStream(reader *bufio.Reader) *bufio.Reader
- func Reverse(bytes []byte) []byte
- func WriteAny(writer *bufio.Writer, o any)
- func WriteUint16(writer *bufio.Writer, num uint)
- func WriteUint32(writer *bufio.Writer, num uint)
- func WriteVarInt(writer *bufio.Writer, num int, treatZeroAsNegative bool)
- func WriteVarInt2(writer *bufio.Writer, num int)
- func WriteVarString(writer *bufio.Writer, str string)
- func WriteVarUint(writer *bufio.Writer, num uint)
- func WriteVarUint8Array(writer *bufio.Writer, array []byte)
- type VarReader
Constants ¶
const ( Bit1 uint = 1 << 0 Bit2 uint = 1 << 1 Bit3 uint = 1 << 2 Bit4 uint = 1 << 3 Bit5 uint = 1 << 4 Bit6 uint = 1 << 5 Bit7 uint = 1 << 6 Bit8 uint = 1 << 7 Bit9 uint = 1 << 8 Bit10 uint = 1 << 9 Bit11 uint = 1 << 10 Bit12 uint = 1 << 11 Bit13 uint = 1 << 12 Bit14 uint = 1 << 13 Bit15 uint = 1 << 14 Bit16 uint = 1 << 15 Bit17 uint = 1 << 16 Bit18 uint = 1 << 17 Bit19 uint = 1 << 18 Bit20 uint = 1 << 19 Bit21 uint = 1 << 20 Bit22 uint = 1 << 21 Bit23 uint = 1 << 22 Bit24 uint = 1 << 23 Bit25 uint = 1 << 24 Bit26 uint = 1 << 25 Bit27 uint = 1 << 26 Bit28 uint = 1 << 27 Bit29 uint = 1 << 28 Bit30 uint = 1 << 29 Bit31 uint = 1 << 30 Bit32 int = 1 << 31 Bits0 uint = (1 << 0) - 1 Bits1 uint = (1 << 1) - 1 Bits2 uint = (1 << 2) - 1 Bits3 uint = (1 << 3) - 1 Bits4 uint = (1 << 4) - 1 Bits5 uint = (1 << 5) - 1 Bits6 uint = (1 << 6) - 1 Bits7 uint = (1 << 7) - 1 Bits8 uint = (1 << 8) - 1 Bits9 uint = (1 << 9) - 1 Bits10 uint = (1 << 10) - 1 Bits11 uint = (1 << 11) - 1 Bits12 uint = (1 << 12) - 1 Bits13 uint = (1 << 13) - 1 Bits14 uint = (1 << 14) - 1 Bits15 uint = (1 << 15) - 1 Bits16 uint = (1 << 16) - 1 Bits17 uint = (1 << 17) - 1 Bits18 uint = (1 << 18) - 1 Bits19 uint = (1 << 19) - 1 Bits20 uint = (1 << 20) - 1 Bits21 uint = (1 << 21) - 1 Bits22 uint = (1 << 22) - 1 Bits23 uint = (1 << 23) - 1 Bits24 uint = (1 << 24) - 1 Bits25 uint = (1 << 25) - 1 Bits26 uint = (1 << 26) - 1 Bits27 uint = (1 << 27) - 1 Bits28 uint = (1 << 28) - 1 Bits29 uint = (1 << 29) - 1 Bits30 uint = (1 << 30) - 1 Bits31 uint = 0x7FFFFFFF Bits32 uint = 0xFFFFFFFF )
Variables ¶
This section is empty.
Functions ¶
func IsLittleEndian ¶
func IsLittleEndian() bool
func ReadByte ¶
ReadByte Reads a byte from the reader and advances the position within the reader by one byte. <exception cref="EndOfreaderException">End of reader reached.</exception>
func ReadBytes ¶
ReadBytes Reads a sequence of bytes from the current reader and advances the position within the reader by the number of bytes read. <exception cref="EndOfreaderException">End of reader reached.</exception>
func ReadUint16 ¶
ReadUint16 Contains <see cref="reader"/> extensions compatible with the <c>lib0</c>: <see href="https://github.com/dmonad/lib0"/>. Reads two bytes as an unsigned integer.
func ReadUint32 ¶
ReadUint32 Reads four bytes as an unsigned integer.
func ReadVarInt ¶
ReadVarInt Reads a 32-bit variable length signed integer. 1/8th of storage is used as encoding overhead. * Values < 2^7 are stored in one byte. * Values < 2^14 are stored in two bytes. <exception cref="InvalidDataException">Invalid binary format.</exception>
func ReadVarString ¶
ReadVarString Reads a variable length string.
func ReadVarUint ¶
ReadVarUint Reads unsigned integer (32-bit) with variable length. 1/8th of the storage is used as encoding overhead. * Values < 2^7 are stored in one byte. * Values < 2^14 are stored in two bytes. <exception cref="InvalidDataException">Invalid binary format.</exception>
func ReadVarUint8Array ¶
ReadVarUint8Array Reads a variable length byte array.
func ReadVarUint8ArrayAsReader ¶
ReadVarUint8ArrayAsReader Reads variable length byte array as a readable <see cref="Memoryreader"/>.
func WriteAny ¶
WriteAny Encodes data with efficient binary format. <br/> Differences to JSON:
- Transforms data to a binary format (not to a string).
- Encodes undefined, NaN, and ArrayBuffer (these can't be represented in JSON).
- Numbers are efficiently encoded either as a variable length integer, as a 32-bit float, or as a 64-bit float.
<br/> Encoding table: | Data Type | Prefix | Encoding method | Comment | | ------------------------------ | ------ | ----------------- | -------------------------------------------------------------- | | undefined | 127 | | Functions, symbol, and everything that cannot be identified | | | | | is encdoded as undefined. | | null | 126 | | | | integer | 125 | WriteVarInt | Only encodes 32-bit signed integers. | | float | 124 | SingleToInt32Bits | | | double | 123 | DoubleToInt64Bits | | | boolean (false) | 121 | | True and false are different data types so we save the | | boolean (true) | | 120 | | following byte (0b_01111000) so the last bit determines value. | | string | 119 | WriteVarString | | | IDictionary<string, any> | 118 | custom | Writes length, then key-value pairs. | | ICollection<any> | 117 | custom | Writes length, then values. | | byte[] | 116 | | We use byte[] for any kind of binary data. | <br/> Reasons for the decreasing prefix: We need the first bit for extendability (later we may want to encode the prefix with <see cref="WriteVarUint(BinaryWriter, uint)"/>). The remaining 7 bits are divided as follows: [0-30] The beginning of the data range is used for custom purposes
(defined by the function that uses this library). [31-127] The end of the data range is used for data encoding.
func WriteUint16 ¶
WriteUint16 Writes two bytes as an unsigned unteger.
func WriteUint32 ¶
WriteUint32 Writes four bytes as an unsigned integer.
func WriteVarInt ¶
WriteVarInt Writes a variable length integer. <br/> Encodes integers in the range <c>[-2147483648, -2147483647]</c>. <br/> We don't use zig-zag encoding because we want to keep the option open to use the same function for <c>BigInt</c> and 53-bit integers (doubles). <br/>
We use the 7-th bit instead for signalling that this is a negative number.
func WriteVarInt2 ¶
func WriteVarString ¶
WriteVarString Writes a variable length string.
func WriteVarUint ¶
WriteVarUint Writes a variable length unsigned integer. Encodes integers in the range <c>[0, 4294967295] / [0, 0xFFFFFFFF]</c>.
func WriteVarUint8Array ¶
WriteVarUint8Array Appends a byte array to the writer.