|
libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
|
Sequential binary writer with configurable byte-order support. More...
#include <BinaryWriter.h>
Public Member Functions | |
| BinaryWriter () | |
| Constructs a BinaryWriter backed by a new, empty, growable MemoryStream. | |
| BinaryWriter (Stream *nStream) | |
| Constructs a BinaryWriter over a raw (non-owning) Stream pointer. | |
| BinaryWriter (std::shared_ptr< Stream > nStream) | |
| Constructs a BinaryWriter over a shared Stream. | |
| void | SetEndianness (Endianness endianness) |
| Sets the byte order used for all subsequent multi-byte writes. | |
| std::shared_ptr< Stream > | GetStream () |
| Returns the underlying stream (e.g. to pass to a BinaryReader after writing). | |
| uint64_t | GetBaseAddress () |
| Returns the current absolute write position. | |
| uint64_t | GetLength () |
| Returns the total number of bytes written to the stream. | |
| void | Seek (int32_t offset, SeekOffsetType seekType) |
| Moves the stream write position. | |
| void | Close () |
| Closes the underlying stream and flushes any buffered data. | |
| void | Write (int8_t value) |
| Writes a signed 8-bit integer. | |
| void | Write (uint8_t value) |
| Writes an unsigned 8-bit integer. | |
| void | Write (int16_t value) |
| Writes a signed 16-bit integer, applying the configured byte order. | |
| void | Write (uint16_t value) |
| Writes an unsigned 16-bit integer, applying the configured byte order. | |
| void | Write (int32_t value) |
| Writes a signed 32-bit integer, applying the configured byte order. | |
| void | Write (int32_t valueA, int32_t valueB) |
| Writes two signed 32-bit integers sequentially, applying the configured byte order. | |
| void | Write (uint32_t value) |
| Writes an unsigned 32-bit integer, applying the configured byte order. | |
| void | Write (int64_t value) |
| Writes a signed 64-bit integer, applying the configured byte order. | |
| void | Write (uint64_t value) |
| Writes an unsigned 64-bit integer, applying the configured byte order. | |
| void | Write (float value) |
| Writes a 32-bit IEEE 754 float, applying the configured byte order. | |
| void | Write (double value) |
| Writes a 64-bit IEEE 754 double, applying the configured byte order. | |
| void | Write (const std::string &str) |
| Writes a length-prefixed UTF-8 string. | |
| void | Write (char *srcBuffer, size_t length) |
Writes length raw bytes from srcBuffer. | |
| std::vector< char > | ToVector () |
| Returns the entire stream contents as a vector of chars. | |
Protected Attributes | |
| std::shared_ptr< Stream > | mStream |
| Underlying byte stream. | |
| Endianness | mEndianness = Endianness::Native |
| Active byte order for multi-byte writes. | |
Sequential binary writer with configurable byte-order support.
BinaryWriter wraps a Stream and provides typed write methods for all primitive integer and floating-point types as well as strings. The byte order used for multi-byte writes is configurable at runtime via SetEndianness().
The default constructor creates an internal MemoryStream that grows automatically; use GetStream() to retrieve the result or ToVector() for a raw copy.
Typical usage:
| Ship::BinaryWriter::BinaryWriter | ( | ) |
Constructs a BinaryWriter backed by a new, empty, growable MemoryStream.
| Ship::BinaryWriter::BinaryWriter | ( | Stream * | nStream | ) |
Constructs a BinaryWriter over a raw (non-owning) Stream pointer.
| nStream | Pointer to an already-constructed stream (ownership not transferred). |
| Ship::BinaryWriter::BinaryWriter | ( | std::shared_ptr< Stream > | nStream | ) |
Constructs a BinaryWriter over a shared Stream.
| nStream | Shared stream to write into. |
| void Ship::BinaryWriter::Close | ( | ) |
Closes the underlying stream and flushes any buffered data.
| uint64_t Ship::BinaryWriter::GetBaseAddress | ( | ) |
Returns the current absolute write position.
| uint64_t Ship::BinaryWriter::GetLength | ( | ) |
Returns the total number of bytes written to the stream.
| std::shared_ptr< Stream > Ship::BinaryWriter::GetStream | ( | ) |
Returns the underlying stream (e.g. to pass to a BinaryReader after writing).
| void Ship::BinaryWriter::Seek | ( | int32_t | offset, |
| SeekOffsetType | seekType | ||
| ) |
Moves the stream write position.
| offset | Byte offset. |
| seekType | Reference point (Start, Current, or End). |
| void Ship::BinaryWriter::SetEndianness | ( | Endianness | endianness | ) |
Sets the byte order used for all subsequent multi-byte writes.
| endianness | Endianness::Little, Big, or Native. |
| std::vector< char > Ship::BinaryWriter::ToVector | ( | ) |
Returns the entire stream contents as a vector of chars.
| void Ship::BinaryWriter::Write | ( | char * | srcBuffer, |
| size_t | length | ||
| ) |
Writes length raw bytes from srcBuffer.
| srcBuffer | Source buffer. |
| length | Number of bytes to write. |
| void Ship::BinaryWriter::Write | ( | const std::string & | str | ) |
Writes a length-prefixed UTF-8 string.
Writes a 32-bit unsigned length (in the configured byte order) followed by the string's bytes. No null terminator is written.
| str | String to write. |
| void Ship::BinaryWriter::Write | ( | double | value | ) |
Writes a 64-bit IEEE 754 double, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | float | value | ) |
Writes a 32-bit IEEE 754 float, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | int16_t | value | ) |
Writes a signed 16-bit integer, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | int32_t | value | ) |
Writes a signed 32-bit integer, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | int32_t | valueA, |
| int32_t | valueB | ||
| ) |
Writes two signed 32-bit integers sequentially, applying the configured byte order.
| valueA | First integer. |
| valueB | Second integer. |
| void Ship::BinaryWriter::Write | ( | int64_t | value | ) |
Writes a signed 64-bit integer, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | int8_t | value | ) |
Writes a signed 8-bit integer.
| void Ship::BinaryWriter::Write | ( | uint16_t | value | ) |
Writes an unsigned 16-bit integer, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | uint32_t | value | ) |
Writes an unsigned 32-bit integer, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | uint64_t | value | ) |
Writes an unsigned 64-bit integer, applying the configured byte order.
| void Ship::BinaryWriter::Write | ( | uint8_t | value | ) |
Writes an unsigned 8-bit integer.
|
protected |
Active byte order for multi-byte writes.
|
protected |
Underlying byte stream.