Open Model Railroad Network (OpenMRN)
Loading...
Searching...
No Matches
ByteChunk Struct Reference

Holds a reference to a raw buffer, with the start and size information. More...

#include <ByteBuffer.hxx>

Public Member Functions

size_t size () const
 
void advance (size_t num_bytes)
 Moves forward the data beginning pointer by a given number of bytes.
 
void set_from (RawBufferPtr buf, size_t len, size_t ofs=0)
 Overwrites this chunk from a raw buffer.
 
void set_from (const string *data)
 Overwrites this chunk from a string.
 
void set_from (const void *data, size_t len)
 Overwrites this chunk from an externally owned memory area.
 
size_t append (const void *data, size_t len)
 Adds more data to the end of the buffer.
 
uint8_t * append_ptr ()
 
void append_complete (size_t len)
 Notifies that a certain number of bytes have been appended, i.e., written into append_ptr().
 
size_t free_space ()
 

Public Attributes

RawBufferPtr ownedData_
 Owns a ref for a RawData buffer.
 
uint8_t * data_ {nullptr}
 Points to the first byte of the useful data.
 
size_t size_ {0}
 How many bytes from data_ does this chunk represent.
 

Detailed Description

Holds a reference to a raw buffer, with the start and size information.

Definition at line 64 of file ByteBuffer.hxx.

Member Function Documentation

◆ advance()

void ByteChunk::advance ( size_t  num_bytes)
inline

Moves forward the data beginning pointer by a given number of bytes.

Represents that some number of bytes were consumed by the sink.

Parameters
num_byteshow much data was consumed. Must be <= size().

Definition at line 85 of file ByteBuffer.hxx.

◆ append()

size_t ByteChunk::append ( const void *  data,
size_t  len 
)
inline

Adds more data to the end of the buffer.

Requirement: this chunk must be a data source, and there has to be an ownedData_ set.

Parameters
datapayload to copy
lenhow many bytes to add
Returns
number of bytes added; this is typically less than len when the RawData buffer gets full. Can be zero.

Definition at line 134 of file ByteBuffer.hxx.

◆ append_complete()

void ByteChunk::append_complete ( size_t  len)
inline

Notifies that a certain number of bytes have been appended, i.e., written into append_ptr().

Requirement: this chunk must be a data source, and there has to be an ownedData_ set.

Definition at line 163 of file ByteBuffer.hxx.

◆ append_ptr()

uint8_t * ByteChunk::append_ptr ( )
inline
Returns
the place where data can be written to append to this buffer. Requirement: this chunk must be a data source, and there has to be an ownedData_ set.

Definition at line 152 of file ByteBuffer.hxx.

◆ free_space()

size_t ByteChunk::free_space ( )
inline
Returns
how many free bytes are there in the underlying raw buffer. This shall only be used by the source (who set ownedData_ to a real raw buffer), and assumes that all bytes beyond the end are free. Always zero if data is owned externally.

Definition at line 172 of file ByteBuffer.hxx.

◆ set_from() [1/3]

void ByteChunk::set_from ( const string *  data)
inline

Overwrites this chunk from a string.

WARNING: the ownership of the string is not transferred; the caller must make sure the string remains alive as long as this Chunk is ever in use (including all copies).

Definition at line 109 of file ByteBuffer.hxx.

◆ set_from() [2/3]

void ByteChunk::set_from ( const void *  data,
size_t  len 
)
inline

Overwrites this chunk from an externally owned memory area.

The caller must make sure the memory area remains alive as long as this Chunk is ever in use (including all copies).

Parameters
datapayload to set into this buffer. Must stay alive.
lennumber of bytes to use from that source.

Definition at line 121 of file ByteBuffer.hxx.

◆ set_from() [3/3]

void ByteChunk::set_from ( RawBufferPtr  buf,
size_t  len,
size_t  ofs = 0 
)
inline

Overwrites this chunk from a raw buffer.

Parameters
bufAn owned share of a RawBuffer.
lenHow many bytes to take from this buffer.
ofsFrom which offset we should take these bytes (default 0, may be omitted).

Definition at line 99 of file ByteBuffer.hxx.

◆ size()

size_t ByteChunk::size ( ) const
inline
Returns
number of bytes pointed to by this chunk.

Definition at line 77 of file ByteBuffer.hxx.

Member Data Documentation

◆ data_

uint8_t* ByteChunk::data_ {nullptr}

Points to the first byte of the useful data.

Definition at line 71 of file ByteBuffer.hxx.

◆ ownedData_

RawBufferPtr ByteChunk::ownedData_

Owns a ref for a RawData buffer.

If this is nullptr, then the data references by this chunk is externally owned.

Definition at line 68 of file ByteBuffer.hxx.

◆ size_

size_t ByteChunk::size_ {0}

How many bytes from data_ does this chunk represent.

Definition at line 74 of file ByteBuffer.hxx.


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