Commit 57227b4a authored by Yann Garcia's avatar Yann Garcia
Browse files

Start validation of MEC 028

parent aed8471d
Loading
Loading
Loading
Loading
+0 −47
Original line number Diff line number Diff line
@@ -36,14 +36,6 @@ int json_codec::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTE
    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 if (msg.ischosen(LibHttp__JsonMessageBodyTypes::JsonBody::ALT_assocStaSubscription)) {
    const WlanInformationAPI__TypesAndValues::AssocStaSubscription& assoc_sta_subscription = msg.assocStaSubscription();
    assoc_sta_subscription.encode(WlanInformationAPI__TypesAndValues::AssocStaSubscription_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_staDataRateSubscription)) {
    const WlanInformationAPI__TypesAndValues::StaDataRateSubscription& sta_data_rate_subscription = msg.staDataRateSubscription();
    sta_data_rate_subscription.encode(WlanInformationAPI__TypesAndValues::StaDataRateSubscription_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");
  }
@@ -171,45 +163,6 @@ 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.find("\"AssocStaSubscription\"") != std::string::npos) {
    if (it->second.find("\"subscription\"") != std::string::npos) { // SubscriptionLinkList
      WlanInformationAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
      subscription_link_list.decode(WlanInformationAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.subscriptionLinkList__wlan() = subscription_link_list;
    } else { // AssocStaSubscription
      WlanInformationAPI__TypesAndValues::AssocStaSubscription assoc_sta_subscription;
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
      assoc_sta_subscription.decode(WlanInformationAPI__TypesAndValues::AssocStaSubscription_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.assocStaSubscription() = assoc_sta_subscription;
    }
  } else if (it->second.find("\"StaDataRateSubscription\"") != std::string::npos) {
    WlanInformationAPI__TypesAndValues::StaDataRateSubscription sta_data_rate_subscription;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    sta_data_rate_subscription.decode(WlanInformationAPI__TypesAndValues::StaDataRateSubscription_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.staDataRateSubscription() = sta_data_rate_subscription;
  } else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("subscriptions") != std::string::npos)) { // SubscriptionLinkList
    // decode_str: {"_links":{"self":{"href":"https://try-mec.etsi.org/sbxpb4c4k2/wai/v2/subscriptions"}}}
    WlanInformationAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    subscription_link_list.decode(WlanInformationAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.subscriptionLinkList__wlan() = subscription_link_list;
  } else if ((it->second.find("\"apInfo\"") != std::string::npos) || (it->second.find("\"apId\"") != std::string::npos)) {
    WlanInformationAPI__TypesAndValues::ApInfoList ap_info_list;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    ap_info_list.decode(WlanInformationAPI__TypesAndValues::ApInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.apInfoList() = ap_info_list;

  } else if ((it->second.find("\"staInfo\"") != std::string::npos) || (it->second.find("\"rssi\"") != std::string::npos)) {
    WlanInformationAPI__TypesAndValues::StaInfoList sta_info_list;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    sta_info_list.decode(WlanInformationAPI__TypesAndValues::StaInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.staInfoList() = sta_info_list;
  } else if (it->second.find("\"AssocStaNotification\"") != std::string::npos) {
    WlanInformationAPI__TypesAndValues::AssocStaNotification assoc_sta_notification;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    assoc_sta_notification.decode(WlanInformationAPI__TypesAndValues::AssocStaNotification_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.assocStaNotification() = assoc_sta_notification;
  } 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);
+46 −0
Original line number Diff line number Diff line
/*!
 * \file      json_codec_factory_mec028.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_mec028.hh"

class Record_Type; //! TITAN forward declaration

/*!
 * \class json_codec_factory_mec028
 * \brief  This class provides a factory class to create an json_codec class instance
 */
class json_codec_factory_mec028: public codec_factory {
  static json_codec_factory_mec028 _f; //! Reference to the unique instance of this class
public: //! \publicsection
  /*!
   * \brief Default constructor
   *        Create a new instance of the json_codec_factory_mec028 class
   * \remark The HELD/IP codec identifier is HELD
   */
  json_codec_factory_mec028() {
    // register factory
    codec_stack_builder::register_codec_factory("json_codec_mec028", 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_mec028();
  };
}; // End of class json_codec_factory_mec028
+4 −4
Original line number Diff line number Diff line
@@ -157,14 +157,14 @@ int json_codec_mec011::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBo
      dns_rule.decode(EdgePlatformApplicationEnablementAPI__TypesAndValues::DnsRule_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
      msg.dnsRule() = dns_rule;
    }
  } else if ((it->second.find("\"SerAvailabilityNotificationSubscription\"") != std::string::npos) || (it->second.find("\"rel\"") != std::string::npos)) {
    EdgePlatformApplicationEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription ser_av;
    ser_av.decode(EdgePlatformApplicationEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.serAvailabilityNotificationSubscription() = ser_av;
  } else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("\"subscriptions\"") != std::string::npos)) {
    EdgePlatformApplicationEnablementAPI__TypesAndValues::SubscriptionLinkList sub_link_list;
    sub_link_list.decode(EdgePlatformApplicationEnablementAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.subscriptionLinkList__app__ens() = sub_link_list;
  } else if ((it->second.find("\"SerAvailabilityNotificationSubscription\"") != std::string::npos) && (it->second.find("\"callbackReference\"") != std::string::npos)) {
    EdgePlatformApplicationEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription ser_av;
    ser_av.decode(EdgePlatformApplicationEnablementAPI__TypesAndValues::SerAvailabilityNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
    msg.serAvailabilityNotificationSubscription() = ser_av;
  } else if ((it->second.find("\"AppTerminationNotificationSubscription\"") != std::string::npos) && (it->second.find("\"callbackReference\"") != std::string::npos)) {
    EdgePlatformApplicationEnablementAPI__TypesAndValues::AppTerminationNotificationSubscription app_term;
    app_term.decode(EdgePlatformApplicationEnablementAPI__TypesAndValues::AppTerminationNotificationSubscription_descr_, decoding_buffer, TTCN_EncDec::CT_JSON);
+114 −0
Original line number Diff line number Diff line
#include <stdexcept>
#include <regex>
#include <string>

#include "json_codec_factory_mec028.hh"

#include "loggers.hh"

#include "LibHttp_JsonMessageBodyTypes.hh"

int json_codec_mec028::encode (const LibHttp__JsonMessageBodyTypes::JsonBody& msg, OCTETSTRING& data)
{
  loggers::get_instance().log_msg(">>> json_codec_mec028::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_assocStaSubscription)) {
    const WlanInformationAPI__TypesAndValues::AssocStaSubscription& assoc_sta_subscription = msg.assocStaSubscription();
    assoc_sta_subscription.encode(WlanInformationAPI__TypesAndValues::AssocStaSubscription_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_staDataRateSubscription)) {
    const WlanInformationAPI__TypesAndValues::StaDataRateSubscription& sta_data_rate_subscription = msg.staDataRateSubscription();
    sta_data_rate_subscription.encode(WlanInformationAPI__TypesAndValues::StaDataRateSubscription_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_mec028::encode");
  return 0;
}

int json_codec_mec028::decode (const OCTETSTRING& p_data, LibHttp__JsonMessageBodyTypes::JsonBody& msg, params* p_params)
{
  loggers::get_instance().log_msg(">>> json_codec_mec028::decode: p_data=", p_data);

  // Sanity checks
  params::const_iterator it;
  if (p_params == nullptr) {
    loggers::get_instance().warning("json_codec_mec028::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_mec028::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_mec028::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_mec028::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("\"AssocStaSubscription\"") != std::string::npos) {
    if (it->second.find("\"subscription\"") != std::string::npos) { // SubscriptionLinkList
      WlanInformationAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
      subscription_link_list.decode(WlanInformationAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.subscriptionLinkList__wlan() = subscription_link_list;
    } else { // AssocStaSubscription
      WlanInformationAPI__TypesAndValues::AssocStaSubscription assoc_sta_subscription;
      TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
      assoc_sta_subscription.decode(WlanInformationAPI__TypesAndValues::AssocStaSubscription_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
      msg.assocStaSubscription() = assoc_sta_subscription;
    }
  } else if (it->second.find("\"StaDataRateSubscription\"") != std::string::npos) {
    WlanInformationAPI__TypesAndValues::StaDataRateSubscription sta_data_rate_subscription;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    sta_data_rate_subscription.decode(WlanInformationAPI__TypesAndValues::StaDataRateSubscription_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.staDataRateSubscription() = sta_data_rate_subscription;
  } else if ((it->second.find("\"_links\"") != std::string::npos) && (it->second.find("subscriptions") != std::string::npos)) { // SubscriptionLinkList
    // decode_str: {"_links":{"self":{"href":"https://try-mec.etsi.org/sbxpb4c4k2/wai/v2/subscriptions"}}}
    WlanInformationAPI__TypesAndValues::SubscriptionLinkList subscription_link_list;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    subscription_link_list.decode(WlanInformationAPI__TypesAndValues::SubscriptionLinkList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.subscriptionLinkList__wlan() = subscription_link_list;
  } else if ((it->second.find("\"apInfo\"") != std::string::npos) || (it->second.find("\"apId\"") != std::string::npos)) {
    WlanInformationAPI__TypesAndValues::ApInfoList ap_info_list;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    ap_info_list.decode(WlanInformationAPI__TypesAndValues::ApInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.apInfoList() = ap_info_list;
  } else if ((it->second.find("\"staInfo\"") != std::string::npos) || (it->second.find("\"rssi\"") != std::string::npos)) {
    WlanInformationAPI__TypesAndValues::StaInfoList sta_info_list;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    sta_info_list.decode(WlanInformationAPI__TypesAndValues::StaInfoList_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.staInfoList() = sta_info_list;
  } else if (it->second.find("\"AssocStaNotification\"") != std::string::npos) {
    WlanInformationAPI__TypesAndValues::AssocStaNotification assoc_sta_notification;
    TTCN_Buffer decoding_buffer_(OCTETSTRING(str.length(), (const unsigned char*)str.c_str()));
    assoc_sta_notification.decode(WlanInformationAPI__TypesAndValues::AssocStaNotification_descr_, decoding_buffer_, TTCN_EncDec::CT_JSON);
    msg.assocStaNotification() = assoc_sta_notification;
  } else {
    return json_codec::decode(p_data, msg, p_params);
  }

  loggers::get_instance().log_msg("<<< json_codec_mec028::decode: ", (const Base_Type&)msg);
  return 0;
}

json_codec_factory_mec028 json_codec_factory_mec028::_f;
+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_mec028: public json_codec
{
public:
  explicit json_codec_mec028() : json_codec() { };
  virtual ~json_codec_mec028() { };

  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_mec028
Loading