TSDuck v3.46-4930
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > Class Template Reference

#include <tsDataBlock.h>

Inheritance diagram for ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >:

Public Member Functions

 DataBlock ()=default
 DataBlock (const ByteBlock &content)
 DataBlock (const ByteBlockPtr &content_ptr, ShareMode mode)
 DataBlock (const DataBlock &other, ShareMode mode)
 DataBlock (const void *content, size_t content_size)
 DataBlock (DataBlock &&other)
virtual ~DataBlock ()
virtual void clear ()
virtual const uint8_t * content () const
DataBlock & copy (const DataBlock &other)
virtual bool isValid () const
bool matchContent (const ByteBlock &pattern, const ByteBlock &mask=ByteBlock()) const
DataBlock & operator= (const DataBlock &other)
DataBlock & operator= (DataBlock &&other) noexcept
bool operator== (const DataBlock &other) const
size_t rawDataSize () const
void reload (const ByteBlock &content)
void reload (const ByteBlockPtr &content_ptr)
void reload (const void *content, size_t content_size)
virtual size_t size () const

Static Public Member Functions

static size_t GetLengthField (const void *content, size_t content_size)
static bool ValidateLengthField (const void *content, size_t content_size, bool allow_extra_data)

Static Public Attributes

static constexpr size_t AFTER_LEN_BYTE_OFFSET = LEN_SIZE == 0 ? 0 : (LEN_OFFSET + LEN_SIZE + 7) / 8
static constexpr size_t LEN_BIT_OFFSET = LEN_SIZE == 0 ? 0 : LEN_OFFSET
static constexpr size_t LEN_BIT_SIZE = LEN_SIZE
static constexpr bool UNBOUNDED_IS_ALLOWED = UNBOUNDED_ALLOWED

Protected Member Functions

void rwAppend (const void *data, size_t dsize)
uint8_t * rwContent ()
void rwResize (size_t s)

Detailed Description

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
class ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >

Base class for all kinds of binary data structures with an optional length field.

Template Parameters
LEN_OFFSETOffset in bits of the length field from the beginning of the structure.
LEN_SIZESize in bits of the length field. If zero, there is no length field.
UNBOUNDED_ALLOWEDIf 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.

Constructor & Destructor Documentation

◆ DataBlock() [1/6]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock ( )
default

Default constructor.

◆ DataBlock() [2/6]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock ( const DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > & other,
ShareMode mode )

Copy constructor.

Parameters
[in]otherAnother instance to copy.
[in]modeThe data are either shared (ShareMode::SHARE) between the two instances or duplicated (ShareMode::COPY).

◆ DataBlock() [3/6]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock ( DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > && other)
inline

Move constructor.

Parameters
[in,out]otherAnother instance to move.

◆ DataBlock() [4/6]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock ( const void * content,
size_t content_size )

Constructor from full binary content.

Parameters
[in]contentAddress of the binary data.
[in]content_sizeSize in bytes of the data.

◆ DataBlock() [5/6]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock ( const ByteBlock & content)

Constructor from full binary content.

Parameters
[in]contentBinary packet data. The content is copied into a new byte block.

◆ DataBlock() [6/6]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::DataBlock ( const ByteBlockPtr & content_ptr,
ShareMode mode )

Constructor from full binary content.

Parameters
[in]content_ptrSafe pointer to the binary data.
[in]modeThe 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.

◆ ~DataBlock()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
virtual ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::~DataBlock ( )
virtual

Virtual destructor.

Member Function Documentation

◆ isValid()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
virtual bool ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::isValid ( ) const
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.

Returns
True if the descriptor has valid content.

Reimplemented in ts::PESPacket, ts::Section, and ts::T2MIPacket.

◆ reload() [1/3]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::reload ( const void * content,
size_t content_size )

Reload from full binary content.

Parameters
[in]contentAddress of the binary packet data.
[in]content_sizeSize in bytes of the packet.

◆ reload() [2/3]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::reload ( const ByteBlock & content)

Reload from full binary content.

Parameters
[in]contentBinary packet data. The content is copied into a new byte block.

◆ reload() [3/3]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::reload ( const ByteBlockPtr & content_ptr)

Reload from full binary content.

Parameters
[in]content_ptrSafe pointer to the binary packet data. The content is referenced, and thus shared. Do not modify the referenced ByteBlock from outside the DataBlock.

◆ clear()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
virtual void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::clear ( )
virtual

Clear data content.

Reimplemented in ts::DemuxedData, ts::PESPacket, ts::Section, and ts::T2MIPacket.

◆ operator=() [1/2]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
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.

Parameters
[in]otherOther packet to assign to this object.
Returns
A reference to this object.

◆ operator=() [2/2]

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
DataBlock & ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::operator= ( DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED > && other)
noexcept

Move assignment operator.

Parameters
[in,out]otherOther packet to assign to this object.
Returns
A reference to this object.

◆ copy()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
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.

Parameters
[in]otherOther data to duplicate into this object.
Returns
A reference to this object.

◆ operator==()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
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.

Parameters
[in]otherOther packet to compare.
Returns
True if the two packets are identical. False otherwise.

◆ content()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
virtual const uint8_t * ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::content ( ) const
virtual

Access to the full binary content of the data. Do not modify content.

Returns
Address of the full binary content of the data. May be invalidated after modification.

◆ size()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
virtual size_t ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::size ( ) const
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.

Returns
Size of the logical binary content of the data.
See also
rawDataSize()

Reimplemented in ts::PESPacket.

◆ rawDataSize()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
size_t ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::rawDataSize ( ) const
inline

Size of the complete binary raw data containing the logical structure. Non-virtual method, always return the same result.

Returns
Size of the complete binary raw data.
See also
size()

◆ matchContent()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
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.

Parameters
[in]patternA byte block to compare with the start of the data.
[in]maskOptional mask to select meaningful bits in pattern.
Returns
Size of the binary content of the data.

◆ GetLengthField()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
size_t ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::GetLengthField ( const void * content,
size_t content_size )
static

Static method to extract the content of the length field.

Parameters
[in]contentAddress of the binary data. Can be the null pointer.
[in]content_sizeSize in bytes of the data.
Returns
The extracted length field or NPOS if the data structure does not contain a length field or if the length is "unbounded" (when allowed).

◆ ValidateLengthField()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
bool ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::ValidateLengthField ( const void * content,
size_t content_size,
bool allow_extra_data )
static

Static method to validate the content of the length field.

Parameters
[in]contentAddress of the binary data. Can be the null pointer.
[in]content_sizeSize in bytes of the data.
[in]allow_extra_dataIf true, additional data are allowed after the declared length.
Returns
True if the length field is valid, or the length field does not exist, or the length field is "unbounded" (when allowed).

◆ rwContent()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
uint8_t * ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::rwContent ( )
inlineprotected

Read/write access to the full binary content of the data for subclasses.

Returns
Address of the full binary content of the data.

◆ rwResize()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::rwResize ( size_t s)
protected

Resize the full binary content of the data for subclasses.

Parameters
[in]sNew size in bytes of the full binary content of the data.

◆ rwAppend()

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
void ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::rwAppend ( const void * data,
size_t dsize )
protected

Append raw data to the full binary content of the data for subclasses.

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

Member Data Documentation

◆ LEN_BIT_OFFSET

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
size_t ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::LEN_BIT_OFFSET = LEN_SIZE == 0 ? 0 : LEN_OFFSET
staticconstexpr

Offset in bits of the length field from the beginning of the structure.

◆ LEN_BIT_SIZE

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
size_t ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::LEN_BIT_SIZE = LEN_SIZE
staticconstexpr

Size in bits of the length field. If zero, there is no length field.

◆ AFTER_LEN_BYTE_OFFSET

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
size_t ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::AFTER_LEN_BYTE_OFFSET = LEN_SIZE == 0 ? 0 : (LEN_OFFSET + LEN_SIZE + 7) / 8
staticconstexpr

Offset in bytes of the next byte after the length field. Zero if there is no length field.

◆ UNBOUNDED_IS_ALLOWED

template<const size_t LEN_OFFSET = 0, const size_t LEN_SIZE = 0, const bool UNBOUNDED_ALLOWED = false>
bool ts::DataBlock< LEN_OFFSET, LEN_SIZE, UNBOUNDED_ALLOWED >::UNBOUNDED_IS_ALLOWED = UNBOUNDED_ALLOWED
staticconstexpr

If true, the length field allows zero as an "unbounded" value.


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