]>
Dogcows Code - chaz/yoink/blob - src/Moof/Packet.hh
1a5e42fed31bc696cae6913194f535d268e0a99a
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_
21 #define PAGE_SIZE 4096
32 Packet(size_t size
= PAGE_SIZE
);
33 Packet(const char* data
, size_t size
);
35 Packet(const Packet
& copy
);
36 Packet
& operator=(const Packet
& copy
);
40 Packet
& operator<<(bool value
);
41 Packet
& operator<<(int8_t value
);
42 Packet
& operator<<(int16_t value
);
43 Packet
& operator<<(int32_t value
);
44 Packet
& operator<<(int64_t value
);
45 Packet
& operator<<(uint8_t value
);
46 Packet
& operator<<(uint16_t value
);
47 Packet
& operator<<(uint32_t value
);
48 Packet
& operator<<(uint64_t value
);
49 Packet
& operator<<(float value
);
50 Packet
& operator<<(double value
);
52 size_t write(const void* bytes
, size_t size
);
54 Packet
& operator>>(bool& value
);
55 Packet
& operator>>(int8_t& value
);
56 Packet
& operator>>(int16_t& value
);
57 Packet
& operator>>(int32_t& value
);
58 Packet
& operator>>(int64_t& value
);
59 Packet
& operator>>(uint8_t& value
);
60 Packet
& operator>>(uint16_t& value
);
61 Packet
& operator>>(uint32_t& value
);
62 Packet
& operator>>(uint64_t& value
);
63 Packet
& operator>>(float& value
);
64 Packet
& operator>>(double& value
);
66 size_t read(void* bytes
, size_t size
);
72 const char* bytes() const
98 inline Packet
& operator<<(Packet
& packet
, const char* value
)
100 uint16_t length
= strlen(value
);
102 packet
.write(value
, length
);
107 inline Packet
& operator<<(Packet
& packet
, const std::basic_string
<T
>& value
)
109 packet
<< (uint16_t)value
.length();
110 packet
.write(value
.data(), value
.length() * sizeof(T
));
115 inline Packet
& operator>>(Packet
& packet
, std::basic_string
<T
>& value
)
121 size_t charsRead
= packet
.read(str
, length
* sizeof(T
));
122 value
.assign(str
, charsRead
);
128 inline Packet
& operator<<(Packet
& packet
, const std::vector
<T
>& value
)
130 packet
<< (uint16_t)value
.size();
131 typename
std::vector
<T
>::const_iterator it
;
132 for (it
= value
.begin(); it
!= value
.end(); ++it
)
140 inline Packet
& operator>>(Packet
& packet
, std::vector
<T
>& value
)
146 for (uint16_t i
= 0; i
< size
; ++i
)
150 value
.push_back(item
);
158 #endif // _MOOF_PACKET_HH_
This page took 0.043975 seconds and 4 git commands to generate.