![]() |
TSDuck v3.43-4441
MPEG Transport Stream Toolkit
|
Base class for all kinds of binary data structures with an optional length field. More...
#include <tsDataBlock.h>
Public Member Functions | |
DataBlock ()=default | |
Default constructor. | |
DataBlock (const ByteBlock &content) | |
Constructor from full binary content. | |
DataBlock (const ByteBlockPtr &content_ptr, ShareMode mode) | |
Constructor from full binary content. | |
DataBlock (const DataBlock &other, ShareMode mode) | |
Copy constructor. | |
DataBlock (const void *content, size_t content_size) | |
Constructor from full binary content. | |
DataBlock (DataBlock &&other) | |
Move constructor. | |
virtual | ~DataBlock () |
Virtual destructor. | |
virtual void | clear () |
Clear data content. | |
virtual const uint8_t * | content () const |
Access to the full binary content of the data. | |
DataBlock & | copy (const DataBlock &other) |
Duplication. | |
virtual bool | isValid () const |
Check if the data structure has valid content. | |
bool | matchContent (const ByteBlock &pattern, const ByteBlock &mask=ByteBlock()) const |
Check if the start of the data matches a given pattern. | |
DataBlock & | operator= (const DataBlock &other) |
Assignment operator. | |
DataBlock & | operator= (DataBlock &&other) noexcept |
Move assignment operator. | |
bool | operator== (const DataBlock &other) const |
Equality operator. | |
size_t | rawDataSize () const |
Size of the complete binary raw data containing the logical structure. | |
void | reload (const ByteBlock &content) |
Reload from full binary content. | |
void | reload (const ByteBlockPtr &content_ptr) |
Reload from full binary content. | |
void | reload (const void *content, size_t content_size) |
Reload from full binary content. | |
virtual size_t | size () const |
Size of the logical binary content of the data. | |
Static Public Member Functions | |
static size_t | GetLengthField (const void *content, size_t content_size) |
Static method to extract the content of the length field. | |
static bool | ValidateLengthField (const void *content, size_t content_size, bool allow_extra_data) |
Static method to validate the content of the length field. | |
Static Public Attributes | |
static constexpr size_t | AFTER_LEN_BYTE_OFFSET = LEN_SIZE == 0 ? 0 : (LEN_OFFSET + LEN_SIZE + 7) / 8 |
Offset in bytes of the next byte after the length field. | |
static constexpr size_t | LEN_BIT_OFFSET = LEN_SIZE == 0 ? 0 : LEN_OFFSET |
Offset in bits of the length field from the beginning of the structure. | |
static constexpr size_t | LEN_BIT_SIZE = LEN_SIZE |
Size in bits of the length field. | |
static constexpr bool | UNBOUNDED_IS_ALLOWED = UNBOUNDED_ALLOWED |
If true, the length field allows zero as an "unbounded" value. | |
Protected Member Functions | |
void | rwAppend (const void *data, size_t dsize) |
Append raw data to the full binary content of the data for subclasses. | |
uint8_t * | rwContent () |
Read/write access to the full binary content of the data for subclasses. | |
void | rwResize (size_t s) |
Resize the full binary content of the data for subclasses. | |
Base class for all kinds of binary data structures with an optional length field.
LEN_OFFSET | Offset in bits of the length field from the beginning of the structure. |
LEN_SIZE | Size in bits of the length field. If zero, there is no length field. |
UNBOUNDED_ALLOWED | If true, the length field allows zero as an "unbounded" value, meaning that the size is unchecked and solely defined by the binary size of the structure. |
The binary data of the structure is hidden inside the class. It is implemented as a shared pointer to a ByteBlock. The corresponding data block can be shared or copied between instances, reducing the number of memory copies.
When defined, the length field shall contain the number of bytes, immediately after that length field.
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock | ( | const DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > & | other, |
ShareMode | mode | ||
) |
Copy constructor.
[in] | other | Another instance to copy. |
[in] | mode | The data are either shared (ShareMode::SHARE) between the two instances or duplicated (ShareMode::COPY). |
|
inline |
Move constructor.
[in,out] | other | Another instance to move. |
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock | ( | const void * | content, |
size_t | content_size | ||
) |
Constructor from full binary content.
[in] | content | Address of the binary data. |
[in] | content_size | Size in bytes of the data. |
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock | ( | const ByteBlock & | content | ) |
Constructor from full binary content.
[in] | content | Binary packet data. The content is copied into a new byte block. |
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock | ( | const ByteBlockPtr & | content_ptr, |
ShareMode | mode | ||
) |
Constructor from full binary content.
[in] | content_ptr | Safe pointer to the binary data. |
[in] | mode | The data are either shared (ShareMode::SHARE) between the descriptor and content_ptr or duplicated (ShareMode::COPY). If shared, do not modify the referenced ByteBlock from outside the DataBlock. |
|
virtual |
Check if the data structure has valid content.
The base implementation only checks that the binary data are allocated. The various constructors or methods which replace the binary content already check the validity of the length field, when there is one. Subclasses may override this method with additional checks.
Reimplemented in ts::PESPacket, ts::Section, and ts::T2MIPacket.
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::reload | ( | const void * | content, |
size_t | content_size | ||
) |
Reload from full binary content.
[in] | content | Address of the binary packet data. |
[in] | content_size | Size in bytes of the packet. |
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::reload | ( | const ByteBlock & | content | ) |
Reload from full binary content.
[in] | content | Binary packet data. The content is copied into a new byte block. |
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::reload | ( | const ByteBlockPtr & | content_ptr | ) |
|
virtual |
Clear data content.
Reimplemented in ts::DemuxedData, ts::PESPacket, ts::Section, and ts::T2MIPacket.
DataBlock & ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::operator= | ( | const DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > & | other | ) |
Assignment operator.
The packets are referenced, and thus shared between the two packet objects.
[in] | other | Other packet to assign to this object. |
|
noexcept |
Move assignment operator.
[in,out] | other | Other packet to assign to this object. |
DataBlock & ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::copy | ( | const DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > & | other | ) |
Duplication.
Similar to assignment but the data are duplicated.
[in] | other | Other data to duplicate into this object. |
bool ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::operator== | ( | const DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > & | other | ) | const |
Equality operator.
The source PID's are ignored, only the data contents are compared.
[in] | other | Other packet to compare. |
|
virtual |
Access to the full binary content of the data.
Do not modify content.
|
virtual |
Size of the logical binary content of the data.
For subclasses of DataBlock, this is the logical size of the data structure inside the DataBlock blob.
Reimplemented in ts::PESPacket.
|
inline |
Size of the complete binary raw data containing the logical structure.
Non-virtual method, always return the same result.
bool ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::matchContent | ( | const ByteBlock & | pattern, |
const ByteBlock & | mask = ByteBlock() |
||
) | const |
Check if the start of the data matches a given pattern.
[in] | pattern | A byte block to compare with the start of the data. |
[in] | mask | Optional mask to select meaningful bits in pattern. |
|
static |
Static method to extract the content of the length field.
[in] | content | Address of the binary data. Can be the null pointer. |
[in] | content_size | Size in bytes of the data. |
|
static |
Static method to validate the content of the length field.
[in] | content | Address of the binary data. Can be the null pointer. |
[in] | content_size | Size in bytes of the data. |
[in] | allow_extra_data | If true, additional data are allowed after the declared length. |
|
inlineprotected |
Read/write access to the full binary content of the data for subclasses.
|
protected |
Resize the full binary content of the data for subclasses.
[in] | s | New size in bytes of the full binary content of the data. |
|
protected |
Append raw data to the full binary content of the data for subclasses.
[in] | data | Address of the new area to append. |
[in] | dsize | Size of the area to append. |
|
staticconstexpr |
Size in bits of the length field.
If zero, there is no length field.
|
staticconstexpr |
Offset in bytes of the next byte after the length field.
Zero if there is no length field.