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

Factory class for TLV messages. More...

#include <tstlvMessageFactory.h>

Classes

class  Parameter
 Location of one parameter value inside the message block. More...
 

Public Member Functions

 MessageFactory (const ByteBlock &bb, const Protocol &protocol)
 Constructor: Analyze a TLV message in memory.
 
 MessageFactory (const void *addr, size_t size, const Protocol &protocol)
 Constructor: Analyze a TLV message in memory.
 
void buildErrorResponse (MessagePtr &msg) const
 Return the error response for the peer.
 
TAG commandTag () const
 Get the message tag.
 
size_t count (TAG tag) const
 Get actual number of occurences of a parameter.
 
uint16_t errorInformation () const
 Get the "error information" resulting from the analysis of the message.
 
MessagePtr errorResponse () const
 Return the error response for the peer.
 
tlv::Error errorStatus () const
 Get the "error status" resulting from the analysis of the message.
 
MessagePtr factory () const
 Return the fully rebuilt message.
 
void factory (MessagePtr &msg) const
 Return the fully rebuilt message.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
INT get (TAG tag) const
 Get an integer parameter.
 
void get (TAG tag, ByteBlock &param) const
 Get an opaque byte block parameter.
 
void get (TAG tag, Parameter &param) const
 Get the location of a parameter.
 
void get (TAG tag, std::string &param) const
 Get a string parameter.
 
void get (TAG tag, std::vector< bool > &param) const
 Get a boolean parameter.
 
template<typename INT , typename std::enable_if< std::is_integral< INT >::value >::type * = nullptr>
void get (TAG tag, std::vector< INT > &param) const
 Get an integer parameter.
 
void get (TAG tag, std::vector< Parameter > &param) const
 Get the location of all occurences of a parameter.
 
void get (TAG tag, std::vector< std::string > &param) const
 Get a string parameter.
 
void getCompound (TAG tag, MessagePtr &param) const
 Get a compound TLV parameter.
 
template<class MSG >
void getCompound (TAG tag, MSG &param) const
 Get a compound TLV parameter (template version).
 
void getCompound (TAG tag, std::vector< MessagePtr > &param) const
 Get a compound TLV parameter.
 
template<class MSG >
void getCompound (TAG tag, std::vector< MSG > &param) const
 Get a compound TLV parameter (template version).
 
VERSION protocolVersion () const
 Get the protocol version number.
 

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 occurence 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 occurences 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 occurences of a parameter.

Parameters
[in]tagParameter tag to search.
Returns
The actual number of occurences 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 occurences 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 , typename std::enable_if< std::is_integral< INT >::value >::type * >
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 , typename std::enable_if< std::is_integral< INT >::value >::type * >
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: