1 #ifndef NETWORK_PACKET_HH |
1 #ifndef NETWORK_PACKET_HH |
2 #define NETWORK_PACKET_HH |
2 #define NETWORK_PACKET_HH |
3 |
3 |
4 #include "NetworkConfig.hh" |
4 #include "NetworkConfig.hh" |
|
5 #include "Vector.hh" |
|
6 #include "Error.hh" |
|
7 |
|
8 class NetworkPacketError : public Error { |
|
9 public: |
|
10 NetworkPacketError (const std::string &message) : Error(message) { } |
|
11 }; |
5 |
12 |
6 class NetworkPacket { |
13 class NetworkPacket { |
7 private: |
14 private: |
8 char buf[NETWORK_PACKET_SIZE]; |
15 char buf[NETWORK_PACKET_SIZE]; |
9 size_t buf_size, data_size, offset; |
16 size_t buf_size, data_size, offset; |
23 size_t get_buf_size (void) const { return buf_size; } |
30 size_t get_buf_size (void) const { return buf_size; } |
24 |
31 |
25 void set_data_size (size_t size) { offset = 0; data_size = size; } |
32 void set_data_size (size_t size) { offset = 0; data_size = size; } |
26 |
33 |
27 // type-reads, handle network-endianlness |
34 // type-reads, handle network-endianlness |
28 uint32_t read_uint32 (void) const; |
35 uint32_t read_uint32 (void); |
29 uint16_t read_uint16 (void) const; |
36 uint16_t read_uint16 (void); |
30 uint8_t read_uint8 (void) const; |
37 uint8_t read_uint8 (void); |
31 |
38 |
32 int32_t read_int32 (void) const; |
39 int32_t read_int32 (void); |
33 int16_t read_int16 (void) const; |
40 int16_t read_int16 (void); |
34 int8_t read_int8 (void) const; |
41 int8_t read_int8 (void); |
|
42 |
|
43 float read_float32 (void); |
|
44 |
|
45 Vector read_vector (void); |
35 |
46 |
36 void write_uint32 (uint32_t val); |
47 void write_uint32 (uint32_t val); |
37 void write_uint16 (uint16_t val); |
48 void write_uint16 (uint16_t val); |
38 void write_uint8 (uint8_t val); |
49 void write_uint8 (uint8_t val); |
39 |
50 |
40 void write_int32 (int32_t val); |
51 void write_int32 (int32_t val); |
41 void write_int16 (int16_t val); |
52 void write_int16 (int16_t val); |
42 void write_int8 (int8_t val); |
53 void write_int8 (int8_t val); |
|
54 |
|
55 void write_float32 (float val); |
43 |
56 |
|
57 void write_vector (const Vector &vec); |
44 void write_packet (const NetworkPacket &pkt); |
58 void write_packet (const NetworkPacket &pkt); |
45 }; |
59 }; |
46 |
60 |
47 #endif /* NETWORK_PACKET_HH */ |
61 #endif /* NETWORK_PACKET_HH */ |