TSDuck v3.40-4025
MPEG Transport Stream Toolkit
|
Definition of a generic block of bytes. More...
#include <tsByteBlock.h>
Public Types | |
using | ByteVector = std::vector< uint8_t > |
Explicit name of superclass, std::vector on uint8_t . | |
Public Member Functions | |
ByteBlock (const char *str) | |
Constructor from a C string. | |
ByteBlock (const void *data, size_type size) | |
Constructor from a data block. | |
ByteBlock (size_type size, uint8_t value) | |
Constructor, initialized with bytes of specified value. | |
ByteBlock (size_type size=0) | |
Default constructor. | |
ByteBlock (std::initializer_list< uint8_t > init) | |
Constructor from an initializer list. | |
void | append (const ByteBlock &bb) |
Append a byte block to a byte block. | |
void | append (const std::string &s) |
Append a string to a byte block. | |
void | append (const void *data, size_type size) |
Append raw data to a byte block. | |
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. | |
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). | |
void | append (uint8_t i, size_type size) |
Append n bytes with value i. | |
void | appendBCD (uint32_t value, size_t bcd_count, bool left_justified=true, uint8_t pad_nibble=0) |
Append an integer in Binary Coded Decimal (BCD) representation at the end. | |
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. | |
void | appendInt16 (int16_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt16BE (int16_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt16LE (int16_t i) |
Append an integer in little endian representation at the end. | |
void | appendInt24 (int32_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt24BE (int32_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt24LE (int32_t i) |
Append an integer in little endian representation at the end. | |
void | appendInt32 (int32_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt32BE (int32_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt32LE (int32_t i) |
Append an integer in little endian representation at the end. | |
void | appendInt64 (int64_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt64BE (int64_t i) |
Append an integer in big endian representation at the end. | |
void | appendInt64LE (int64_t i) |
Append an integer in little endian representation at the end. | |
void | appendInt8 (int8_t i) |
Append an integer in big endian representation at the end. | |
bool | appendToFile (const UString &fileName, Report *report=nullptr) const |
Save a byte block to a binary file, append to existing file content. | |
void | appendUInt16 (uint16_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt16BE (uint16_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt16LE (uint16_t i) |
Append an integer in little endian representation at the end. | |
void | appendUInt24 (uint32_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt24BE (uint32_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt24LE (uint32_t i) |
Append an integer in little endian representation at the end. | |
void | appendUInt32 (uint32_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt32BE (uint32_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt32LE (uint32_t i) |
Append an integer in little endian representation at the end. | |
void | appendUInt40 (uint64_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt40BE (uint64_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt40LE (uint64_t i) |
Append an integer in little endian representation at the end. | |
void | appendUInt48 (uint64_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt48BE (uint64_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt48LE (uint64_t i) |
Append an integer in little endian representation at the end. | |
void | appendUInt64 (uint64_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt64BE (uint64_t i) |
Append an integer in big endian representation at the end. | |
void | appendUInt64LE (uint64_t i) |
Append an integer in little endian representation at the end. | |
void | appendUInt8 (uint8_t i) |
Append an integer in big endian representation at the end. | |
void | appendUTF8 (const UString &s) |
Append a unicode string in UTF-8 representation to a byte block. | |
void | appendUTF8WithByteLength (const UString &s) |
Append a unicode string in UTF-8 representation to a byte block with one-byte preceding length. | |
void | copy (const void *data, size_type size) |
Replace the content of a byte block. | |
uint8_t * | dataEnd () |
Get a pointer after the last byte in the block. | |
const uint8_t * | dataEnd () const |
Get a pointer after the last byte in the block. | |
uint8_t * | enlarge (size_type n) |
Increase size return pointer to new area at end of block. | |
void | erase (size_type first, size_type size) |
Remove 'size' elements at index 'first'. | |
size_type | find (uint8_t value, size_type start=0) |
Find the first occurence of a byte value in a byte block. | |
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. | |
std::istream & | read (std::istream &strm, size_t maxSize=std::numeric_limits< size_t >::max()) |
Read a byte block from standard streams (binary mode). | |
bool | saveToFile (const UString &fileName, Report *report=nullptr) const |
Save a byte block to a binary file. | |
std::ostream & | write (std::ostream &strm) const |
Write a byte to standard streams (binary mode). | |
Definition of a generic block of bytes.
This is a subclass of std::vector
on uint8_t
.
|
explicit |
Default constructor.
[in] | size | Initial size in bytes of the block. |
ts::ByteBlock::ByteBlock | ( | size_type | size, |
uint8_t | value | ||
) |
Constructor, initialized with bytes of specified value.
[in] | size | Initial size in bytes of the block. |
[in] | value | Value of each byte. |
ts::ByteBlock::ByteBlock | ( | const void * | data, |
size_type | size | ||
) |
Constructor from a data block.
[in] | data | Address of area to copy. |
[in] | size | Initial size of the block. |
ts::ByteBlock::ByteBlock | ( | const char * | str | ) |
Constructor from a C string.
[in] | str | Address of a nul-terminated string. The content of the byte block is the content of the string, excluding the terminating nul character. |
ts::ByteBlock::ByteBlock | ( | std::initializer_list< uint8_t > | init | ) |
Constructor from an initializer list.
[in] | init | Initializer list. |
|
inline |
Get a pointer after the last byte in the block.
|
inline |
Get a pointer after the last byte in the block.
size_type ts::ByteBlock::find | ( | uint8_t | value, |
size_type | start = 0 |
||
) |
Find the first occurence of a byte value in a byte block.
[in] | value | The byte value to search. |
[in] | start | Index where to start (at the beginning by default). |
void ts::ByteBlock::copy | ( | const void * | data, |
size_type | size | ||
) |
Replace the content of a byte block.
[in] | data | Address of the new area to copy. |
[in] | size | Size of the area to copy. |
void ts::ByteBlock::erase | ( | size_type | first, |
size_type | size | ||
) |
Remove 'size' elements at index 'first'.
The STL equivalent uses iterators, not indices.
[in] | first | Index of the first byte to erase. |
[in] | size | Number of bytes to erase. |
uint8_t * ts::ByteBlock::enlarge | ( | size_type | n | ) |
Increase size return pointer to new area at end of block.
[in] | n | Number of bytes to add at the end of the block. |
|
inline |
Append raw data to a byte block.
[in] | data | Address of the new area to append. |
[in] | size | Size of the area to append. |
|
inline |
Append a byte block to a byte block.
[in] | bb | Byte block to append. |
|
inline |
Append a string to a byte block.
[in] | s | String to append. |
void ts::ByteBlock::appendUTF8 | ( | const UString & | s | ) |
Append a unicode string in UTF-8 representation to a byte block.
[in] | s | String to append. |
void ts::ByteBlock::appendUTF8WithByteLength | ( | const UString & | s | ) |
Append a unicode string in UTF-8 representation to a byte block with one-byte preceding length.
[in] | s | String to append. UTF-8 representation is trunctated to 255 if necessary so that the length fits in one byte. |
|
inline |
Append n bytes with value i.
[in] | i | Value of each byte. |
[in] | size | Number of bytes to append. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in big endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
|
inline |
Append an integer in little endian representation at the end.
[in] | i | Integer value to serialize at the end of the block. |
void ts::ByteBlock::appendBCD | ( | uint32_t | value, |
size_t | bcd_count, | ||
bool | left_justified = true , |
||
uint8_t | pad_nibble = 0 |
||
) |
Append an integer in Binary Coded Decimal (BCD) representation at the end.
[in] | value | Integer value to serialize at the end of the block. |
[in] | bcd_count | Number of BCD digits. Note that bcd_count can be even. |
[in] | left_justified | When true (the default), the first BCD digit starts in the first half of the first byte. When false and bcd_count is odd, the first BCD digit starts in the second half of the first byte. This parameter is ignored when bcd_count is even. |
[in] | pad_nibble | A value in the range 0..15 to set in the unused nibble when bcd_count is odd. This is the first half of the first byte when left_justified is false. This is the second half of the last byte when left_justified is true. This parameter is ignored when bcd_count is even. |
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.
[in] | fileName | Input file name. |
[in] | maxSize | Maximum size to read. By default, read up to end of file or error. |
[in,out] | report | If not null, where to report errors. |
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.
[in] | fileName | Input file name. |
[in] | maxSize | Maximum size to read. By default, read up to end of file or error. |
[in,out] | report | If not null, where to report errors. |
Save a byte block to a binary file.
[in] | fileName | Output file name. |
[in,out] | report | If not null, where to report errors. |
Save a byte block to a binary file, append to existing file content.
[in] | fileName | Output file name. |
[in,out] | report | If not null, where to report errors. |
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).
[in,out] | strm | A standard stream in input mode. |
[in] | maxSize | Maximum size to read. By default, read up to end of file or error. |
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).
[in,out] | strm | A standard stream in input mode. |
[in] | maxSize | Maximum size to read. By default, read up to end of file or error. |
std::ostream & ts::ByteBlock::write | ( | std::ostream & | strm | ) | const |
Write a byte to standard streams (binary mode).
[in,out] | strm | A standard stream in output mode. |