|
NSUNI/NSLAR Library a250670
|
Provides classes for reading and writing binary data to and from various sources. More...
Classes | |
| class | nnl::RWBase |
| Base interface for data reading/writing classes. More... | |
| class | nnl::Reader |
| Abstract class for reading data. More... | |
| class | nnl::Writer |
| Abstract class for writing data. More... | |
| class | nnl::FileReader |
| Reader implementation for reading from a file. More... | |
| class | nnl::FileRW |
| Reader/Writer implementation for file io operations. More... | |
| class | nnl::BufferView |
| Reader implementation for read-only memory buffers. More... | |
| class | nnl::BufferSpan |
| Reader/Writer implementation for mutable memory buffers. More... | |
| class | nnl::BufferRW |
| Reader/Writer implementation that writes to an internal growable buffer. More... | |
Typedefs | |
| using | nnl::Buffer = std::vector<u8> |
| A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted in multiple ways. | |
Provides classes for reading and writing binary data to and from various sources.
| class nnl::RWBase |
Base interface for data reading/writing classes.
Provides basic functionality for data "streams".
Inherited by nnl::Reader [virtual], and nnl::Writer [virtual].
Public Member Functions | |
| virtual void | Seek (std::size_t offset)=0 |
| Seeks to a specific offset in the data. | |
| virtual std::size_t | Tell ()=0 |
| Gets the current position in the data. | |
| virtual std::size_t | Len ()=0 |
| Gets the available length of the data. | |
|
pure virtual |
Gets the available length of the data.
Implemented in nnl::BufferRW, nnl::BufferSpan, nnl::BufferView, nnl::FileReader, and nnl::FileRW.
|
pure virtual |
Seeks to a specific offset in the data.
| offset | The offset to seek to. |
Implemented in nnl::BufferRW, nnl::BufferSpan, nnl::BufferView, nnl::FileReader, and nnl::FileRW.
|
pure virtual |
Gets the current position in the data.
Implemented in nnl::BufferRW, nnl::BufferSpan, nnl::BufferView, nnl::FileReader, and nnl::FileRW.
| class nnl::Reader |
Abstract class for reading data.
Inherits from RWBase and provides methods to read trivially copyable data from various sources.
Inherits nnl::RWBase.
Inherited by nnl::BufferRW, nnl::BufferSpan, nnl::BufferView, nnl::FileRW, and nnl::FileReader.
Public Member Functions | |
| void | ReadBuf (void *dst, std::size_t size) |
| Reads a block of data into the specified destination. | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| T | ReadLE () |
| Reads a trivially copyable object. | |
| template<typename T> | |
| std::vector< T > | ReadArrayLE (std::size_t num_elements) |
| Reads multiple trivially copyable objects into a vector. | |
| Public Member Functions inherited from nnl::RWBase | |
| virtual void | Seek (std::size_t offset)=0 |
| Seeks to a specific offset in the data. | |
| virtual std::size_t | Tell ()=0 |
| Gets the current position in the data. | |
| virtual std::size_t | Len ()=0 |
| Gets the available length of the data. | |
Protected Member Functions | |
| virtual void | ReadData (void *dst, std::size_t size)=0 |
| Low-level data reading implementation. | |
|
inline |
Reads multiple trivially copyable objects into a vector.
| T | Type to read (must be trivially copyable) |
| num_elements | Number of elements to read |
|
inline |
Reads a block of data into the specified destination.
| dst | Pointer to the destination buffer. |
| size | Size of the data to read in bytes. |
|
protectedpure virtual |
Low-level data reading implementation.
| dst | Destination buffer |
| size | Number of bytes to read |
Implemented in nnl::BufferRW, nnl::BufferSpan, nnl::BufferView, nnl::FileReader, and nnl::FileRW.
|
inline |
Reads a trivially copyable object.
| T | Type to read (must be trivially copyable) |
| class nnl::Writer |
Abstract class for writing data.
Inherits from RWBase and provides methods to write trivially copyable data to various destinations.
Inherits nnl::RWBase.
Inherited by nnl::BufferRW, nnl::BufferSpan, and nnl::FileRW.
Public Member Functions | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| Offset< T > | MakeOffsetLE () |
| Creates an Offset pointing to the current position. | |
| Offset< u8 > | WriteBuf (const void *src, std::size_t size) |
| Writes raw binary data. | |
| template<typename T, std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0> | |
| Offset< T > | WriteLE (const T &value) |
| Writes a trivially copyable value. | |
| template<typename T> | |
| Offset< T > | WriteArrayLE (const std::vector< T > &container) |
| Writes contents of a vector. | |
| void | AlignData (std::size_t multiple, unsigned char value=0) |
| Aligns the current position to a specified multiple. | |
| Public Member Functions inherited from nnl::RWBase | |
| virtual void | Seek (std::size_t offset)=0 |
| Seeks to a specific offset in the data. | |
| virtual std::size_t | Tell ()=0 |
| Gets the current position in the data. | |
| virtual std::size_t | Len ()=0 |
| Gets the available length of the data. | |
Protected Member Functions | |
| virtual void | WriteData (const void *src, std::size_t size)=0 |
| Low-level data writing implementation. | |
|
inline |
Aligns the current position to a specified multiple.
| multiple | Alignment boundary (e.g., 4 for 4-byte alignment) |
| value | Byte value to use for padding |
|
inline |
|
inline |
Writes contents of a vector.
| container | Container to write |
Writes raw binary data.
| src | Source buffer |
| size | Number of bytes to write |
|
protectedpure virtual |
Low-level data writing implementation.
| src | Source buffer |
| size | Number of bytes to write |
Implemented in nnl::BufferRW, nnl::BufferSpan, and nnl::FileRW.
|
inline |
Writes a trivially copyable value.
| T | Value type (must be trivially copyable) |
| value | Value to write |
| class nnl::FileReader |
Reader implementation for reading from a file.
Inherits nnl::Reader.
Public Member Functions | |
| FileReader (const std::filesystem::path &path) | |
| Constructs a FileReader from the specified file. | |
| void | Seek (std::size_t offset) override |
| Seeks to a specific offset in the data. | |
| std::size_t | Tell () override |
| Gets the current position in the data. | |
| std::size_t | Len () override |
| Gets the available length of the data. | |
| void | ClearState () |
| Clears any error flags on the file stream. | |
| void | Close () |
| Closes the file. | |
| Public Member Functions inherited from nnl::Reader | |
| void | ReadBuf (void *dst, std::size_t size) |
| Reads a block of data into the specified destination. | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| T | ReadLE () |
| Reads a trivially copyable object. | |
| template<typename T> | |
| std::vector< T > | ReadArrayLE (std::size_t num_elements) |
| Reads multiple trivially copyable objects into a vector. | |
Protected Member Functions | |
| void | ReadData (void *dst, std::size_t size) override |
| Low-level data reading implementation. | |
|
inline |
Constructs a FileReader from the specified file.
| path | The filesystem path to the file. |
| nnl::IOError |
|
inline |
Clears any error flags on the file stream.
|
inline |
Closes the file.
|
inlineoverridevirtual |
|
inlineoverrideprotectedvirtual |
Low-level data reading implementation.
| dst | Destination buffer |
| size | Number of bytes to read |
Implements nnl::Reader.
|
inlineoverridevirtual |
Seeks to a specific offset in the data.
| offset | The offset to seek to. |
Implements nnl::RWBase.
|
inlineoverridevirtual |
Gets the current position in the data.
Implements nnl::RWBase.
| class nnl::FileRW |
Reader/Writer implementation for file io operations.
Inherits nnl::Writer, and nnl::Reader.
Public Member Functions | |
| FileRW (const std::filesystem::path &path, bool truncate) | |
| Constructs a FileRW from the specified file. | |
| void | Seek (std::size_t offset) override |
| Seeks to a specific offset in the data. | |
| std::size_t | Tell () override |
| Gets the current position in the data. | |
| std::size_t | Len () override |
| Gets the available length of the data. | |
| void | ClearState () |
| Clears any error flags on the file stream. | |
| void | Close () |
| Closes the file. | |
| Public Member Functions inherited from nnl::Writer | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| Offset< T > | MakeOffsetLE () |
| Creates an Offset pointing to the current position. | |
| Offset< u8 > | WriteBuf (const void *src, std::size_t size) |
| Writes raw binary data. | |
| template<typename T, std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0> | |
| Offset< T > | WriteLE (const T &value) |
| Writes a trivially copyable value. | |
| template<typename T> | |
| Offset< T > | WriteArrayLE (const std::vector< T > &container) |
| Writes contents of a vector. | |
| void | AlignData (std::size_t multiple, unsigned char value=0) |
| Aligns the current position to a specified multiple. | |
| Public Member Functions inherited from nnl::Reader | |
| void | ReadBuf (void *dst, std::size_t size) |
| Reads a block of data into the specified destination. | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| T | ReadLE () |
| Reads a trivially copyable object. | |
| template<typename T> | |
| std::vector< T > | ReadArrayLE (std::size_t num_elements) |
| Reads multiple trivially copyable objects into a vector. | |
Protected Member Functions | |
| void | WriteData (const void *src, std::size_t size) override |
| Low-level data writing implementation. | |
| void | ReadData (void *dst, std::size_t size) override |
| Low-level data reading implementation. | |
|
inline |
Constructs a FileRW from the specified file.
| path | The filesystem path to the file. |
| truncate | If the contents should be discarded |
| nnl::IOError |
|
inline |
Clears any error flags on the file stream.
|
inline |
Closes the file.
|
inlineoverridevirtual |
|
inlineoverrideprotectedvirtual |
Low-level data reading implementation.
| dst | Destination buffer |
| size | Number of bytes to read |
Implements nnl::Reader.
|
inlineoverridevirtual |
Seeks to a specific offset in the data.
| offset | The offset to seek to. |
Implements nnl::RWBase.
|
inlineoverridevirtual |
Gets the current position in the data.
Implements nnl::RWBase.
|
inlineoverrideprotectedvirtual |
Low-level data writing implementation.
| src | Source buffer |
| size | Number of bytes to write |
Implements nnl::Writer.
| class nnl::BufferView |
Reader implementation for read-only memory buffers.
Provides a view into existing memory without taking ownership. Suitable for reading from buffers or memory-mapped files. Offers an interface similar to std::vector.
Inherits nnl::Reader.
Public Member Functions | |
| BufferView (const void *buffer, std::size_t size) noexcept | |
| Constructs a BufferView from a pointer/size pair. | |
| template<typename TContainer, typename = std::enable_if_t<std::is_trivially_copyable_v<typename TContainer::value_type>>> | |
| BufferView (const TContainer &buffer) noexcept | |
| Constructs a BufferView from a generic contiguous container. | |
| void | Seek (std::size_t offset) override |
| Seeks to a specific offset in the data. | |
| std::size_t | Tell () override |
| Gets the current position in the data. | |
| std::size_t | Len () override |
| Gets the available length of the data. | |
| BufferView | SubView (std::size_t offset, std::size_t size) const |
| Creates a view into a subrange of the buffer. | |
| const u8 * | data () const noexcept |
| Gets pointer to the underlying buffer. | |
| Public Member Functions inherited from nnl::Reader | |
| void | ReadBuf (void *dst, std::size_t size) |
| Reads a block of data into the specified destination. | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| T | ReadLE () |
| Reads a trivially copyable object. | |
| template<typename T> | |
| std::vector< T > | ReadArrayLE (std::size_t num_elements) |
| Reads multiple trivially copyable objects into a vector. | |
Protected Member Functions | |
| void | ReadData (void *dst, std::size_t size) override |
| Low-level data reading implementation. | |
|
inlinenoexcept |
Constructs a BufferView from a pointer/size pair.
| buffer | Pointer to the buffer. |
| size | The byte size of the buffer. |
|
inlinenoexcept |
Constructs a BufferView from a generic contiguous container.
| buffer | Reference to the container to use as the source. |
|
inlinenoexcept |
Gets pointer to the underlying buffer.
|
inlineoverridevirtual |
|
inlineoverrideprotectedvirtual |
Low-level data reading implementation.
| dst | Destination buffer |
| size | Number of bytes to read |
Implements nnl::Reader.
|
inlineoverridevirtual |
Seeks to a specific offset in the data.
| offset | The offset to seek to. |
Implements nnl::RWBase.
|
inlinenodiscard |
Creates a view into a subrange of the buffer.
| offset | Starting offset |
| size | Size of the subview |
|
inlineoverridevirtual |
Gets the current position in the data.
Implements nnl::RWBase.
| class nnl::BufferSpan |
Reader/Writer implementation for mutable memory buffers.
Provides read/write access to existing memory without taking ownership. Suitable for modification of buffers or memory-mapped files. Offers an interface similar to std::vector.
Inherits nnl::Reader, and nnl::Writer.
Public Member Functions | |
| BufferSpan (void *buffer, std::size_t size) noexcept | |
| Constructs a BufferSpan from a pointer/size pair. | |
| template<typename TContainer, typename = std::enable_if_t<std::is_trivially_copyable_v<typename TContainer::value_type>>> | |
| BufferSpan (TContainer &buffer) noexcept | |
| Constructs a BufferView from a generic contiguous container. | |
| void | Seek (std::size_t offset) override |
| Seeks to a specific offset in the data. | |
| std::size_t | Tell () override |
| Gets the current position in the data. | |
| std::size_t | Len () override |
| Gets the available length of the data. | |
| void | Clear (u8 val=0) |
| Clears the buffer with a specific value. | |
| BufferView | SubView (std::size_t offset, std::size_t size) const |
| Creates a read-only view into a subrange. | |
| BufferSpan | SubSpan (std::size_t offset, std::size_t size) |
| Creates a mutable span into a subrange. | |
| operator BufferView () const noexcept | |
| Implicit conversion to BufferView. | |
| u8 * | data () noexcept |
| Gets the pointer to the underlying buffer. | |
| Public Member Functions inherited from nnl::Reader | |
| void | ReadBuf (void *dst, std::size_t size) |
| Reads a block of data into the specified destination. | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| T | ReadLE () |
| Reads a trivially copyable object. | |
| template<typename T> | |
| std::vector< T > | ReadArrayLE (std::size_t num_elements) |
| Reads multiple trivially copyable objects into a vector. | |
| Public Member Functions inherited from nnl::Writer | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| Offset< T > | MakeOffsetLE () |
| Creates an Offset pointing to the current position. | |
| Offset< u8 > | WriteBuf (const void *src, std::size_t size) |
| Writes raw binary data. | |
| template<typename T, std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0> | |
| Offset< T > | WriteLE (const T &value) |
| Writes a trivially copyable value. | |
| template<typename T> | |
| Offset< T > | WriteArrayLE (const std::vector< T > &container) |
| Writes contents of a vector. | |
| void | AlignData (std::size_t multiple, unsigned char value=0) |
| Aligns the current position to a specified multiple. | |
Protected Member Functions | |
| void | ReadData (void *dst, std::size_t size) override |
| Low-level data reading implementation. | |
| void | WriteData (const void *src, std::size_t size) override |
| Low-level data writing implementation. | |
|
inlinenoexcept |
Constructs a BufferSpan from a pointer/size pair.
| buffer | Pointer to the buffer. |
| size | The byte size of the buffer. |
|
inlinenoexcept |
Constructs a BufferView from a generic contiguous container.
| buffer | Reference to the container to use as the source. |
|
inline |
Clears the buffer with a specific value.
| val | Value to fill with |
|
inlinenoexcept |
Gets the pointer to the underlying buffer.
|
inlineoverridevirtual |
|
inlinenoexcept |
Implicit conversion to BufferView.
|
inlineoverrideprotectedvirtual |
Low-level data reading implementation.
| dst | Destination buffer |
| size | Number of bytes to read |
Implements nnl::Reader.
|
inlineoverridevirtual |
Seeks to a specific offset in the data.
| offset | The offset to seek to. |
Implements nnl::RWBase.
|
inlinenodiscard |
Creates a mutable span into a subrange.
| offset | Starting offset |
| size | Size of the subspan |
|
inlinenodiscard |
Creates a read-only view into a subrange.
| offset | Starting offset |
| size | Size of the subview |
|
inlineoverridevirtual |
Gets the current position in the data.
Implements nnl::RWBase.
|
inlineoverrideprotectedvirtual |
Low-level data writing implementation.
| src | Source buffer |
| size | Number of bytes to write |
Implements nnl::Writer.
| class nnl::BufferRW |
Reader/Writer implementation that writes to an internal growable buffer.
Automatically manages memory allocation and grows the buffer as needed. The written data can be extracted as an std::vector<u8> by a copy or move operation.
Inherits nnl::Writer, and nnl::Reader.
Public Member Functions | |
| void | Seek (std::size_t offset) override |
| Seeks to a specific offset in the data. | |
| std::size_t | Tell () override |
| Gets the current position in the data. | |
| std::size_t | Len () override |
| Gets the available length of the data. | |
| Buffer | CopyBuf () const |
| Makes a copy of the data. | |
| Buffer | ReleaseBuf () noexcept |
| Transfers the ownership of the internal buffer_. | |
| operator Buffer && () &&noexcept | |
| Implicit conversion to std::vector<u8>&&. | |
| Public Member Functions inherited from nnl::Writer | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| Offset< T > | MakeOffsetLE () |
| Creates an Offset pointing to the current position. | |
| Offset< u8 > | WriteBuf (const void *src, std::size_t size) |
| Writes raw binary data. | |
| template<typename T, std::enable_if_t< std::is_trivially_copyable_v< T >, int > = 0> | |
| Offset< T > | WriteLE (const T &value) |
| Writes a trivially copyable value. | |
| template<typename T> | |
| Offset< T > | WriteArrayLE (const std::vector< T > &container) |
| Writes contents of a vector. | |
| void | AlignData (std::size_t multiple, unsigned char value=0) |
| Aligns the current position to a specified multiple. | |
| Public Member Functions inherited from nnl::Reader | |
| void | ReadBuf (void *dst, std::size_t size) |
| Reads a block of data into the specified destination. | |
| template<typename T, typename = std::enable_if_t<std::is_trivially_copyable_v<T>>> | |
| T | ReadLE () |
| Reads a trivially copyable object. | |
| template<typename T> | |
| std::vector< T > | ReadArrayLE (std::size_t num_elements) |
| Reads multiple trivially copyable objects into a vector. | |
Protected Member Functions | |
| void | WriteData (const void *src, std::size_t size) override |
| Low-level data writing implementation. | |
| void | ReadData (void *dst, std::size_t size) override |
| Low-level data reading implementation. | |
|
inline |
Makes a copy of the data.
|
inlineoverridevirtual |
|
inlinenoexcept |
Implicit conversion to std::vector<u8>&&.
This function can be used to move the contents of the buffer_ to std::vector<u8>.
|
inlineoverrideprotectedvirtual |
Low-level data reading implementation.
| dst | Destination buffer |
| size | Number of bytes to read |
Implements nnl::Reader.
|
inlinenodiscardnoexcept |
Transfers the ownership of the internal buffer_.
|
inlineoverridevirtual |
Seeks to a specific offset in the data.
| offset | The offset to seek to. |
Implements nnl::RWBase.
|
inlineoverridevirtual |
Gets the current position in the data.
Implements nnl::RWBase.
|
inlineoverrideprotectedvirtual |
Low-level data writing implementation.
| src | Source buffer |
| size | Number of bytes to write |
Implements nnl::Writer.
| using nnl::Buffer = std::vector<u8> |
A type alias for std::vector<u8> that denotes a raw, contiguous memory region that may be interpreted in multiple ways.