libcluon  0.0.148
cluon::EnvelopeConverter Class Reference

#include <EnvelopeConverter.hpp>

Public Member Functions

 EnvelopeConverter ()=default
 
int32_t setMessageSpecification (const std::string &ms) noexcept
 
std::string getJSONFromProtoEncodedEnvelope (const std::string &protoEncodedEnvelope) noexcept
 
std::string getJSONFromEnvelope (cluon::data::Envelope &envelope) noexcept
 
std::string getProtoEncodedEnvelopeFromJSONWithoutTimeStamps (const std::string &json, int32_t messageIdentifier, uint32_t senderStamp) noexcept
 
std::string getProtoEncodedEnvelopeFromJSON (const std::string &json, int32_t messageIdentifier, uint32_t senderStamp) noexcept
 

Detailed Description

This class provides various conversion functions to and from Envelope data structures.

Constructor & Destructor Documentation

◆ EnvelopeConverter()

cluon::EnvelopeConverter::EnvelopeConverter ( )
default

Member Function Documentation

◆ getJSONFromEnvelope()

std::string cluon::EnvelopeConverter::getJSONFromEnvelope ( cluon::data::Envelope &  envelope)
noexcept

This method transforms the given Envelope to JSON.

Parameters
envelopeEnvelope.
Returns
JSON representation from given Envelope using the given message specification.

References cluon::GenericMessage::accept(), cluon::GenericMessage::createFrom(), cluon::FromProtoVisitor::decodeFrom(), and retVal.

◆ getJSONFromProtoEncodedEnvelope()

std::string cluon::EnvelopeConverter::getJSONFromProtoEncodedEnvelope ( const std::string &  protoEncodedEnvelope)
noexcept

This method transforms the given Proto-encoded Envelope to JSON. The Proto-encoded envelope might be preceded with a 5-bytes OD4-header (optional).

Parameters
protoEncodedEnvelopeProto-encoded Envelope.
Returns
JSON representation from given Proto-encoded Envelope using the given message specification.

References cluon::FromProtoVisitor::decodeFrom(), cluon::extractEnvelope(), and retVal.

◆ getProtoEncodedEnvelopeFromJSON()

std::string cluon::EnvelopeConverter::getProtoEncodedEnvelopeFromJSON ( const std::string &  json,
int32_t  messageIdentifier,
uint32_t  senderStamp 
)
noexcept

This method transforms a given JSON representation into a Proto-encoded Envelope including the prepended OD4-header and setting cluon::time::now() as sampleTimeStamp.

Parameters
jsonrepresentation according to the given message specification.
messageIdentifierThe given JSON representation shall be interpreted as the specified message.
senderStampto be used in the Envelope.
Returns
Proto-encoded Envelope including OD4-header or empty string.

References cluon::GenericMessage::accept(), cluon::GenericMessage::createFrom(), cluon::FromJSONVisitor::decodeFrom(), cluon::ToProtoVisitor::encodedData(), cluon::time::now(), retVal, and cluon::serializeEnvelope().

◆ getProtoEncodedEnvelopeFromJSONWithoutTimeStamps()

std::string cluon::EnvelopeConverter::getProtoEncodedEnvelopeFromJSONWithoutTimeStamps ( const std::string &  json,
int32_t  messageIdentifier,
uint32_t  senderStamp 
)
noexcept

This method transforms a given JSON representation into a Proto-encoded Envelope including the prepended OD4-header.

Parameters
jsonrepresentation according to the given message specification.
messageIdentifierThe given JSON representation shall be interpreted as the specified message.
senderStampto be used in the Envelope.
Returns
Proto-encoded Envelope including OD4-header or empty string.

◆ setMessageSpecification()

int32_t cluon::EnvelopeConverter::setMessageSpecification ( const std::string &  ms)
noexcept

This method sets the message specification to be used for interpreting a given Proto-encoded Envelope.

Parameters
msMessage specification following the ODVD format.
Returns
-1 in case of invalid message specification; otherwise, number of successfully parsed messages from given message specification.

References mm, cluon::MessageParser::parse(), and retVal.