TSDuck v3.46-4967
MPEG Transport Stream Toolkit
Loading...
Searching...
No Matches
ts::tlv::MessageFactory Class Reference

#include <tstlvMessageFactory.h>

Classes

class  Parameter

Public Member Functions

 MessageFactory (const ByteBlock &bb, const Protocol &protocol)
 MessageFactory (const void *addr, size_t size, const Protocol &protocol)
void buildErrorResponse (MessagePtr &msg) const
TAG commandTag () const
size_t count (TAG tag) const
uint16_t errorInformation () const
MessagePtr errorResponse () const
tlv::Error errorStatus () const
MessagePtr factory () const
void factory (MessagePtr &msg) const
template<typename INT>
requires std::integral<INT>
INT get (TAG tag) const
void get (TAG tag, ByteBlock &param) const
void get (TAG tag, Parameter &param) const
void get (TAG tag, std::string &param) const
void get (TAG tag, std::vector< bool > &param) const
template<typename INT>
requires std::integral<INT>
void get (TAG tag, std::vector< INT > &param) const
void get (TAG tag, std::vector< Parameter > &param) const
void get (TAG tag, std::vector< std::string > &param) const
void getCompound (TAG tag, MessagePtr &param) const
template<class MSG>
void getCompound (TAG tag, MSG &param) const
void getCompound (TAG tag, std::vector< MessagePtr > &param) const
template<class MSG>
void getCompound (TAG tag, std::vector< MSG > &param) const
VERSION protocolVersion () const

Detailed Description

Factory class for TLV messages

The following methods should be used by the application to deserialize messages:

The following types and methods should be used by the constructors of the ts::tlv::Message subclasses.

The get() and getCompound() methods retrieve the value of parameters. For each parameter type, two versions are available.

  • The first version returns the first occurrence of a parameter and is typically used when the cardinality of a parameter is 1 or 0 to 1. In the later case, the message deserialization routine should first check the availability of the parameter using count().
  • The second version returns all occurrences of the parameter in a vector.

An exception is thrown when the parameter is not present (first version) or when the actual size of the parameter does not match the expected size of the type. In both cases, this should not happen in properly written message classes since the validity of the parameters were checked by the constructor of the MessageFactory.

Constructor & Destructor Documentation

◆ MessageFactory() [1/2]

ts::tlv::MessageFactory::MessageFactory ( const void * addr,
size_t size,
const Protocol & protocol )

Constructor: Analyze a TLV message in memory.

Parameters
[in]addrAddress of a binary TLV message.
[in]sizeSize in bytes of the message.
[in]protocolThe message is validated according to this protocol.

◆ MessageFactory() [2/2]

ts::tlv::MessageFactory::MessageFactory ( const ByteBlock & bb,
const Protocol & protocol )

Constructor: Analyze a TLV message in memory.

Parameters
[in]bbBinary TLV message.
[in]protocolThe message is validated according to this protocol.

Member Function Documentation

◆ errorStatus()

tlv::Error ts::tlv::MessageFactory::errorStatus ( ) const
inline

Get the "error status" resulting from the analysis of the message.

Returns
The error status. If not OK, there is no valid message.

◆ errorInformation()

uint16_t ts::tlv::MessageFactory::errorInformation ( ) const
inline

Get the "error information" resulting from the analysis of the message.

Returns
The error information.

◆ commandTag()

TAG ts::tlv::MessageFactory::commandTag ( ) const
inline

Get the message tag.

Returns
The message tag.

◆ protocolVersion()

VERSION ts::tlv::MessageFactory::protocolVersion ( ) const
inline

Get the protocol version number.

Returns
The protocol version number.

◆ factory() [1/2]

void ts::tlv::MessageFactory::factory ( MessagePtr & msg) const

Return the fully rebuilt message. Valid only when errorStatus() == OK.

Parameters
[out]msgSafe pointer to the rebuilt message. Set a null pointer on error.

◆ factory() [2/2]

MessagePtr ts::tlv::MessageFactory::factory ( ) const

Return the fully rebuilt message. Valid only when errorStatus() == OK.

Returns
Safe pointer to the rebuilt message or null pointer on error.

◆ buildErrorResponse()

void ts::tlv::MessageFactory::buildErrorResponse ( MessagePtr & msg) const

Return the error response for the peer. Valid only when errorStatus() != OK.

Parameters
[out]msgSafe pointer to the error response message. Set a null pointer without error.

◆ errorResponse()

MessagePtr ts::tlv::MessageFactory::errorResponse ( ) const

Return the error response for the peer. Valid only when errorStatus() != OK.

Returns
Safe pointer to the error response message or null pointer without error.

◆ count()

size_t ts::tlv::MessageFactory::count ( TAG tag) const
inline

Get actual number of occurrences of a parameter.

Parameters
[in]tagParameter tag to search.
Returns
The actual number of occurrences of a parameter.

◆ get() [1/8]

void ts::tlv::MessageFactory::get ( TAG tag,
Parameter & param ) const

Get the location of a parameter. Address and size point into the original message buffer, use with care!

Parameters
[in]tagParameter tag to search.
[out]paramDescription of the parameter value.

◆ get() [2/8]

void ts::tlv::MessageFactory::get ( TAG tag,
std::vector< Parameter > & param ) const

Get the location of all occurrences of a parameter. Address and size point into the original message buffer, use with care!

Parameters
[in]tagParameter tag to search.
[out]paramVector of descriptions of the parameter values.

◆ get() [3/8]

template<typename INT>
requires std::integral<INT>
INT ts::tlv::MessageFactory::get ( TAG tag) const

Get an integer parameter.

Template Parameters
INTInteger type for the value. The size of INT must match the parameter size.
Parameters
[in]tagParameter tag to search.
Returns
The parameter value.

◆ get() [4/8]

template<typename INT>
requires std::integral<INT>
void ts::tlv::MessageFactory::get ( TAG tag,
std::vector< INT > & param ) const

Get an integer parameter.

Template Parameters
INTInteger type for the value. The size of INT must match the parameter size.
Parameters
[in]tagParameter tag to search.
[out]paramAll parameter values.

◆ get() [5/8]

void ts::tlv::MessageFactory::get ( TAG tag,
std::vector< bool > & param ) const

Get a boolean parameter. This method returns a vector of booleans. For one single boolean value, use the template version.

Parameters
[in]tagParameter tag to search.
[out]paramAll parameter values.

◆ get() [6/8]

void ts::tlv::MessageFactory::get ( TAG tag,
std::string & param ) const
inline

Get a string parameter.

Parameters
[in]tagParameter tag to search.
[out]paramParameter value.

◆ get() [7/8]

void ts::tlv::MessageFactory::get ( TAG tag,
std::vector< std::string > & param ) const

Get a string parameter.

Parameters
[in]tagParameter tag to search.
[out]paramAll parameter values.

◆ get() [8/8]

void ts::tlv::MessageFactory::get ( TAG tag,
ByteBlock & param ) const
inline

Get an opaque byte block parameter.

Parameters
[in]tagParameter tag to search.
[out]paramParameter value.

◆ getCompound() [1/4]

void ts::tlv::MessageFactory::getCompound ( TAG tag,
MessagePtr & param ) const

Get a compound TLV parameter.

Parameters
[in]tagParameter tag to search.
[out]paramSafe pointer to the parameter value.

◆ getCompound() [2/4]

void ts::tlv::MessageFactory::getCompound ( TAG tag,
std::vector< MessagePtr > & param ) const

Get a compound TLV parameter.

Parameters
[in]tagParameter tag to search.
[out]paramVector of safe pointers to all parameter values.

◆ getCompound() [3/4]

template<class MSG>
void ts::tlv::MessageFactory::getCompound ( TAG tag,
MSG & param ) const

Get a compound TLV parameter (template version).

Template Parameters
MSGExpected class of parameter value, a subclass of ts::tlv::Message.
Parameters
[in]tagParameter tag to search.
[out]paramParameter value.

◆ getCompound() [4/4]

template<class MSG>
void ts::tlv::MessageFactory::getCompound ( TAG tag,
std::vector< MSG > & param ) const

Get a compound TLV parameter (template version).

Template Parameters
MSGExpected class of parameter value, a subclass of ts::tlv::Message.
Parameters
[in]tagParameter tag to search.
[out]paramVector of all parameter values.

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