libultraship
Reimplementations of libultra (N64 SDK) functions for modern hardware
Loading...
Searching...
No Matches
BinaryWriter.h
Go to the documentation of this file.
1#pragma once
2
3#include <array>
4#include <memory>
5#include <string>
6#include <vector>
7#include "endianness.h"
8#include "Stream.h"
9
10namespace Ship {
31 public:
34
40
45 BinaryWriter(std::shared_ptr<Stream> nStream);
46
51 void SetEndianness(Endianness endianness);
52
56 std::shared_ptr<Stream> GetStream();
57
61 uint64_t GetBaseAddress();
62
66 uint64_t GetLength();
67
73 void Seek(int32_t offset, SeekOffsetType seekType);
74
78 void Close();
79
81 void Write(int8_t value);
82
84 void Write(uint8_t value);
85
87 void Write(int16_t value);
88
90 void Write(uint16_t value);
91
93 void Write(int32_t value);
94
100 void Write(int32_t valueA, int32_t valueB);
101
103 void Write(uint32_t value);
104
106 void Write(int64_t value);
107
109 void Write(uint64_t value);
110
112 void Write(float value);
113
115 void Write(double value);
116
125 void Write(const std::string& str);
126
132 void Write(char* srcBuffer, size_t length);
133
137 std::vector<char> ToVector();
138
139 protected:
140 std::shared_ptr<Stream> mStream;
142};
143} // namespace Ship
@ Native
Platform is little-endian; Native resolves to Little.
Sequential binary writer with configurable byte-order support.
Definition BinaryWriter.h:30
void Write(uint64_t value)
Writes an unsigned 64-bit integer, applying the configured byte order.
uint64_t GetLength()
Returns the total number of bytes written to the stream.
void Write(const std::string &str)
Writes a length-prefixed UTF-8 string.
void Seek(int32_t offset, SeekOffsetType seekType)
Moves the stream write position.
void Write(float value)
Writes a 32-bit IEEE 754 float, applying the configured byte order.
void Close()
Closes the underlying stream and flushes any buffered data.
std::shared_ptr< Stream > GetStream()
Returns the underlying stream (e.g. to pass to a BinaryReader after writing).
void Write(int8_t value)
Writes a signed 8-bit integer.
BinaryWriter(std::shared_ptr< Stream > nStream)
Constructs a BinaryWriter over a shared Stream.
std::vector< char > ToVector()
Returns the entire stream contents as a vector of chars.
void SetEndianness(Endianness endianness)
Sets the byte order used for all subsequent multi-byte writes.
void Write(uint16_t value)
Writes an unsigned 16-bit integer, applying the configured byte order.
void Write(uint8_t value)
Writes an unsigned 8-bit integer.
std::shared_ptr< Stream > mStream
Underlying byte stream.
Definition BinaryWriter.h:140
void Write(int32_t valueA, int32_t valueB)
Writes two signed 32-bit integers sequentially, applying the configured byte order.
void Write(char *srcBuffer, size_t length)
Writes length raw bytes from srcBuffer.
Endianness mEndianness
Active byte order for multi-byte writes.
Definition BinaryWriter.h:141
void Write(int16_t value)
Writes a signed 16-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(double value)
Writes a 64-bit IEEE 754 double, applying the configured byte order.
BinaryWriter()
Constructs a BinaryWriter backed by a new, empty, growable MemoryStream.
void Write(int32_t value)
Writes a signed 32-bit integer, applying the configured byte order.
void Write(uint32_t value)
Writes an unsigned 32-bit integer, applying the configured byte order.
BinaryWriter(Stream *nStream)
Constructs a BinaryWriter over a raw (non-owning) Stream pointer.
uint64_t GetBaseAddress()
Returns the current absolute write position.
Abstract base class for sequential byte streams (read/write).
Definition Stream.h:26
Core namespace for the libultraship engine framework.
Definition gfx_direct3d_common.h:14
SeekOffsetType
Identifies the reference point for a seek operation.
Definition Stream.h:10