TSDuck Version 3.16-1064 (TSDuck - The MPEG Transport Stream Toolkit)
ts::ByteBlock Class Reference

Definition of a generic block of bytes. More...

Inheritance diagram for ts::ByteBlock:
Collaboration diagram for ts::ByteBlock:

Public Types

typedef std::vector< uint8_t > ByteVector
 Explicit name of superclass, std::vector on uint8_t.
 

Public Member Functions

 ByteBlock (size_type size=0)
 Default constructor. More...
 
 ByteBlock (size_type size, uint8_t value)
 Constructor, initialized with bytes of specified value. More...
 
 ByteBlock (const void *data, size_type size)
 Constructor from a data block. More...
 
 ByteBlock (const char *str)
 Constructor from a C string. More...
 
 ByteBlock (std::initializer_list< uint8_t > init)
 Constructor from an initializer list. More...
 
void append (const void *data, size_type size)
 Append raw data to a byte block. More...
 
void append (const ByteBlock &bb)
 Append a byte block to a byte block. More...
 
void append (const std::string &s)
 Append a string to a byte block. More...
 
void append (uint8_t i, size_type size)
 Append n bytes with value i. More...
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void append (INT i)
 Append an integer in big endian representation at the end. More...
 
std::istream & append (std::istream &strm, size_t maxSize=std::numeric_limits< size_t >::max())
 Read a byte block from standard streams and append to existing content (binary mode). More...
 
void appendBCD (uint32_t i, size_t bcd_count)
 Append an integer in Binary Coded Decimal (BCD) representation at the end. More...
 
bool appendFromFile (const UString &fileName, size_t maxSize=std::numeric_limits< size_t >::max(), Report *report=nullptr)
 Read a byte block from a binary file and append to existing content. More...
 
void appendInt16 (int16_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt16BE (int16_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt16LE (int16_t i)
 Append an integer in little endian representation at the end. More...
 
void appendInt24 (int32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt24BE (int32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt24LE (int32_t i)
 Append an integer in little endian representation at the end. More...
 
void appendInt32 (int32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt32BE (int32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt32LE (int32_t i)
 Append an integer in little endian representation at the end. More...
 
void appendInt64 (int64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt64BE (int64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendInt64LE (int64_t i)
 Append an integer in little endian representation at the end. More...
 
void appendInt8 (int8_t i)
 Append an integer in big endian representation at the end. More...
 
bool appendToFile (const UString &fileName, Report *report=nullptr) const
 Save a byte block to a binary file, append to existing file content. More...
 
void appendUInt16 (uint16_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt16BE (uint16_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt16LE (uint16_t i)
 Append an integer in little endian representation at the end. More...
 
void appendUInt24 (uint32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt24BE (uint32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt24LE (uint32_t i)
 Append an integer in little endian representation at the end. More...
 
void appendUInt32 (uint32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt32BE (uint32_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt32LE (uint32_t i)
 Append an integer in little endian representation at the end. More...
 
void appendUInt40 (uint64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt40BE (uint64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt40LE (uint64_t i)
 Append an integer in little endian representation at the end. More...
 
void appendUInt48 (uint64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt48BE (uint64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt48LE (uint64_t i)
 Append an integer in little endian representation at the end. More...
 
void appendUInt64 (uint64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt64BE (uint64_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUInt64LE (uint64_t i)
 Append an integer in little endian representation at the end. More...
 
void appendUInt8 (uint8_t i)
 Append an integer in big endian representation at the end. More...
 
void appendUTF8 (const UString &s)
 Append a unicode string in UTF-8 representation to a byte block. More...
 
void appendUTF8WithByteLength (const UString &s)
 Append a unicode string in UTF-8 representation to a byte block with one-byte preceding length. More...
 
void copy (const void *data, size_type size)
 Replace the content of a byte block. More...
 
void * enlarge (size_type n)
 Increase size return pointer to new area at end of block. More...
 
void erase (size_type first, size_type size)
 Remove 'size' elements at index 'first'. More...
 
bool loadFromFile (const UString &fileName, size_t maxSize=std::numeric_limits< size_t >::max(), Report *report=nullptr)
 Read a byte block from a binary file. More...
 
std::istream & read (std::istream &strm, size_t maxSize=std::numeric_limits< size_t >::max())
 Read a byte block from standard streams (binary mode). More...
 
bool saveToFile (const UString &fileName, Report *report=nullptr) const
 Save a byte block to a binary file. More...
 
std::ostream & write (std::ostream &strm) const
 Write a byte to standard streams (binary mode). More...
 

Detailed Description

Definition of a generic block of bytes.

This is a subclass of std::vector on uint8_t.

Constructor & Destructor Documentation

◆ ByteBlock() [1/5]

ts::ByteBlock::ByteBlock ( size_type  size = 0)
explicit

Default constructor.

Parameters
[in]sizeInitial size in bytes of the block.

◆ ByteBlock() [2/5]

ts::ByteBlock::ByteBlock ( size_type  size,
uint8_t  value 
)

Constructor, initialized with bytes of specified value.

Parameters
[in]sizeInitial size in bytes of the block.
[in]valueValue of each byte.

◆ ByteBlock() [3/5]

ts::ByteBlock::ByteBlock ( const void *  data,
size_type  size 
)

Constructor from a data block.

Parameters
[in]dataAddress of area to copy.
[in]sizeInitial size of the block.

◆ ByteBlock() [4/5]

ts::ByteBlock::ByteBlock ( const char *  str)

Constructor from a C string.

Parameters
[in]strAddress of a nul-terminated string. The content of the byte block is the content of the string, excluding the terminating nul character.

◆ ByteBlock() [5/5]

ts::ByteBlock::ByteBlock ( std::initializer_list< uint8_t >  init)

Constructor from an initializer list.

Parameters
[in]initInitializer list.

Member Function Documentation

◆ copy()

void ts::ByteBlock::copy ( const void *  data,
size_type  size 
)

Replace the content of a byte block.

Parameters
[in]dataAddress of the new area to copy.
[in]sizeSize of the area to copy.

◆ erase()

void ts::ByteBlock::erase ( size_type  first,
size_type  size 
)

Remove 'size' elements at index 'first'.

The STL equivalent uses iterators, not indices.

Parameters
[in]firstIndex of the first byte to erase.
[in]sizeNumber of bytes to erase.

◆ enlarge()

void* ts::ByteBlock::enlarge ( size_type  n)

Increase size return pointer to new area at end of block.

Parameters
[in]nNumber of bytes to add at the end of the block.
Returns
Address of the new n-byte area at the end of the block.

◆ append() [1/6]

void ts::ByteBlock::append ( const void *  data,
size_type  size 
)
inline

Append raw data to a byte block.

Parameters
[in]dataAddress of the new area to append.
[in]sizeSize of the area to append.

◆ append() [2/6]

void ts::ByteBlock::append ( const ByteBlock bb)
inline

Append a byte block to a byte block.

Parameters
[in]bbByte block to append.

◆ append() [3/6]

void ts::ByteBlock::append ( const std::string &  s)
inline

Append a string to a byte block.

Parameters
[in]sString to append.

◆ appendUTF8()

void ts::ByteBlock::appendUTF8 ( const UString s)

Append a unicode string in UTF-8 representation to a byte block.

Parameters
[in]sString to append.

◆ appendUTF8WithByteLength()

void ts::ByteBlock::appendUTF8WithByteLength ( const UString s)

Append a unicode string in UTF-8 representation to a byte block with one-byte preceding length.

Parameters
[in]sString to append. UTF-8 representation is trunctated to 255 if necessary so that the length fits in one byte.

◆ append() [4/6]

void ts::ByteBlock::append ( uint8_t  i,
size_type  size 
)
inline

Append n bytes with value i.

Parameters
[in]iValue of each byte.
[in]sizeNumber of bytes to append.

◆ appendUInt8()

void ts::ByteBlock::appendUInt8 ( uint8_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt16()

void ts::ByteBlock::appendUInt16 ( uint16_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt24()

void ts::ByteBlock::appendUInt24 ( uint32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt32()

void ts::ByteBlock::appendUInt32 ( uint32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt40()

void ts::ByteBlock::appendUInt40 ( uint64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt48()

void ts::ByteBlock::appendUInt48 ( uint64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt64()

void ts::ByteBlock::appendUInt64 ( uint64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt8()

void ts::ByteBlock::appendInt8 ( int8_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt16()

void ts::ByteBlock::appendInt16 ( int16_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt24()

void ts::ByteBlock::appendInt24 ( int32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt32()

void ts::ByteBlock::appendInt32 ( int32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt64()

void ts::ByteBlock::appendInt64 ( int64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt16BE()

void ts::ByteBlock::appendUInt16BE ( uint16_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt24BE()

void ts::ByteBlock::appendUInt24BE ( uint32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt32BE()

void ts::ByteBlock::appendUInt32BE ( uint32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt40BE()

void ts::ByteBlock::appendUInt40BE ( uint64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt48BE()

void ts::ByteBlock::appendUInt48BE ( uint64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt64BE()

void ts::ByteBlock::appendUInt64BE ( uint64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt16BE()

void ts::ByteBlock::appendInt16BE ( int16_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt24BE()

void ts::ByteBlock::appendInt24BE ( int32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt32BE()

void ts::ByteBlock::appendInt32BE ( int32_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt64BE()

void ts::ByteBlock::appendInt64BE ( int64_t  i)
inline

Append an integer in big endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt16LE()

void ts::ByteBlock::appendUInt16LE ( uint16_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt24LE()

void ts::ByteBlock::appendUInt24LE ( uint32_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt32LE()

void ts::ByteBlock::appendUInt32LE ( uint32_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt40LE()

void ts::ByteBlock::appendUInt40LE ( uint64_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt48LE()

void ts::ByteBlock::appendUInt48LE ( uint64_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendUInt64LE()

void ts::ByteBlock::appendUInt64LE ( uint64_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt16LE()

void ts::ByteBlock::appendInt16LE ( int16_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt24LE()

void ts::ByteBlock::appendInt24LE ( int32_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt32LE()

void ts::ByteBlock::appendInt32LE ( int32_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendInt64LE()

void ts::ByteBlock::appendInt64LE ( int64_t  i)
inline

Append an integer in little endian representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.

◆ append() [5/6]

template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void ts::ByteBlock::append ( INT  i)
inline

Append an integer in big endian representation at the end.

Template variant.

Template Parameters
INTInteger type to serialize.
Parameters
[in]iInteger value to serialize at the end of the block.

◆ appendBCD()

void ts::ByteBlock::appendBCD ( uint32_t  i,
size_t  bcd_count 
)

Append an integer in Binary Coded Decimal (BCD) representation at the end.

Parameters
[in]iInteger value to serialize at the end of the block.
[in]bcd_countNumber of BCD digits. Note that bcd_count can be even.

◆ loadFromFile()

bool ts::ByteBlock::loadFromFile ( const UString fileName,
size_t  maxSize = std::numeric_limits< size_t >::max(),
Report report = nullptr 
)

Read a byte block from a binary file.

Parameters
[in]fileNameInput file name.
[in]maxSizeMaximum size to read. By default, read up to end of file or error.
[in,out]reportIf not null, where to report errors.
Returns
True on success, false on error.

◆ appendFromFile()

bool ts::ByteBlock::appendFromFile ( const UString fileName,
size_t  maxSize = std::numeric_limits< size_t >::max(),
Report report = nullptr 
)

Read a byte block from a binary file and append to existing content.

Parameters
[in]fileNameInput file name.
[in]maxSizeMaximum size to read. By default, read up to end of file or error.
[in,out]reportIf not null, where to report errors.
Returns
True on success, false on error.

◆ saveToFile()

bool ts::ByteBlock::saveToFile ( const UString fileName,
Report report = nullptr 
) const
inline

Save a byte block to a binary file.

Parameters
[in]fileNameOutput file name.
[in,out]reportIf not null, where to report errors.
Returns
True on success, false on error.

◆ appendToFile()

bool ts::ByteBlock::appendToFile ( const UString fileName,
Report report = nullptr 
) const
inline

Save a byte block to a binary file, append to existing file content.

Parameters
[in]fileNameOutput file name.
[in,out]reportIf not null, where to report errors.
Returns
True on success, false on error.

◆ read()

std::istream& ts::ByteBlock::read ( std::istream &  strm,
size_t  maxSize = std::numeric_limits< size_t >::max() 
)

Read a byte block from standard streams (binary mode).

Parameters
[in,out]strmA standard stream in input mode.
[in]maxSizeMaximum size to read. By default, read up to end of file or error.
Returns
A reference to the strm object.

◆ append() [6/6]

std::istream& ts::ByteBlock::append ( std::istream &  strm,
size_t  maxSize = std::numeric_limits< size_t >::max() 
)

Read a byte block from standard streams and append to existing content (binary mode).

Parameters
[in,out]strmA standard stream in input mode.
[in]maxSizeMaximum size to read. By default, read up to end of file or error.
Returns
A reference to the strm object.

◆ write()

std::ostream& ts::ByteBlock::write ( std::ostream &  strm) const
inline

Write a byte to standard streams (binary mode).

Parameters
[in,out]strmA standard stream in output mode.
Returns
A reference to the strm object.

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