ByteWriter provides a byte writer and reader that can write/read different integer and floating point types
to/from a memory buffer.
It provides functions for writing/reading signed/unsigned, little/big endian integers of 8, 16, 24, 32 and 64 bits and functions for
reading little/big endian floating points numbers of 32 and 64 bits. It also provides functions to write/read NUL-terminated strings in
various character encodings.
- public bool ensure_free_space (uint size)
Checks if enough free space from the current write cursor is available
and reallocates if necessary.
- public bool fill (uint8 value, uint size)
Writes size
bytes containing value
to
this.
- public void free ()
Frees this and all memory allocated
by it.
- public Buffer free_and_get_buffer ()
Frees this and all memory allocated
by it except the current data, which is returned as Buffer.
- public uint8 free_and_get_data ()
Frees this and all memory allocated
by it except the current data, which is returned.
- public uint get_remaining ()
Returns the remaining size of data that can still be written.
- public void init ()
Initializes this to an empty
instance
- public void init_with_data (uint8[] data, bool initialized)
Initializes this with the given
memory area.
- public void init_with_size (uint size, bool fixed)
Initializes this with the given
initial data size.
- public bool put_buffer (Buffer buffer, size_t offset, ssize_t size)
Writes size
bytes of data
to
this.
- public bool put_data (uint8[] data)
Writes data.length
bytes of data
to
this.
- public bool put_float32_be (float val)
Writes a big endian 32 bit float to this
.
- public bool put_float32_le (float val)
Writes a little endian 32 bit float to this
.
- public bool put_float64_be (double val)
Writes a big endian 64 bit float to this
.
- public bool put_float64_le (double val)
Writes a little endian 64 bit float to this
.
- public bool put_int16_be (int16 val)
Writes a signed big endian 16 bit integer to
this.
- public bool put_int16_le (int16 val)
Writes a signed little endian 16 bit integer to
this.
- public bool put_int24_be (int32 val)
Writes a signed big endian 24 bit integer to
this.
- public bool put_int24_le (int32 val)
Writes a signed little endian 24 bit integer to
this.
- public bool put_int32_be (int32 val)
Writes a signed big endian 32 bit integer to
this.
- public bool put_int32_le (int32 val)
Writes a signed little endian 32 bit integer to
this.
- public bool put_int64_be (int64 val)
Writes a signed big endian 64 bit integer to
this.
- public bool put_int64_le (int64 val)
Writes a signed little endian 64 bit integer to
this.
- public bool put_int8 (int8 val)
Writes a signed 8 bit integer to this
.
- public bool put_string_utf16 (uint16[] data)
Writes a NUL-terminated UTF16 string to
this (including the terminator).
- public bool put_string_utf32 (uint32[] data)
Writes a NUL-terminated UTF32 string to
this (including the terminator).
- public bool put_string_utf8 (string data)
Writes a NUL-terminated UTF8 string to this
(including the terminator).
- public bool put_uint16_be (uint16 val)
Writes a unsigned big endian 16 bit integer to
this.
- public bool put_uint16_le (uint16 val)
Writes a unsigned little endian 16 bit integer to
this.
- public bool put_uint24_be (uint32 val)
Writes a unsigned big endian 24 bit integer to
this.
- public bool put_uint24_le (uint32 val)
Writes a unsigned little endian 24 bit integer to
this.
- public bool put_uint32_be (uint32 val)
Writes a unsigned big endian 32 bit integer to
this.
- public bool put_uint32_le (uint32 val)
Writes a unsigned little endian 32 bit integer to
this.
- public bool put_uint64_be (uint64 val)
Writes a unsigned big endian 64 bit integer to
this.
- public bool put_uint64_le (uint64 val)
Writes a unsigned little endian 64 bit integer to
this.
- public bool put_uint8 (uint8 val)
Writes a unsigned 8 bit integer to this
.
- public void reset ()
Resets this and frees the data if
it's owned by this.
- public Buffer reset_and_get_buffer ()
Resets this and returns the current
data as buffer.
- public uint8[] reset_and_get_data ()
Resets this and returns the current
data.