sparrow-ipc 0.2.0
Loading...
Searching...
No Matches
sparrow_ipc::chunked_memory_output_stream< R > Class Template Reference

An output stream that writes data into separate memory chunks. More...

#include <chunk_memory_output_stream.hpp>

Public Member Functions

 chunked_memory_output_stream (R &chunks)
 Constructs a chunked memory output stream with a reference to a chunk container.
 
chunked_memory_output_stream< R > & write (const char *s, std::streamsize count)
 Writes character data as a new chunk.
 
chunked_memory_output_stream< R > & write (std::span< const std::uint8_t > span)
 Writes a span of bytes as a new chunk.
 
chunked_memory_output_stream< R > & write (std::vector< uint8_t > &&buffer)
 Writes a buffer by moving it into the chunk container.
 
chunked_memory_output_stream< R > & write (uint8_t value, std::size_t count)
 Writes a byte value repeated a specified number of times as a new chunk.
 
chunked_memory_output_stream< R > & put (char value)
 Writes a single character as a new chunk.
 
void reserve (std::size_t size)
 Reserves capacity in the chunk container.
 
void reserve (const std::function< std::size_t()> &calculate_reserve_size)
 Reserves capacity using a lazy calculation function.
 
size_t size () const
 Gets the total size of all chunks.
 

Detailed Description

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
class sparrow_ipc::chunked_memory_output_stream< R >

An output stream that writes data into separate memory chunks.

This template class stores data in discrete memory chunks rather than a single contiguous buffer. Each write operation creates a new chunk, making it suitable for scenarios where data needs to be processed or transmitted in separate units.

Template Parameters
RA random access range type where each element is itself a random access range of uint8_t. Typically std::vector<std::vector<uint8_t>> or similar nested container types.

The chunked approach offers several benefits:

  • Avoids large contiguous memory allocations
  • Enables efficient chunk-by-chunk processing or transmission
  • Supports memory reservation for the chunk container (not individual chunks)
Note
Each write operation creates a new chunk in the container, regardless of the write size.

Definition at line 32 of file chunk_memory_output_stream.hpp.

Constructor & Destructor Documentation

◆ chunked_memory_output_stream()

template<typename R>
sparrow_ipc::chunked_memory_output_stream< R >::chunked_memory_output_stream ( R & chunks)
inlineexplicit

Constructs a chunked memory output stream with a reference to a chunk container.

Parameters
chunksReference to the container that will store the memory chunks. The stream stores a pointer to this container for write operations.

Definition at line 42 of file chunk_memory_output_stream.hpp.

Here is the caller graph for this function:

Member Function Documentation

◆ put()

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::put ( char value)

Writes a single character as a new chunk.

Creates a new chunk containing a single byte.

Parameters
valueThe character value to write
Returns
Reference to this stream for method chaining

Definition at line 177 of file chunk_memory_output_stream.hpp.

Here is the call graph for this function:

◆ reserve() [1/2]

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
void sparrow_ipc::chunked_memory_output_stream< R >::reserve ( const std::function< std::size_t()> & calculate_reserve_size)

Reserves capacity using a lazy calculation function.

Reserves space for chunks by calling the provided function to determine the count.

Parameters
calculate_reserve_sizeFunction that returns the number of chunks to reserve

Definition at line 196 of file chunk_memory_output_stream.hpp.

◆ reserve() [2/2]

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
void sparrow_ipc::chunked_memory_output_stream< R >::reserve ( std::size_t size)

Reserves capacity in the chunk container.

Reserves space for the specified number of chunks in the container. This does not reserve space within individual chunks.

Parameters
sizeNumber of chunks to reserve space for

Definition at line 187 of file chunk_memory_output_stream.hpp.

Here is the call graph for this function:
Here is the caller graph for this function:

◆ size()

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
size_t sparrow_ipc::chunked_memory_output_stream< R >::size ( ) const
nodiscard

Gets the total size of all chunks.

Calculates and returns the sum of sizes of all chunks in the container.

Returns
The total number of bytes across all chunks

Definition at line 205 of file chunk_memory_output_stream.hpp.

Here is the caller graph for this function:

◆ write() [1/4]

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write ( const char * s,
std::streamsize count )

Writes character data as a new chunk.

Creates a new chunk containing the specified character data.

Parameters
sPointer to the character data to write
countNumber of characters to write
Returns
Reference to this stream for method chaining

Definition at line 137 of file chunk_memory_output_stream.hpp.

Here is the call graph for this function:

◆ write() [2/4]

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write ( std::span< const std::uint8_t > span)

Writes a span of bytes as a new chunk.

Creates a new chunk containing the data from the provided span.

Parameters
spanA span of bytes to write as a new chunk
Returns
Reference to this stream for method chaining

Definition at line 147 of file chunk_memory_output_stream.hpp.

Here is the call graph for this function:

◆ write() [3/4]

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write ( std::vector< uint8_t > && buffer)

Writes a buffer by moving it into the chunk container.

This is an optimized write operation that moves an existing buffer into the chunk container, avoiding a copy operation.

Parameters
bufferA vector of bytes to move into the chunk container
Returns
Reference to this stream for method chaining

Definition at line 157 of file chunk_memory_output_stream.hpp.

Here is the call graph for this function:

◆ write() [4/4]

template<typename R>
requires std::ranges::random_access_range<R> && std::ranges::random_access_range<std::ranges::range_value_t<R>> && std::same_as<typename std::ranges::range_value_t<R>::value_type, uint8_t>
chunked_memory_output_stream< R > & sparrow_ipc::chunked_memory_output_stream< R >::write ( uint8_t value,
std::size_t count )

Writes a byte value repeated a specified number of times as a new chunk.

Creates a new chunk filled with the specified byte value.

Parameters
valueThe byte value to write
countNumber of times to repeat the value
Returns
Reference to this stream for method chaining

Definition at line 167 of file chunk_memory_output_stream.hpp.

Here is the call graph for this function:

The documentation for this class was generated from the following file: