4#include <aegis2d/net/export.hpp>
24 static constexpr std::size_t max_string_size = 0xFFFF;
69 [[nodiscard]] std::span<const std::byte>
data() const noexcept;
72 [[nodiscard]]
std::
size_t size() const noexcept;
74 void clear() noexcept;
77 std::vector<
std::
byte> buffer_;
96 [[nodiscard]] std::optional<std::uint8_t>
read_u8() noexcept;
99 [[nodiscard]]
std::optional<
std::uint16_t> read_u16() noexcept;
102 [[nodiscard]]
std::optional<
std::uint32_t> read_u32() noexcept;
105 [[nodiscard]]
std::optional<
std::uint64_t> read_u64() noexcept;
108 [[nodiscard]]
std::optional<
std::int8_t> read_i8() noexcept;
111 [[nodiscard]]
std::optional<
std::int16_t> read_i16() noexcept;
114 [[nodiscard]]
std::optional<
std::int32_t> read_i32() noexcept;
117 [[nodiscard]]
std::optional<
std::int64_t> read_i64() noexcept;
122 [[nodiscard]]
std::optional<
float> read_f32() noexcept;
126 [[nodiscard]]
std::optional<
double> read_f64() noexcept;
130 [[nodiscard]]
std::optional<
bool> read_bool() noexcept;
135 [[nodiscard]]
std::optional<
std::span<const
std::
byte>> read_bytes(
std::
size_t count) noexcept;
141 [[nodiscard]]
std::optional<
std::
string> read_string();
145 [[nodiscard]]
bool failed() const noexcept;
149 [[nodiscard]]
bool at_end() const noexcept;
152 [[nodiscard]]
std::
size_t position() const noexcept;
155 [[nodiscard]]
std::
size_t remaining() const noexcept;
158 [[nodiscard]]
std::optional<
std::span<const
std::
byte>> take(
std::
size_t count) noexcept;
160 std::span<const
std::
byte> bytes_;
161 std::
size_t position_ = 0;
162 bool failed_ = false;
Reads values written by BinaryWriter from untrusted bytes, never past their end.
Definition binary.hpp:88
BinaryReader(std::span< const std::byte > bytes) noexcept
Starts reading at the beginning of bytes.
std::optional< std::uint8_t > read_u8() noexcept
Reads an unsigned 8-bit integer.
Writes values field by field into a growing byte buffer.
Definition binary.hpp:21
void write_u64(std::uint64_t value)
Appends an unsigned 64-bit integer (8 bytes).
void write_i64(std::int64_t value)
Appends a signed 64-bit integer (8 bytes, two's complement).
std::span< const std::byte > data() const noexcept
Bytes written so far.
void write_string(std::string_view text)
Appends a string as its byte length on 16 bits, then its bytes (UTF-8).
void write_i32(std::int32_t value)
Appends a signed 32-bit integer (4 bytes, two's complement).
void write_u8(std::uint8_t value)
Appends an unsigned 8-bit integer (1 byte).
void write_bytes(std::span< const std::byte > bytes)
Appends raw bytes, without length: the reader must know how many to read.
void write_bool(bool value)
Appends a boolean as one byte, 0 or 1.
void write_f64(double value)
Appends a 64-bit float (8 bytes, IEEE 754 bits).
void write_i8(std::int8_t value)
Appends a signed 8-bit integer (1 byte, two's complement).
void write_i16(std::int16_t value)
Appends a signed 16-bit integer (2 bytes, two's complement).
void write_u16(std::uint16_t value)
Appends an unsigned 16-bit integer (2 bytes).
void write_f32(float value)
Appends a 32-bit float (4 bytes, IEEE 754 bits).
void write_u32(std::uint32_t value)
Appends an unsigned 32-bit integer (4 bytes).
Binary serialization, UDP/TCP sockets and the network thread.
Definition binary.hpp:14
Definition endpoint.hpp:85