TSDuck Version 3.32-2769 (TSDuck - The MPEG Transport Stream Toolkit)
ts::TLVSyntax Class Reference

Representation of a Tag, Length, Value (TVL) syntax. More...

Public Member Functions

 TLVSyntax (int start=-1, int size=-1, size_t tagSize=1, size_t lengthSize=1, bool msb=true, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance()))))
 Default constructor. More...
 
bool fromString (const UString &s, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance()))))
 Set the values of a TLVSyntax object from a string representation. More...
 
size_t getLengthSize () const
 Get the size in bytes of the Length field. More...
 
size_t getTagAndLength (const uint8_t *data, size_t size, uint32_t &tag, size_t &length) const
 Extract a tag and length value from a data area. More...
 
size_t getTagSize () const
 Get the size in bytes of the Tag field. More...
 
bool locateTLV (const uint8_t *data, size_t dataSize, size_t &tlvStart, size_t &tlvSize) const
 Locate the "TLV area" inside a data area. More...
 
bool operator< (const TLVSyntax &other) const
 Comparison operator, typically used to sort containers of TLVSyntax. More...
 
bool set (int start=-1, int size=-1, size_t tagSize=1, size_t lengthSize=1, bool msb=true, Report &report=(*(static_cast< ts::Report * >(ts::CerrReport::Instance()))))
 Set the values of a TLVSyntax object. More...
 
void setAutoLocation ()
 Update the TLV syntax to automatically locate the TLV area.
 

Detailed Description

Representation of a Tag, Length, Value (TVL) syntax.

An instance of this class describe how a part of a data area, typically in the payload of an MPEG section, is structured as a suite of TLV records. The complete suite of all contiguous TLV records is named the "TLV area" inside the larger data area.

A TLV area is described by the following values:

  • The start index in the data area. This is the starting index of the first tag field. A negative value for start means "auto". The best match of a "TLV area" will be found automatically.
  • The size in bytes of the TLV area. A negative value means "auto", up to the last consistent TLV record before the end of the data area.
  • The tag size in bytes. The valid sizes are 1 (default), 2 and 4.
  • The length size in bytes. The valid sizes are 1 (default), 2 and 4.
  • The byte order of the tag and length fields. The default is MSB.

Constructor & Destructor Documentation

◆ TLVSyntax()

ts::TLVSyntax::TLVSyntax ( int  start = -1,
int  size = -1,
size_t  tagSize = 1,
size_t  lengthSize = 1,
bool  msb = true,
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) 
)

Default constructor.

Parameters
[in]startStarting index of the "TLV area" in the "data area". A negative value means "auto".
[in]sizeSize in bytes of the "TLV area". A negative value means "auto".
[in]tagSizeSize in bytes of the tag field. The valid sizes are 1 (default), 2 and 4.
[in]lengthSizeSize in bytes of the length field. The valid sizes are 1 (default), 2 and 4.
[in]msbIf true, the tag and length fields are represented in MSB-first.
[in,out]reportWhere to report errors.

Member Function Documentation

◆ set()

bool ts::TLVSyntax::set ( int  start = -1,
int  size = -1,
size_t  tagSize = 1,
size_t  lengthSize = 1,
bool  msb = true,
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) 
)

Set the values of a TLVSyntax object.

Parameters
[in]startStarting index of the "TLV area" in the "data area". A negative value means "auto".
[in]sizeSize in bytes of the "TLV area". A negative value means "auto".
[in]tagSizeSize in bytes of the tag field. The valid sizes are 1 (default), 2 and 4.
[in]lengthSizeSize in bytes of the length field. The valid sizes are 1 (default), 2 and 4.
[in]msbIf true, the tag and length fields are represented in MSB-first.
[in,out]reportWhere to report errors.
Returns
True on success, false on error (invalid sizes).

◆ getTagSize()

size_t ts::TLVSyntax::getTagSize ( ) const
inline

Get the size in bytes of the Tag field.

Returns
The size in bytes of the Tag field.

◆ getLengthSize()

size_t ts::TLVSyntax::getLengthSize ( ) const
inline

Get the size in bytes of the Length field.

Returns
The size in bytes of the Length field.

◆ fromString()

bool ts::TLVSyntax::fromString ( const UString s,
Report report = (*(static_cast< ts::Report * >(ts::CerrReport::Instance()))) 
)

Set the values of a TLVSyntax object from a string representation.

Typically used to ingest command line parameters.

Parameters
[in]sThe string representation in the form "start,size,tagSize,lengthSize,order". The start and size fields can be set to "auto". The order field shall be either "msb" or lsb". All fields are optional. Missing fields receive the default value as defined in the constructor.
[in,out]reportWhere to report errors.
Returns
True on success, false on error.

◆ getTagAndLength()

size_t ts::TLVSyntax::getTagAndLength ( const uint8_t *  data,
size_t  size,
uint32_t &  tag,
size_t &  length 
) const

Extract a tag and length value from a data area.

Parameters
[in]dataAddress of the TLV record.
[in]sizeTotal size in bytes of the data area after data address.
[out]tagReturned tag value.
[out]lengthReturned length value.
Returns
The size of the tag and length field, ie. the offset after data where the value field starts. Return 0 on error (if the TLV record does not fit).

◆ locateTLV()

bool ts::TLVSyntax::locateTLV ( const uint8_t *  data,
size_t  dataSize,
size_t &  tlvStart,
size_t &  tlvSize 
) const

Locate the "TLV area" inside a data area.

If the start or size are set to "auto", return the best match.

Parameters
[in]dataAddress of the TLV data area.
[in]dataSizeTotal size in bytes of the data area.
[out]tlvStartStarting offset of the "TLV area" after data.
[out]tlvSizeSize in bytes of the "TLV area". Zero if no suitable TLV area was found.
Returns
True if TLV area found, false otherwise.

◆ operator<()

bool ts::TLVSyntax::operator< ( const TLVSyntax other) const
inline

Comparison operator, typically used to sort containers of TLVSyntax.

Parameters
[in]otherOther instance to compare.
Returns
True if this object logically preceeds other.

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