Simple Geolocalization and Course Transmission Protocol (SGCTP)
 All Classes Namespaces Files Functions Variables Enumerations Enumerator Friends Macros Pages
payload.hpp
Go to the documentation of this file.
1 // INDENTING (emacs/vi): -*- mode:c++; tab-width:2; c-basic-offset:2; intent-tabs-mode:nil; -*- ex: set tabstop=2 expandtab:
2 
3 /*
4  * Simple Geolocalization and Course Transmission Protocol (SGCTP)
5  * Copyright (C) 2014 Cedric Dufour <http://cedric.dufour.name>
6  *
7  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
8  * free software:
9  * you can redistribute it and/or modify it under the terms of the GNU General
10  * Public License as published by the Free Software Foundation, Version 3.
11  *
12  * The Simple Geolocalization and Course Transmission Protocol (SGCTP) is
13  * distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
14  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A
15  * PARTICULAR PURPOSE.
16  *
17  * See the GNU General Public License for more details.
18  */
19 
20 #ifndef SGCTP_CPAYLOAD_HPP
21 #define SGCTP_CPAYLOAD_HPP
22 
23 // C
24 #include <stdint.h>
25 #include <stdlib.h>
26 #include <string.h>
27 
28 
29 // SGCTP namespace
30 namespace SGCTP
31 {
32 
33  // External
34  class CData;
35 
36 
38 
41  class CPayload
42  {
43 
44  //----------------------------------------------------------------------
45  // CONSTANTS / STATIC
46  //----------------------------------------------------------------------
47 
48  public:
50  static const uint16_t BUFFER_SIZE = 33024; // Actually, it is 32939... but let's keep a few extra bytes available
51 
52  private:
54  static const uint8_t BITMASK[9];
55 
56  public:
58 
61  static unsigned char* allocBuffer()
62  {
63  return (unsigned char*)malloc( BUFFER_SIZE * sizeof( unsigned char ) );
64  };
66 
70  static void zeroBuffer( unsigned char *_pucBuffer )
71  {
72  memset( _pucBuffer, 0, BUFFER_SIZE * sizeof( unsigned char ) );
73  };
75 
79  static void freeBuffer( unsigned char *_pucBuffer )
80  {
81  ::free( _pucBuffer );
82  };
83 
84  //----------------------------------------------------------------------
85  // FIELDS
86  //----------------------------------------------------------------------
87 
88  private:
90  unsigned char *pucBufferPut;
92  const unsigned char *pucBufferGet;
95 
96 
97  //----------------------------------------------------------------------
98  // CONSTRUCTORS / DESTRUCTOR
99  //----------------------------------------------------------------------
100 
101  public:
103  {};
104  virtual ~CPayload()
105  {};
106 
107 
108  //----------------------------------------------------------------------
109  // METHODS
110  //----------------------------------------------------------------------
111 
112  private:
114 
118  void putBits( uint8_t _ui8tBitsSize,
119  uint8_t _ui8tBits );
121 
125  void putBytes( uint16_t _ui16tBytesSize,
126  const unsigned char *_pucBytes );
128 
132  uint8_t getBits( uint8_t _ui8tBitsSize );
134 
138  void getBytes( uint16_t _ui16tBytesSize,
139  unsigned char *_pucBytes );
140 
141  public:
143 
146  virtual int alloc()
147  {
148  return 0;
149  };
151 
156  virtual int serialize( unsigned char *_pucBuffer,
157  const CData &_roData );
159 
164  virtual int unserialize( CData *_poData,
165  const unsigned char *_pucBuffer,
166  uint16_t _ui16tBufferSize );
168  virtual void free() {};
169 
170  };
171 
172 }
173 
174 #endif // SGCTP_CPAYLOAD_HPP
virtual int unserialize(CData *_poData, const unsigned char *_pucBuffer, uint16_t _ui16tBufferSize)
Unserialize the SGCTP data from the given payload buffer.
Definition: payload.cpp:355
static const uint16_t BUFFER_SIZE
Buffer size required for payload (un-)serialization.
Definition: payload.hpp:50
static void freeBuffer(unsigned char *_pucBuffer)
Free a buffer allocated for payload (un-)serialization.
Definition: payload.hpp:79
uint8_t getBits(uint8_t _ui8tBitsSize)
Retrieve the given bits from the payload.
Definition: payload.cpp:69
uint32_t ui32tBufferBitOffset
SGCTP payload bit position.
Definition: payload.hpp:94
virtual void free()
Free resources for payload (un-)serialization.
Definition: payload.hpp:168
SGCTP data container.
Definition: data.hpp:44
virtual int serialize(unsigned char *_pucBuffer, const CData &_roData)
Serialize the given SGCTP data into the given payload buffer.
Definition: payload.cpp:93
void putBytes(uint16_t _ui16tBytesSize, const unsigned char *_pucBytes)
Add the given bytes to the payload.
Definition: payload.cpp:57
unsigned char * pucBufferPut
SGCTP payload export buffer pointer.
Definition: payload.hpp:82
(Raw) SGCTP payload
Definition: payload.hpp:41
void putBits(uint8_t _ui8tBitsSize, uint8_t _ui8tBits)
Add the given bits to the payload.
Definition: payload.cpp:42
virtual ~CPayload()
Definition: payload.hpp:104
virtual int alloc()
Allocate resources for payload (un-)serialization.
Definition: payload.hpp:146
static void zeroBuffer(unsigned char *_pucBuffer)
Zero-out a buffer required for payload (un-)serialization.
Definition: payload.hpp:70
const unsigned char * pucBufferGet
SGCTP payload import buffer pointer.
Definition: payload.hpp:92
static const uint8_t BITMASK[9]
Bit masks used to (un-)serialize data bit-per-bit.
Definition: payload.hpp:54
void getBytes(uint16_t _ui16tBytesSize, unsigned char *_pucBytes)
Retrieve the given bytes from the payload.
Definition: payload.cpp:81
static unsigned char * allocBuffer()
Allocate a buffer for payload (un-)serialization.
Definition: payload.hpp:61