Loading ccsrc/Protocols/Json/json_codec.cc +5 −0 Original line number Diff line number Diff line Loading @@ -163,6 +163,11 @@ int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); mts_session_info.decode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.mtsSessionInfo() = mts_session_info; } else if ((it->second[0] == '[') && (it->second.find("\"iotPlatformId\"") != std::string::npos)) { IoTAPI__TypesAndValues::IotPlatformInfoList iot_platform_info_list; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); iot_platform_info_list.decode(IoTAPI__TypesAndValues::IotPlatformInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.iotPlatformInfoList() = iot_platform_info_list; } else if (it->second.find("\"detail\"") != std::string::npos) { LibMec__TypesAndValues::ProblemDetails problem_details; problem_details.decode(LibMec__TypesAndValues::ProblemDetails_descr_, decoding_buffer, TTCN_EncDec::CT_JSON); Loading ccsrc/Protocols/Json/json_codec_factory_mec033.hh 0 → 100644 +46 −0 Original line number Diff line number Diff line /*! * \file json_codec_factory_mec033.hh * \brief Header file for ITS JSON/IP protocol codec factory. * \author ETSI STF569 / TTF T027 / TTF T043 * \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_mec033.hh" class Record_Type; //! TITAN forward declaration /*! * \class json_codec_factory_mec033 * \brief This class provides a factory class to create an json_codec class instance */ class json_codec_factory_mec033: public codec_factory { static json_codec_factory_mec033 _f; //! Reference to the unique instance of this class public: //! \publicsection /*! * \brief Default constructor * Create a new instance of the json_codec_factory_mec033 class * \remark The HELD/IP codec identifier is HELD */ json_codec_factory_mec033() { // register factory codec_stack_builder::register_codec_factory("json_codec_mec033", this); }; /*! * \fn codec* 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_mec033(); }; }; // End of class json_codec_factory_mec033 ccsrc/Protocols/Json/json_codec_mec033.cc 0 → 100644 +91 −0 Original line number Diff line number Diff line #include <stdexcept> #include <regex> #include <string> #include "json_codec_factory_mec033.hh" #include "loggers.hh" #include "LibHttp_JsonMessageBodyTypes.hh" int json_codec_mec033::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTETSTRING& data) { loggers::get_instance().log_msg(">>> json_codec_mec033::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_iotPlatformInfo)) { const IoTAPI__TypesAndValues::IotPlatformInfo& iot_platform_info = msg.iotPlatformInfo(); iot_platform_info.encode(IoTAPI__TypesAndValues::IotPlatformInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/; } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_deviceInfo__iot)) { const IoTAPI__TypesAndValues::DeviceInfo& device_info = msg.deviceInfo__iot(); device_info.encode(IoTAPI__TypesAndValues::DeviceInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/; } else { return json_codec::encode(msg, data); } loggers::get_instance().log("<<< json_codec_mec033::encode"); return 0; } int json_codec_mec033::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody& msg, params* p_params) { loggers::get_instance().log_msg(">>> json_codec_mec033::decode: p_data=", p_data); // Sanity checks params::const_iterator it; if (p_params == nullptr) { loggers::get_instance().warning("json_codec_mec033::decode: Failed to access p_params (null pointer)"); return -1; // TODO Use p_data instead of return -1 } else { it = p_params->find("decode_str"); if (it == p_params->cend()) { loggers::get_instance().warning("json_codec_mec033::decode: Failed to access p_params item (decode_str)"); return -1; // TODO Use p_data instead of return -1 } loggers::get_instance().log("json_codec_mec033::decode: it->second='%c' / '%s'", it->second.c_str()[0], it->second.c_str()); } // 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_mec033::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("\"iotPlatformId\"") != std::string::npos) { IoTAPI__TypesAndValues::IotPlatformInfo iot_platform_info; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); iot_platform_info.decode(IoTAPI__TypesAndValues::IotPlatformInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.iotPlatformInfo() = iot_platform_info; } else if ((it->second[0] == '[') && (it->second.find("\"deviceId\"") != std::string::npos)) { IoTAPI__TypesAndValues::DeviceInfoList device_info_list; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); device_info_list.decode(IoTAPI__TypesAndValues::DeviceInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.deviceInfoList__iot() = device_info_list; } else if (it->second.find("\"deviceId\"") != std::string::npos) { IoTAPI__TypesAndValues::DeviceInfo device_info; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); device_info.decode(IoTAPI__TypesAndValues::DeviceInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.deviceInfo__iot() = device_info; } else { return json_codec::decode(p_data, msg, p_params); } loggers::get_instance().log_msg("<<< json_codec_mec033::decode: ", (const Base_Type&)msg); return 0; } json_codec_factory_mec033 json_codec_factory_mec033::_f; ccsrc/Protocols/Json/json_codec_mec033.hh 0 → 100644 +25 −0 Original line number Diff line number Diff line #pragma once #include "codec_gen.hh" #include "params.hh" #include "json_codec.hh" class Base_Type; class TTCN_Typedescriptor_t; class TTCN_Buffer; namespace LibHttp__JsonMessageBodyTypes { class JsonBody; } class json_codec_mec033: public json_codec { public: explicit json_codec_mec033() : json_codec() { }; virtual ~json_codec_mec033() { }; int encode (const LibHttp__JsonMessageBodyTypes::JsonBody&, OCTETSTRING& data); int decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody&, params* p_params = NULL); }; // End of class json_codec_mec033 ccsrc/Protocols/Json/module.mk +1 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ sources := \ json_codec_mec013.cc \ json_codec_mec030.cc \ json_codec_mec028.cc \ json_codec_mec033.cc \ json_codec_mec040.cc \ Loading Loading
ccsrc/Protocols/Json/json_codec.cc +5 −0 Original line number Diff line number Diff line Loading @@ -163,6 +163,11 @@ int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); mts_session_info.decode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.mtsSessionInfo() = mts_session_info; } else if ((it->second[0] == '[') && (it->second.find("\"iotPlatformId\"") != std::string::npos)) { IoTAPI__TypesAndValues::IotPlatformInfoList iot_platform_info_list; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); iot_platform_info_list.decode(IoTAPI__TypesAndValues::IotPlatformInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.iotPlatformInfoList() = iot_platform_info_list; } else if (it->second.find("\"detail\"") != std::string::npos) { LibMec__TypesAndValues::ProblemDetails problem_details; problem_details.decode(LibMec__TypesAndValues::ProblemDetails_descr_, decoding_buffer, TTCN_EncDec::CT_JSON); Loading
ccsrc/Protocols/Json/json_codec_factory_mec033.hh 0 → 100644 +46 −0 Original line number Diff line number Diff line /*! * \file json_codec_factory_mec033.hh * \brief Header file for ITS JSON/IP protocol codec factory. * \author ETSI STF569 / TTF T027 / TTF T043 * \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_mec033.hh" class Record_Type; //! TITAN forward declaration /*! * \class json_codec_factory_mec033 * \brief This class provides a factory class to create an json_codec class instance */ class json_codec_factory_mec033: public codec_factory { static json_codec_factory_mec033 _f; //! Reference to the unique instance of this class public: //! \publicsection /*! * \brief Default constructor * Create a new instance of the json_codec_factory_mec033 class * \remark The HELD/IP codec identifier is HELD */ json_codec_factory_mec033() { // register factory codec_stack_builder::register_codec_factory("json_codec_mec033", this); }; /*! * \fn codec* 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_mec033(); }; }; // End of class json_codec_factory_mec033
ccsrc/Protocols/Json/json_codec_mec033.cc 0 → 100644 +91 −0 Original line number Diff line number Diff line #include <stdexcept> #include <regex> #include <string> #include "json_codec_factory_mec033.hh" #include "loggers.hh" #include "LibHttp_JsonMessageBodyTypes.hh" int json_codec_mec033::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTETSTRING& data) { loggers::get_instance().log_msg(">>> json_codec_mec033::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_iotPlatformInfo)) { const IoTAPI__TypesAndValues::IotPlatformInfo& iot_platform_info = msg.iotPlatformInfo(); iot_platform_info.encode(IoTAPI__TypesAndValues::IotPlatformInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/; } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_deviceInfo__iot)) { const IoTAPI__TypesAndValues::DeviceInfo& device_info = msg.deviceInfo__iot(); device_info.encode(IoTAPI__TypesAndValues::DeviceInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON); data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/; } else { return json_codec::encode(msg, data); } loggers::get_instance().log("<<< json_codec_mec033::encode"); return 0; } int json_codec_mec033::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody& msg, params* p_params) { loggers::get_instance().log_msg(">>> json_codec_mec033::decode: p_data=", p_data); // Sanity checks params::const_iterator it; if (p_params == nullptr) { loggers::get_instance().warning("json_codec_mec033::decode: Failed to access p_params (null pointer)"); return -1; // TODO Use p_data instead of return -1 } else { it = p_params->find("decode_str"); if (it == p_params->cend()) { loggers::get_instance().warning("json_codec_mec033::decode: Failed to access p_params item (decode_str)"); return -1; // TODO Use p_data instead of return -1 } loggers::get_instance().log("json_codec_mec033::decode: it->second='%c' / '%s'", it->second.c_str()[0], it->second.c_str()); } // 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_mec033::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("\"iotPlatformId\"") != std::string::npos) { IoTAPI__TypesAndValues::IotPlatformInfo iot_platform_info; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); iot_platform_info.decode(IoTAPI__TypesAndValues::IotPlatformInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.iotPlatformInfo() = iot_platform_info; } else if ((it->second[0] == '[') && (it->second.find("\"deviceId\"") != std::string::npos)) { IoTAPI__TypesAndValues::DeviceInfoList device_info_list; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); device_info_list.decode(IoTAPI__TypesAndValues::DeviceInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.deviceInfoList__iot() = device_info_list; } else if (it->second.find("\"deviceId\"") != std::string::npos) { IoTAPI__TypesAndValues::DeviceInfo device_info; TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str())); device_info.decode(IoTAPI__TypesAndValues::DeviceInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON); msg.deviceInfo__iot() = device_info; } else { return json_codec::decode(p_data, msg, p_params); } loggers::get_instance().log_msg("<<< json_codec_mec033::decode: ", (const Base_Type&)msg); return 0; } json_codec_factory_mec033 json_codec_factory_mec033::_f;
ccsrc/Protocols/Json/json_codec_mec033.hh 0 → 100644 +25 −0 Original line number Diff line number Diff line #pragma once #include "codec_gen.hh" #include "params.hh" #include "json_codec.hh" class Base_Type; class TTCN_Typedescriptor_t; class TTCN_Buffer; namespace LibHttp__JsonMessageBodyTypes { class JsonBody; } class json_codec_mec033: public json_codec { public: explicit json_codec_mec033() : json_codec() { }; virtual ~json_codec_mec033() { }; int encode (const LibHttp__JsonMessageBodyTypes::JsonBody&, OCTETSTRING& data); int decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody&, params* p_params = NULL); }; // End of class json_codec_mec033
ccsrc/Protocols/Json/module.mk +1 −0 Original line number Diff line number Diff line Loading @@ -4,6 +4,7 @@ sources := \ json_codec_mec013.cc \ json_codec_mec030.cc \ json_codec_mec028.cc \ json_codec_mec033.cc \ json_codec_mec040.cc \ Loading