TSDuck v3.38-3696
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::TLVSyntax Class Reference

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

#include <tsTLVSyntax.h>

Public Member Functions

 TLVSyntax (int start=-1, int size=-1, size_t tagSize=1, size_t lengthSize=1, bool msb=true, Report &report=(ts::CerrReport::Instance()))
 Default constructor.
 
bool fromString (const UString &s, Report &report=(ts::CerrReport::Instance()))
 Set the values of a TLVSyntax object from a string representation.
 
size_t getLengthSize () const
 Get the size in bytes of the Length field.
 
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.
 
size_t getTagSize () const
 Get the size in bytes of the Tag field.
 
bool locateTLV (const uint8_t *data, size_t dataSize, size_t &tlvStart, size_t &tlvSize) const
 Locate the "TLV area" inside a data area.
 
bool operator< (const TLVSyntax &other) const
 Comparison operator, typically used to sort containers of TLVSyntax.
 
bool set (int start=-1, int size=-1, size_t tagSize=1, size_t lengthSize=1, bool msb=true, Report &report=(ts::CerrReport::Instance()))
 Set the values of a TLVSyntax object.
 
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 = (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 = (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 = (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: