GeoNetworkingCodec.hh 2.57 KB
Newer Older
#ifndef GNCODEC_H
#define GNCODEC_H
garciay's avatar
garciay committed

#include <vector>

garciay's avatar
garciay committed
#include "loggers.hh"
garciay's avatar
garciay committed
class Base_Type;
class TTCN_Typedescriptor_t;
class TTCN_Buffer;

namespace LibItsGeoNetworking__TypesAndValues {
garciay's avatar
garciay committed
  class GeoNetworkingPdu;
  class HeaderTST;
  class ExtendedHeader;
  class DecodedPayload;
};

namespace LibItsSecurity__TypesAndValues {
garciay's avatar
garciay committed
  class SecuredMessage;
garciay's avatar
garciay committed
struct Encoding_Context {
garciay's avatar
garciay committed
  unsigned char next_header;
  unsigned char header_type;
  unsigned int  plLength_position;
  unsigned int  plLength;
garciay's avatar
garciay committed
  Encoding_Context() { next_header = 0xff; header_type = 0xff; plLength_position = -1; plLength = -1; }
garciay's avatar
garciay committed
};
garciay's avatar
garciay committed
//typedef struct Encoding_Context Encoding_Context;
garciay's avatar
garciay committed

struct Decoding_Context {
garciay's avatar
garciay committed
  unsigned char              next_header;
  unsigned char              header_type;
  unsigned char              header_sub_type;
  unsigned int               plLength;
  std::vector<unsigned char> payload;
garciay's avatar
garciay committed
  Decoding_Context() : payload{} { next_header = 0xff; header_type = 0xff; header_sub_type = 0xff; plLength = -1; }
garciay's avatar
garciay committed
};
garciay's avatar
garciay committed
//typedef struct Decoding_Context Decoding_Context;
class GeoNetworkingCodec : public Codec<LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu> {
garciay's avatar
garciay committed
  Encoding_Context _ec;
  Decoding_Context _dc;
  
  int encode_ (const Base_Type& type, const TTCN_Typedescriptor_t& field_descriptor, TTCN_Buffer& encoding_buffer);
  int encode_extendedHeader(const LibItsGeoNetworking__TypesAndValues::ExtendedHeader& u, TTCN_Buffer& encoding_buffer);
  int encode_decodedPayload(const LibItsGeoNetworking__TypesAndValues::DecodedPayload& u, TTCN_Buffer& encoding_buffer);
garciay's avatar
garciay committed
  int decode_ (Base_Type& type, const TTCN_Typedescriptor_t& field_descriptor, TTCN_Buffer& decoding_buffer);
  int decode_headerTST(LibItsGeoNetworking__TypesAndValues::HeaderTST& u, TTCN_Buffer& decoding_buffer);
  int decode_extendedHeader(LibItsGeoNetworking__TypesAndValues::ExtendedHeader& u, TTCN_Buffer& decodin_buffer);
public:
garciay's avatar
garciay committed
  GeoNetworkingCodec() : Codec<LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu>(), _ec(), _dc() { loggers::loggers::log("GeoNetworkingCodec::GeoNetworkingCodec(D) :%d ", _ec.next_header); };
  virtual ~GeoNetworkingCodec() { loggers::loggers::log("GeoNetworkingCodec::~GeoNetworkingCodec"); };
  
  int encode (const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& msg, OCTETSTRING& data);
  int decode (const OCTETSTRING& data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& msg);