]>
Dogcows Code - chaz/yoink/blob - src/Moof/Packet.hh
198212c352646984e3a3352a6705a73e0de9c600
2 /*] Copyright (c) 2009-2010, Charles McGarvey [**************************
3 **] All rights reserved.
7 * Distributable under the terms and conditions of the 2-clause BSD license;
8 * see the file COPYING for a complete text of the license.
10 **************************************************************************/
12 #ifndef _MOOF_PACKET_HH_
13 #define _MOOF_PACKET_HH_
19 #include <boost/shared_array.hpp>
29 Packet(size_t size
= 1024);
30 Packet(const char* data
, size_t size
);
32 Packet
& operator<<(bool value
);
33 Packet
& operator<<(int8_t value
);
34 Packet
& operator<<(int16_t value
);
35 Packet
& operator<<(int32_t value
);
36 Packet
& operator<<(int64_t value
);
37 Packet
& operator<<(uint8_t value
);
38 Packet
& operator<<(uint16_t value
);
39 Packet
& operator<<(uint32_t value
);
40 Packet
& operator<<(uint64_t value
);
41 //Packet& operator<<(float value);
42 //Packet& operator<<(double value);
43 //Packet& operator<<(long double value);
45 size_t write(const void* bytes
, size_t size
);
47 Packet
& operator>>(bool& value
);
48 Packet
& operator>>(int8_t& value
);
49 Packet
& operator>>(int16_t& value
);
50 Packet
& operator>>(int32_t& value
);
51 Packet
& operator>>(int64_t& value
);
52 Packet
& operator>>(uint8_t& value
);
53 Packet
& operator>>(uint16_t& value
);
54 Packet
& operator>>(uint32_t& value
);
55 Packet
& operator>>(uint64_t& value
);
57 size_t read(void* bytes
, size_t size
);
60 const char* bytes() const
62 return &mBuffer
.get()[mR
];
73 boost::shared_array
<char> mBuffer
;
86 inline Packet
& operator<<(Packet
& packet
, const char* value
)
88 uint8_t length
= strnlen(value
, 255);
90 packet
.write(value
, length
);
94 inline Packet
& operator<<(Packet
& packet
, const std::string
& value
)
96 packet
<< (uint8_t)value
.length();
97 packet
.write(value
.c_str(), value
.length());
102 inline Packet
& operator<<(Packet
& packet
, const std::vector
<T
>& value
)
104 packet
<< (uint8_t)value
.size();
105 typename
std::vector
<T
>::const_iterator it
;
106 for (it
= value
.begin(); it
!= value
.end(); ++it
)
114 inline Packet
& operator>>(Packet
& packet
, std::string
& value
)
120 size_t charsRead
= packet
.read(str
, length
);
121 value
.assign(str
, charsRead
);
126 inline Packet
& operator>>(Packet
& packet
, std::vector
<T
>& value
)
132 for (uint8_t i
= 0; i
< size
; ++i
)
136 value
.push_back(item
);
145 #endif // _MOOF_PACKET_HH_
This page took 0.038094 seconds and 4 git commands to generate.