GeoNetworkingCodec.hh 2.11 KB
Newer Older
garciay's avatar
garciay committed
1
2
#ifndef GNCODEC_H
#define GNCODEC_H
garciay's avatar
garciay committed
3
4
5

#include <vector>

6
#include "Codec.hh"
garciay's avatar
garciay committed
7

garciay's avatar
garciay committed
8
9
10
11
12
13
class Base_Type;
class OCTETSTRING;
class TTCN_Typedescriptor_t;
class TTCN_Buffer;


filatov's avatar
filatov committed
14
namespace LibItsGeoNetworking__TypesAndValues {
garciay's avatar
garciay committed
15
16
17
    class GeoNetworkingPdu;
    class ExtendedHeader;
    class DecodedPayload;
filatov's avatar
filatov committed
18
19
}

garciay's avatar
garciay committed
20
21
struct Encoding_Context {
    unsigned char next_header; // FIXME Useless?
22
    unsigned char header_type; // FIXME Useless?
garciay's avatar
garciay committed
23
24
    unsigned int  plLength_position;
    unsigned int  plLength;
garciay's avatar
garciay committed
25

26
    Encoding_Context() { next_header = 0xff; header_type = 0xff; plLength_position = -1; plLength = -1; }
garciay's avatar
garciay committed
27
28
29
};

struct Decoding_Context {
garciay's avatar
garciay committed
30
    unsigned char              next_header; // FIXME Useless?
31
32
    unsigned char              header_type; // FIXME Useless?
    unsigned char              header_sub_type; // FIXME Useless?
garciay's avatar
garciay committed
33
34
    unsigned int               plLength;
    std::vector<unsigned char> payload;
garciay's avatar
garciay committed
35

36
    Decoding_Context() : payload() { next_header = 0xff; header_type = 0xff; header_sub_type = 0xff; plLength = -1; }
garciay's avatar
garciay committed
37
38
};

filatov's avatar
filatov committed
39
class GeoNetworkingCodec : public Codec<LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu> {
40

garciay's avatar
garciay committed
41
42
43
44
45
46
47
48
49
    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);

    int decode_ (Base_Type& type, const TTCN_Typedescriptor_t& field_descriptor, TTCN_Buffer& decoding_buffer);
    int decode_extendedHeader(LibItsGeoNetworking__TypesAndValues::ExtendedHeader& u, TTCN_Buffer& decoding_buffer);
50

garciay's avatar
garciay committed
51

garciay's avatar
garciay committed
52
public:
garciay's avatar
garciay committed
53
    GeoNetworkingCodec() : _ec(), _dc() {};
54

garciay's avatar
garciay committed
55
56
    virtual int encode (const LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& msg, OCTETSTRING& data);
    virtual int decode (const OCTETSTRING& data, LibItsGeoNetworking__TypesAndValues::GeoNetworkingPdu& msg);
garciay's avatar
garciay committed
57
58
59
};

#endif