Loading ccsrc/Protocols/Json/json_codec.cc +87 Changes for ccsrc/Protocols/Json/json_codec.cc: 87 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdexcept> #include <regex> #include <string> #include "json_codec_factory.hh" #include "loggers.hh" #include "LibHttp_JsonMessageBodyTypes.hh" /*int json_codec::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTETSTRING& data) { loggers::get_instance().log_msg(">>> json_codec::encode: ", (const Base_Type&)msg); TTCN_EncDec::clear_error(); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT); TTCN_Buffer encoding_buffer; if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_dequeueRegistrationRequest)) { const LibNg112__DequeueRegistration::DequeueRegistrationRequest& dequeue_registration_request = msg.dequeueRegistrationRequest(); dequeue_registration_request.encode(LibNg112__DequeueRegistration::DequeueRegistrationRequest_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_dequeueRegistrationResponse)) { const LibNg112__DequeueRegistration::DequeueRegistrationResponse& dequeue_registration_response = msg.dequeueRegistrationResponse(); dequeue_registration_response.encode(LibNg112__DequeueRegistration::DequeueRegistrationResponse_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); } else { loggers::get_instance().error("json_codec::encode: Not supported"); } loggers::get_instance().log("<<< json_codec::encode"); return 0; } int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody& msg, params* p_params) { loggers::get_instance().log_msg(">>> json_codec::decode: p_data=", p_data); // Sanity checks params::const_iterator it; if (p_params == nullptr) { loggers::get_instance().warning("json_codec::decode: Failed to access p_params (null pointer)"); return -1; } else { it = p_params->find("decode_str"); if (it == p_params->cend()) { loggers::get_instance().warning("json_codec::decode: Failed to access p_params item (decode_str)"); return -1; } } // Remove data structure name (if present) ... std::string str; if ((it->second[0] != '[') && (it->second[0] != '{')) { int idx_begin = it->second.find(":"); int idx_end = it->second.rfind("}") - 1; // Remove the last '}' str = it->second.substr(idx_begin + 1, idx_end - idx_begin); } else { str = it->second; } // ..and create the decoding buffer TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT); TTCN_EncDec::clear_error(); loggers::get_instance().log("json_codec::decode: decoding_buffer='%c' / '%s'", str[0], str.c_str()); TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); if (it->second.find("\"DequeueRegistrationQueueUri\"") != std::string::npos) { LibNg112__DequeueRegistration::DequeueRegistrationRequest dequeue_registration_request; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); dequeue_registration_request.decode(LibNg112__DequeueRegistration::DequeueRegistrationRequest_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.dequeueRegistrationRequest() = dequeue_registration_request; } else if (it->second.find("\"DequeueRegistrationStatusCode\"") != std::string::npos) { LibNg112__DequeueRegistration::DequeueRegistrationResponse dequeue_registration_response; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); dequeue_registration_response.decode(LibNg112__DequeueRegistration::DequeueRegistrationResponse_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.dequeueRegistrationResponse() = dequeue_registration_response; } else { loggers::get_instance().warning("json_codec::decode: Unsupported variant"); return -1; } loggers::get_instance().log_msg("<<< json_codec::decode: ", (const Base_Type&)msg); return 0; } */ json_codec_factory json_codec_factory::_f; ccsrc/Protocols/Json/json_codec.hh +23 Changes for ccsrc/Protocols/Json/json_codec.hh: 23 added lines, 0 removed lines. Original line number Diff line number Diff line #pragma once #include "codec_gen.hh" #include "params.hh" class Base_Type; class TTCN_Typedescriptor_t; class TTCN_Buffer; namespace LibHttp__JsonMessageBodyTypes { class JsonBody; } class json_codec: public codec_gen <LibHttp__JsonMessageBodyTypes::JsonBody, LibHttp__JsonMessageBodyTypes::JsonBody> { public: explicit json_codec() : codec_gen<LibHttp__JsonMessageBodyTypes::JsonBody, LibHttp__JsonMessageBodyTypes::JsonBody>() { }; virtual ~json_codec() { }; virtual int encode (const LibHttp__JsonMessageBodyTypes::JsonBody&, OCTETSTRING& data) { return -1; }; virtual int decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody&, params* p_params = NULL) { return -1; }; }; // End of class json_codec ccsrc/Protocols/Json/json_codec_factory.hh +46 Changes for ccsrc/Protocols/Json/json_codec_factory.hh: 46 added lines, 0 removed lines. Original line number Diff line number Diff line /*! * \file json_codec_factory.hh * \brief Header file for LOST/IP protocol codec_gen factory. * \author ETSI STF525 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. * \version 0.1 */ #pragma once #include "codec_stack_builder.hh" #include "json_codec.hh" class Record_Type; //! TITAN forward declaration /*! * \class json_codec_factory * \brief This class provides a factory class to create an json_codec class instance */ class json_codec_factory: public codec_factory { static json_codec_factory _f; //! Reference to the unique instance of this class public: //! \publicsection /*! * \brief Default constructor * Create a new instance of the json_codec_factory class * \remark The LOST/IP codec_gen identifier is LOST */ json_codec_factory() { // register factory codec_stack_builder::register_codec_factory("json_codec", this); }; /*! * \fn codec_gen* create_codec(const std::string & type, const std::string & param); * \brief Create the codecs stack based on the provided codecs stack description * \param[in] p_type The provided codecs stack description * \param[in] p_params Optional parameters * \return 0 on success, -1 otherwise * \inline */ inline virtual codec_gen<Record_Type, Record_Type>* create_codec() { return (codec_gen<Record_Type, Record_Type>*)new json_codec(); }; }; // End of class json_codec_factory ccsrc/Protocols/Json/module.mk +3 Changes for ccsrc/Protocols/Json/module.mk: 3 added lines, 0 removed lines. Original line number Diff line number Diff line sources := json_codec.cc includes := . ccsrc/Protocols/Xml/xml_codec.cc +4 Changes for ccsrc/Protocols/Xml/xml_codec.cc: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,10 @@ int xml_codec::encode(const LibHttp__XmlMessageBodyTypes::XmlBody& msg, OCTETSTR const http__www__cise__eu__servicemodel__v1__message::PullResponse& pull_response = msg.pull__response(); loggers::get_instance().log_msg("xml_codec::encode: Process PullResponse: ", (const Base_Type&)pull_response); pull_response.encode(http__www__cise__eu__servicemodel__v1__message::PullResponse_descr_, encoding_buffer, TTCN_EncDec::CT_XER, XER_EXTENDED); } else if (msg.ischosen(LibHttp__XmlMessageBodyTypes::XmlBody::ALT_raw)) { data = char2oct(msg.raw()); loggers::get_instance().log_msg("xml_codec::encode: Process Raw: ", data); return 0; } else { loggers::get_instance().warning("xml_codec::encode: Unsupported variant"); return -1; Loading Loading
ccsrc/Protocols/Json/json_codec.cc +87 Changes for ccsrc/Protocols/Json/json_codec.cc: 87 added lines, 0 removed lines. Original line number Diff line number Diff line #include <stdexcept> #include <regex> #include <string> #include "json_codec_factory.hh" #include "loggers.hh" #include "LibHttp_JsonMessageBodyTypes.hh" /*int json_codec::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTETSTRING& data) { loggers::get_instance().log_msg(">>> json_codec::encode: ", (const Base_Type&)msg); TTCN_EncDec::clear_error(); TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT); TTCN_Buffer encoding_buffer; if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_dequeueRegistrationRequest)) { const LibNg112__DequeueRegistration::DequeueRegistrationRequest& dequeue_registration_request = msg.dequeueRegistrationRequest(); dequeue_registration_request.encode(LibNg112__DequeueRegistration::DequeueRegistrationRequest_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_dequeueRegistrationResponse)) { const LibNg112__DequeueRegistration::DequeueRegistrationResponse& dequeue_registration_response = msg.dequeueRegistrationResponse(); dequeue_registration_response.encode(LibNg112__DequeueRegistration::DequeueRegistrationResponse_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()); } else { loggers::get_instance().error("json_codec::encode: Not supported"); } loggers::get_instance().log("<<< json_codec::encode"); return 0; } int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody& msg, params* p_params) { loggers::get_instance().log_msg(">>> json_codec::decode: p_data=", p_data); // Sanity checks params::const_iterator it; if (p_params == nullptr) { loggers::get_instance().warning("json_codec::decode: Failed to access p_params (null pointer)"); return -1; } else { it = p_params->find("decode_str"); if (it == p_params->cend()) { loggers::get_instance().warning("json_codec::decode: Failed to access p_params item (decode_str)"); return -1; } } // Remove data structure name (if present) ... std::string str; if ((it->second[0] != '[') && (it->second[0] != '{')) { int idx_begin = it->second.find(":"); int idx_end = it->second.rfind("}") - 1; // Remove the last '}' str = it->second.substr(idx_begin + 1, idx_end - idx_begin); } else { str = it->second; } // ..and create the decoding buffer TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT); TTCN_EncDec::clear_error(); loggers::get_instance().log("json_codec::decode: decoding_buffer='%c' / '%s'", str[0], str.c_str()); TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); if (it->second.find("\"DequeueRegistrationQueueUri\"") != std::string::npos) { LibNg112__DequeueRegistration::DequeueRegistrationRequest dequeue_registration_request; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); dequeue_registration_request.decode(LibNg112__DequeueRegistration::DequeueRegistrationRequest_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.dequeueRegistrationRequest() = dequeue_registration_request; } else if (it->second.find("\"DequeueRegistrationStatusCode\"") != std::string::npos) { LibNg112__DequeueRegistration::DequeueRegistrationResponse dequeue_registration_response; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); dequeue_registration_response.decode(LibNg112__DequeueRegistration::DequeueRegistrationResponse_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.dequeueRegistrationResponse() = dequeue_registration_response; } else { loggers::get_instance().warning("json_codec::decode: Unsupported variant"); return -1; } loggers::get_instance().log_msg("<<< json_codec::decode: ", (const Base_Type&)msg); return 0; } */ json_codec_factory json_codec_factory::_f;
ccsrc/Protocols/Json/json_codec.hh +23 Changes for ccsrc/Protocols/Json/json_codec.hh: 23 added lines, 0 removed lines. Original line number Diff line number Diff line #pragma once #include "codec_gen.hh" #include "params.hh" class Base_Type; class TTCN_Typedescriptor_t; class TTCN_Buffer; namespace LibHttp__JsonMessageBodyTypes { class JsonBody; } class json_codec: public codec_gen <LibHttp__JsonMessageBodyTypes::JsonBody, LibHttp__JsonMessageBodyTypes::JsonBody> { public: explicit json_codec() : codec_gen<LibHttp__JsonMessageBodyTypes::JsonBody, LibHttp__JsonMessageBodyTypes::JsonBody>() { }; virtual ~json_codec() { }; virtual int encode (const LibHttp__JsonMessageBodyTypes::JsonBody&, OCTETSTRING& data) { return -1; }; virtual int decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody&, params* p_params = NULL) { return -1; }; }; // End of class json_codec
ccsrc/Protocols/Json/json_codec_factory.hh +46 Changes for ccsrc/Protocols/Json/json_codec_factory.hh: 46 added lines, 0 removed lines. Original line number Diff line number Diff line /*! * \file json_codec_factory.hh * \brief Header file for LOST/IP protocol codec_gen factory. * \author ETSI STF525 * \copyright ETSI Copyright Notification * No part may be reproduced except as authorized by written permission. * The copyright and the foregoing restriction extend to reproduction in all media. * All rights reserved. * \version 0.1 */ #pragma once #include "codec_stack_builder.hh" #include "json_codec.hh" class Record_Type; //! TITAN forward declaration /*! * \class json_codec_factory * \brief This class provides a factory class to create an json_codec class instance */ class json_codec_factory: public codec_factory { static json_codec_factory _f; //! Reference to the unique instance of this class public: //! \publicsection /*! * \brief Default constructor * Create a new instance of the json_codec_factory class * \remark The LOST/IP codec_gen identifier is LOST */ json_codec_factory() { // register factory codec_stack_builder::register_codec_factory("json_codec", this); }; /*! * \fn codec_gen* create_codec(const std::string & type, const std::string & param); * \brief Create the codecs stack based on the provided codecs stack description * \param[in] p_type The provided codecs stack description * \param[in] p_params Optional parameters * \return 0 on success, -1 otherwise * \inline */ inline virtual codec_gen<Record_Type, Record_Type>* create_codec() { return (codec_gen<Record_Type, Record_Type>*)new json_codec(); }; }; // End of class json_codec_factory
ccsrc/Protocols/Json/module.mk +3 Changes for ccsrc/Protocols/Json/module.mk: 3 added lines, 0 removed lines. Original line number Diff line number Diff line sources := json_codec.cc includes := .
ccsrc/Protocols/Xml/xml_codec.cc +4 Changes for ccsrc/Protocols/Xml/xml_codec.cc: 4 added lines, 0 removed lines. Original line number Diff line number Diff line Loading @@ -25,6 +25,10 @@ int xml_codec::encode(const LibHttp__XmlMessageBodyTypes::XmlBody& msg, OCTETSTR const http__www__cise__eu__servicemodel__v1__message::PullResponse& pull_response = msg.pull__response(); loggers::get_instance().log_msg("xml_codec::encode: Process PullResponse: ", (const Base_Type&)pull_response); pull_response.encode(http__www__cise__eu__servicemodel__v1__message::PullResponse_descr_, encoding_buffer, TTCN_EncDec::CT_XER, XER_EXTENDED); } else if (msg.ischosen(LibHttp__XmlMessageBodyTypes::XmlBody::ALT_raw)) { data = char2oct(msg.raw()); loggers::get_instance().log_msg("xml_codec::encode: Process Raw: ", data); return 0; } else { loggers::get_instance().warning("xml_codec::encode: Unsupported variant"); return -1; Loading