]>
Dogcows Code - chaz/yoink/blob - src/Moof/Packet.hh
208b22e9bc75fa51af739546708e7023206b6bdc
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
);
44 size_t write(const void* bytes
, size_t size
);
46 Packet
& operator>>(bool& value
);
47 Packet
& operator>>(int8_t& value
);
48 Packet
& operator>>(int16_t& value
);
49 Packet
& operator>>(int32_t& value
);
50 Packet
& operator>>(int64_t& value
);
51 Packet
& operator>>(uint8_t& value
);
52 Packet
& operator>>(uint16_t& value
);
53 Packet
& operator>>(uint32_t& value
);
54 Packet
& operator>>(uint64_t& value
);
55 Packet
& operator>>(float& value
);
56 Packet
& operator>>(double& value
);
58 size_t read(void* bytes
, size_t size
);
61 const char* bytes() const
63 return &mBuffer
.get()[mR
];
74 boost::shared_array
<char> mBuffer
;
87 inline Packet
& operator<<(Packet
& packet
, const char* value
)
89 uint16_t length
= strlen(value
);
91 packet
.write(value
, length
);
95 inline Packet
& operator<<(Packet
& packet
, const std::string
& value
)
97 packet
<< (uint16_t)value
.length();
98 packet
.write(value
.c_str(), value
.length());
103 inline Packet
& operator<<(Packet
& packet
, const std::vector
<T
>& value
)
105 packet
<< (uint8_t)value
.size();
106 typename
std::vector
<T
>::const_iterator it
;
107 for (it
= value
.begin(); it
!= value
.end(); ++it
)
115 inline Packet
& operator>>(Packet
& packet
, std::string
& value
)
121 size_t charsRead
= packet
.read(str
, length
);
122 value
.assign(str
, charsRead
);
127 inline Packet
& operator>>(Packet
& packet
, std::vector
<T
>& value
)
133 for (uint8_t i
= 0; i
< size
; ++i
)
137 value
.push_back(item
);
146 #endif // _MOOF_PACKET_HH_
This page took 0.034682 seconds and 4 git commands to generate.