Commit c597505c authored by Muhammad Umair Khan's avatar Muhammad Umair Khan
Browse files

validate and bug fixes in MEC015 Traffic Management API

parent 8dc2ab37
Loading
Loading
Loading
Loading
+74 −95
Original line number Original line Diff line number Diff line
@@ -16,31 +16,26 @@ int json_codec::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTE
  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
  TTCN_Buffer encoding_buffer;
  TTCN_Buffer encoding_buffer;


  if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_ueIdentityTagInfo)) {
  if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_ueIdentityTagInfo))
  {
    const UEidentityAPI__TypesAndValues::UeIdentityTagInfo &ue_identity_tag_info = msg.ueIdentityTagInfo();
    const UEidentityAPI__TypesAndValues::UeIdentityTagInfo &ue_identity_tag_info = msg.ueIdentityTagInfo();
    ue_identity_tag_info.encode(UEidentityAPI__TypesAndValues::UeIdentityTagInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    ue_identity_tag_info.encode(UEidentityAPI__TypesAndValues::UeIdentityTagInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
    data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data());
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_cellChangeSubscription)) {
  }
  else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_cellChangeSubscription))
  {
    const RnisAPI__TypesAndValues::CellChangeSubscription &cell_change_subscription = msg.cellChangeSubscription();
    const RnisAPI__TypesAndValues::CellChangeSubscription &cell_change_subscription = msg.cellChangeSubscription();
    cell_change_subscription.encode(RnisAPI__TypesAndValues::CellChangeSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    cell_change_subscription.encode(RnisAPI__TypesAndValues::CellChangeSubscription_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = /*char2oct(CHARSTRING("{\"CellChangeSubscription\": ")) + */ OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) /* + char2oct(CHARSTRING("}"))*/;
    data = /*char2oct(CHARSTRING("{\"CellChangeSubscription\": ")) + */ OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) /* + char2oct(CHARSTRING("}"))*/;
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_appContext)) {
  }
  else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_appContext))
  {
    const UEAppInterfaceAPI__TypesAndValues::AppContext &app_context = msg.appContext();
    const UEAppInterfaceAPI__TypesAndValues::AppContext &app_context = msg.appContext();
    app_context.encode(UEAppInterfaceAPI__TypesAndValues::AppContext_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    app_context.encode(UEAppInterfaceAPI__TypesAndValues::AppContext_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = char2oct(CHARSTRING("{\"AppContext\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
    data = char2oct(CHARSTRING("{\"AppContext\": ")) + OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data()) + char2oct(CHARSTRING("}"));
  } else if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_bwInfo)) {
  }
    const TrafficManagementAPI__TypesAndValues::BwInfo& bw_info = msg.bwInfo();
  else
    bw_info.encode(TrafficManagementAPI__TypesAndValues::BwInfo_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::ATL_bwchgeventsubscription)) {
    const TrafficManagementAPI__TypesAndValues::BwChgEventSubscription& bw_chg_event_subscription = msg.bwInfo();
    bw_info.encode(TrafficManagementAPI__TypesAndValues::BwChgEventSubscription_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_mtsSessionInfo)) {
    const TrafficManagementAPI__TypesAndValues::MtsSessionInfo& mts_session_info = msg.mtsSessionInfo();
    mts_session_info.encode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_descr_, encoding_buffer, TTCN_EncDec::CT_JSON);
    data = OCTETSTRING(encoding_buffer.get_len(), encoding_buffer.get_data())/* + char2oct(CHARSTRING("}"))*/;
  } else {
    loggers::get_instance().error("json_codec::encode: Not supported");
    loggers::get_instance().error("json_codec::encode: Not supported");
  }
  }


@@ -54,12 +49,16 @@ int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes


  // Sanity checks
  // Sanity checks
  params::const_iterator it;
  params::const_iterator it;
  if (p_params == nullptr) {
  if (p_params == nullptr)
  {
    loggers::get_instance().warning("json_codec::decode: Failed to access p_params (null pointer)");
    loggers::get_instance().warning("json_codec::decode: Failed to access p_params (null pointer)");
    return -1; // TODO Use p_data instead of return -1
    return -1; // TODO Use p_data instead of return -1
  } else {
  }
  else
  {
    it = p_params->find("decode_str");
    it = p_params->find("decode_str");
    if (it == p_params->cend()) {
    if (it == p_params->cend())
    {
      loggers::get_instance().warning("json_codec::decode: Failed to access p_params item (decode_str)");
      loggers::get_instance().warning("json_codec::decode: Failed to access p_params item (decode_str)");
      return -1; // TODO Use p_data instead of return -1
      return -1; // TODO Use p_data instead of return -1
    }
    }
@@ -68,11 +67,14 @@ int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes


  // Remove data structure name (if present) ...
  // Remove data structure name (if present) ...
  std::string str;
  std::string str;
  if ((it->second[0] != '[') && (it->second[0] != '{')) {
  if ((it->second[0] != '[') && (it->second[0] != '{'))
  {
    int idx_begin = it->second.find(":");
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    int idx_end = it->second.rfind("}") - 1; // Remove the last '}'
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
  } else {
  }
  else
  {
    str = it->second;
    str = it->second;
  }
  }
  // ..and create the decoding buffer
  // ..and create the decoding buffer
@@ -81,111 +83,88 @@ int json_codec::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes
  loggers::get_instance().log("json_codec::decode: decoding_buffer='%c' / '%s'", str[0], str.c_str());
  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()));
  TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));


  if (it->second.find("\"ueIdentityTagInfo\"") != std::string::npos) {
  if (it->second.find("\"ueIdentityTagInfo\"") != std::string::npos)
  {
    UEidentityAPI__TypesAndValues::UeIdentityTagInfo ue_identity_tag_info;
    UEidentityAPI__TypesAndValues::UeIdentityTagInfo ue_identity_tag_info;
    ue_identity_tag_info.decode(UEidentityAPI__TypesAndValues::UeIdentityTagInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    ue_identity_tag_info.decode(UEidentityAPI__TypesAndValues::UeIdentityTagInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.ueIdentityTagInfo() = ue_identity_tag_info;
    msg.ueIdentityTagInfo() = ue_identity_tag_info;
  } else if (it->second.find("\"CellChangeSubscription\"") != std::string::npos) {
  }
  else if (it->second.find("\"CellChangeSubscription\"") != std::string::npos)
  {
    RnisAPI__TypesAndValues::CellChangeSubscription cell_change_subscription;
    RnisAPI__TypesAndValues::CellChangeSubscription cell_change_subscription;
    cell_change_subscription.decode(RnisAPI__TypesAndValues::CellChangeSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    cell_change_subscription.decode(RnisAPI__TypesAndValues::CellChangeSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.cellChangeSubscription() = cell_change_subscription;
    msg.cellChangeSubscription() = cell_change_subscription;
    // TODO Continue with other ChangeSubscription
    // TODO Continue with other ChangeSubscription
  } else if (it->second.find("\"cellInfo\"") != std::string::npos) {
  }
  else if (it->second.find("\"cellInfo\"") != std::string::npos)
  {
    RnisAPI__TypesAndValues::L2Meas l2_meas;
    RnisAPI__TypesAndValues::L2Meas l2_meas;
    l2_meas.decode(RnisAPI__TypesAndValues::L2Meas_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    l2_meas.decode(RnisAPI__TypesAndValues::L2Meas_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.l2Meas() = l2_meas;
    msg.l2Meas() = l2_meas;
  } else if ((it->second.find("\"appInstanceId\"") != std::string::npos) && (it->second.find("\"requestId\"") != std::string::npos)) {
  }
  else if ((it->second.find("\"appInstanceId\"") != std::string::npos) && (it->second.find("\"requestId\"") != std::string::npos))
  {
    RnisAPI__TypesAndValues::RabInfo rab_info;
    RnisAPI__TypesAndValues::RabInfo rab_info;
    rab_info.decode(RnisAPI__TypesAndValues::RabInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    rab_info.decode(RnisAPI__TypesAndValues::RabInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.rabInfo() = rab_info;
    msg.rabInfo() = rab_info;
  } else if (it->second.find("\"S1BearerInfo\"") != std::string::npos) {
  }
  else if (it->second.find("\"S1BearerInfo\"") != std::string::npos)
  {
    RnisAPI__TypesAndValues::S1BearerInfo s1_nearer_info;
    RnisAPI__TypesAndValues::S1BearerInfo s1_nearer_info;
    s1_nearer_info.decode(RnisAPI__TypesAndValues::S1BearerInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    s1_nearer_info.decode(RnisAPI__TypesAndValues::S1BearerInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.s1BearerInfo() = s1_nearer_info;
    msg.s1BearerInfo() = s1_nearer_info;
  } else if ((it->second.find("\"appInstanceId\"") != std::string::npos) && (it->second.find("\"plmn\"") != std::string::npos)) {
  }
  else if ((it->second.find("\"appInstanceId\"") != std::string::npos) && (it->second.find("\"plmn\"") != std::string::npos))
  {
    RnisAPI__TypesAndValues::PlmnInfos plmn_infos;
    RnisAPI__TypesAndValues::PlmnInfos plmn_infos;
    plmn_infos.decode(RnisAPI__TypesAndValues::PlmnInfos_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    plmn_infos.decode(RnisAPI__TypesAndValues::PlmnInfos_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.plmnInfos() = plmn_infos;
    msg.plmnInfos() = plmn_infos;
  } else if (it->second.find("\"RabEstSubscription\"") != std::string::npos) {
  }
  else if (it->second.find("\"RabEstSubscription\"") != std::string::npos)
  {
    RnisAPI__TypesAndValues::RabEstSubscription rab_est_subscription;
    RnisAPI__TypesAndValues::RabEstSubscription rab_est_subscription;
    rab_est_subscription.decode(RnisAPI__TypesAndValues::RabEstSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    rab_est_subscription.decode(RnisAPI__TypesAndValues::RabEstSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.rabEstSubscription() = rab_est_subscription;
    msg.rabEstSubscription() = rab_est_subscription;
  } else if (it->second.find("\"RabModSubscription\"") != std::string::npos) {
  }
  else if (it->second.find("\"RabModSubscription\"") != std::string::npos)
  {
    RnisAPI__TypesAndValues::RabModSubscription rab_mod_subscription;
    RnisAPI__TypesAndValues::RabModSubscription rab_mod_subscription;
    rab_mod_subscription.decode(RnisAPI__TypesAndValues::RabModSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    rab_mod_subscription.decode(RnisAPI__TypesAndValues::RabModSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.rabModSubscription() = rab_mod_subscription;
    msg.rabModSubscription() = rab_mod_subscription;
  } else if (it->second.find("\"RabRelSubscription\"") != std::string::npos) {
  }
  else if (it->second.find("\"RabRelSubscription\"") != std::string::npos)
  {
    RnisAPI__TypesAndValues::RabRelSubscription rab_rel_subscription;
    RnisAPI__TypesAndValues::RabRelSubscription rab_rel_subscription;
    rab_rel_subscription.decode(RnisAPI__TypesAndValues::RabRelSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    rab_rel_subscription.decode(RnisAPI__TypesAndValues::RabRelSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.rabRelSubscription() = rab_rel_subscription;
    msg.rabRelSubscription() = rab_rel_subscription;
  } else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("subscriptions\"") != std::string::npos)) { // SubscriptionLinkList
  }
  else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("subscriptions\"") != std::string::npos))
  { // SubscriptionLinkList
    // FIXME Conflict with MEC-028 SubscriptionLinkList data type
    // FIXME Conflict with MEC-028 SubscriptionLinkList data type
    RnisAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    RnisAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    subscription_link_list.decode(RnisAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    subscription_link_list.decode(RnisAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.subscriptionLinkList() = subscription_link_list;
    msg.subscriptionLinkList() = subscription_link_list;
  } else if (it->second.find("\"associateDevAppId\"") != std::string::npos) {
  }
  else if (it->second.find("\"associateDevAppId\"") != std::string::npos)
  {
    UEAppInterfaceAPI__TypesAndValues::AppContext appContext;
    UEAppInterfaceAPI__TypesAndValues::AppContext appContext;
    appContext.decode(UEAppInterfaceAPI__TypesAndValues::AppContext_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    appContext.decode(UEAppInterfaceAPI__TypesAndValues::AppContext_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.appContext() = appContext;
    msg.appContext() = appContext;
  } else if (it->second.find("\"appInfo\"") != std::string::npos) {
  }
  else if (it->second.find("\"appInfo\"") != std::string::npos)
  {
    UEAppInterfaceAPI__TypesAndValues::AppInfo appInfo;
    UEAppInterfaceAPI__TypesAndValues::AppInfo appInfo;
    appInfo.decode(UEAppInterfaceAPI__TypesAndValues::AppInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    appInfo.decode(UEAppInterfaceAPI__TypesAndValues::AppInfo_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.appInfo() = appInfo;
    msg.appInfo() = appInfo;
  } else if ((it->second.find("\"bwInfo\"") != std::string::npos) || (it->second.find("\"fixedBWPriority\"") != std::string::npos)) {
  }
    // Need to change some enumerated string not supported by TTCN-3 language
  else if (it->second.find("\"detail\"") != std::string::npos)
    while (true) {
  {
      if (str.find("\"00\"") != std::string::npos) {
        str = regex_replace(str, regex("\"00\""), "\"Downlink\"");
      } else if (str.find("\"01\"") != std::string::npos) {
        str = regex_replace(str, regex("\"01\""), "\"Uplink\"");
      } else if (str.find("\"10\"") != std::string::npos) {
        str = regex_replace(str, regex("\"10\""), "\"Symmetrical\"");
      } else {
        loggers::get_instance().log("json_codec::decode: BwInfo in break");
        break;
      }
    } // End of 'while' loop
    loggers::get_instance().log("json_codec::decode: BwInfo after converting enum: %s", str.c_str());
    if (it->second[0] == '[') { // BwInfoList
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
      TrafficManagementAPI__TypesAndValues::BwInfoList bw_info_list;
      bw_info_list.decode(TrafficManagementAPI__TypesAndValues::BwInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.bwInfoList() = bw_info_list;
    } else { // BwInfo
      TrafficManagementAPI__TypesAndValues::BwInfo bw_info;
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
      bw_info.decode(TrafficManagementAPI__TypesAndValues::BwInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.bwInfo() = bw_info;
    }
  } else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("subscriptions\"") != std::string::npos)) { // SubscriptionLinkList
    TrafficManagementAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    subscription_link_list.decode(TrafficManagementAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.subscriptionLinkList() = subscription_link_list;
  } else if ((it->second.find("\"bwchgeventsubscription\"") != std::string::npos) {
    TrafficManagementAPI__TypesAndValues::BwChgEventSubscription bw_chg_event_subscription;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    bw_chg_event_subscription.decode(TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.bwchgeventsubscription() = bw_chg_event_subscription;
  } else if ((it->second.find("\"mtsCapabilityInfo\"") != std::string::npos) || (it->second.find("\"mtsAccessInfo\"") != std::string::npos)) {
    TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo mts_cap_info;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    mts_cap_info.decode(TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.mtsCapabilityInfo() = mts_cap_info;
  } else if ((it->second.find("\"mtsSessionInfo\"") != std::string::npos) || (it->second.find("\"mtsMode\"") != std::string::npos)) {
    TrafficManagementAPI__TypesAndValues::MtsSessionInfo mts_session_info;
    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;
    LibMec__TypesAndValues::ProblemDetails problem_details;
    problem_details.decode(LibMec__TypesAndValues::ProblemDetails_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    problem_details.decode(LibMec__TypesAndValues::ProblemDetails_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.problemDetails() = problem_details;
    msg.problemDetails() = problem_details;
  } else {
  }
  else
  {
    loggers::get_instance().warning("json_codec::decode: Unsupported variant");
    loggers::get_instance().warning("json_codec::decode: Unsupported variant");
    return -1;
    return -1;
  }
  }
+46 −0
Original line number Original line Diff line number Diff line
/*!
 * \file      json_codec_factory_mec015.hh
 * \brief     Header file for ITS JSON/IP protocol codec factory.
 * \author    ETSI STF569 / TTF T027
 * \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_mec015.hh"

class Record_Type; //! TITAN forward declaration

/*!
 * \class json_codec_factory_mec015
 * \brief  This class provides a factory class to create a json_codec class instance
 */
class json_codec_factory_mec015: public codec_factory {
  static json_codec_factory_mec015 _f; //! Reference to the unique instance of this class
public: //! \publicsection
  /*!
   * \brief Default constructor
   *        Create a new instance of the json_codec_factory_mec015 class
   * \remark The MEC015 codec identifier is json_codec_mec015
   */
  json_codec_factory_mec015() {
    // register factory
    codec_stack_builder::register_codec_factory("json_codec_mec015", 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_mec015();
  };
}; // End of class json_codec_factory_mec015
+154 −0
Original line number Original line Diff line number Diff line
#include <stdexcept>
#include <regex>
#include <string>

#include "json_codec_factory_mec015.hh"
#include "loggers.hh"
#include "LibHttp_JsonMessageBodyTypes.hh"


int json_codec_mec015::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_bwInfo))
  {
    const TrafficManagementAPI__TypesAndValues::BwInfo &bw_info = msg.bwInfo();
    bw_info.encode(TrafficManagementAPI__TypesAndValues::BwInfo_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_bwchgeventsubscription))
  {
    const TrafficManagementAPI__TypesAndValues::BwChgEventSubscription &bw_chg_event_subscription = msg.bwchgeventsubscription();
    bw_chg_event_subscription.encode(TrafficManagementAPI__TypesAndValues::BwChgEventSubscription_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_mtsSessionInfo))
  {
    const TrafficManagementAPI__TypesAndValues::MtsSessionInfo &mts_session_info = msg.mtsSessionInfo();
    mts_session_info.encode(TrafficManagementAPI__TypesAndValues::MtsSessionInfo_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_mec015::decode(const OCTETSTRING &p_data, LibHttp__JsonMessageBodyTypes::JsonBody &msg, params *p_params)
{
  loggers::get_instance().log_msg(">>> json_codec::decode: p_data=", p_data);

  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;
    }
  }

  std::string str;
  if ((it->second[0] != '[') && (it->second[0] != '{'))
  {
    int idx_begin = it->second.find(":");
    int idx_end = it->second.rfind("}") - 1;
    str = it->second.substr(idx_begin + 1, idx_end - idx_begin);
  }
  else
  {
    str = it->second;
  }

  TTCN_EncDec::set_error_behavior(TTCN_EncDec::ET_ALL, TTCN_EncDec::EB_DEFAULT);
  TTCN_EncDec::clear_error();
  TTCN_Buffer decoding_buffer(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));

  if ((it->second.find("\"bwInfo\"") != std::string::npos) || (it->second.find("\"fixedBWPriority\"") != std::string::npos))
  {
    while (true)
    {
      if (str.find("\"00\"") != std::string::npos)
        str = regex_replace(str, regex("\"00\""), "\"Downlink\"");
      else if (str.find("\"01\"") != std::string::npos)
        str = regex_replace(str, regex("\"01\""), "\"Uplink\"");
      else if (str.find("\"10\"") != std::string::npos)
        str = regex_replace(str, regex("\"10\""), "\"Symmetrical\"");
      else
        break;
    }

    if (it->second[0] == '[')
    {
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
      TrafficManagementAPI__TypesAndValues::BwInfoList bw_info_list;
      bw_info_list.decode(TrafficManagementAPI__TypesAndValues::BwInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.bwInfoList() = bw_info_list;
    }
    else
    {
      TrafficManagementAPI__TypesAndValues::BwInfo bw_info;
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
      bw_info.decode(TrafficManagementAPI__TypesAndValues::BwInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.bwInfo() = bw_info;
    }
  }
  else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("subscriptions\"") != std::string::npos))
  {
    TrafficManagementAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    subscription_link_list.decode(TrafficManagementAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.subscriptionLinkList__bw() = subscription_link_list;
  }
  else if ((it->second.find("\"BwChgEventSubscription\"") != std::string::npos))
  {
    TrafficManagementAPI__TypesAndValues::BwChgEventSubscription bw_chg_event_subscription;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
    bw_chg_event_subscription.decode(TrafficManagementAPI__TypesAndValues::BwChgEventSubscription_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.bwchgeventsubscription() = bw_chg_event_subscription;
  }
  else if ((it->second.find("\"notificationType\"") != std::string::npos))
  {
    TrafficManagementAPI__TypesAndValues::BwChgEventNotification bw_chg_event_notification;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
    bw_chg_event_notification.decode(TrafficManagementAPI__TypesAndValues::BwChgEventNotification_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.bwChgEventNotification() = bw_chg_event_notification;
  }
  else if ((it->second.find("\"mtsCapabilityInfo\"") != std::string::npos) || (it->second.find("\"mtsAccessInfo\"") != std::string::npos))
  {
    TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo mts_cap_info;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char *)str.c_str()));
    mts_cap_info.decode(TrafficManagementAPI__TypesAndValues::MtsCapabilityInfo_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.mtsCapabilityInfo() = mts_cap_info;
  }
  else if ((it->second.find("\"mtsSessionInfo\"") != std::string::npos) || (it->second.find("\"mtsMode\"") != std::string::npos))
  {
    TrafficManagementAPI__TypesAndValues::MtsSessionInfo mts_session_info;
    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
  {
    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_mec015 json_codec_factory_mec015::_f;
+24 −0
Original line number Original line 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_mec015: public json_codec
{
public:
  explicit json_codec_mec015() : json_codec() { };
  virtual ~json_codec_mec015() { };

  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_mec015
+1 −2
Original line number Original line Diff line number Diff line
@@ -2,11 +2,10 @@ sources := \
  json_codec.cc        \
  json_codec.cc        \
  json_codec_mec011.cc \
  json_codec_mec011.cc \
  json_codec_mec013.cc \
  json_codec_mec013.cc \
  json_codec_mec015.cc \
  json_codec_mec030.cc \
  json_codec_mec030.cc \
  json_codec_mec028.cc \
  json_codec_mec028.cc \
  json_codec_mec033.cc \
  json_codec_mec040.cc \
  json_codec_mec040.cc \
  json_codec_mec046.cc \




includes := .
includes := .
Loading