]>
Dogcows Code - chaz/yoink/blob - src/Moof/Packet.hh
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
);
37 Packet
& operator<<(bool value
);
38 Packet
& operator<<(int8_t value
);
39 Packet
& operator<<(int16_t value
);
40 Packet
& operator<<(int32_t value
);
41 Packet
& operator<<(int64_t value
);
42 Packet
& operator<<(uint8_t value
);
43 Packet
& operator<<(uint16_t value
);
44 Packet
& operator<<(uint32_t value
);
45 Packet
& operator<<(uint64_t value
);
46 Packet
& operator<<(float value
);
47 Packet
& operator<<(double value
);
49 size_t write(const void* bytes
, size_t size
);
51 Packet
& operator>>(bool& value
);
52 Packet
& operator>>(int8_t& value
);
53 Packet
& operator>>(int16_t& value
);
54 Packet
& operator>>(int32_t& value
);
55 Packet
& operator>>(int64_t& value
);
56 Packet
& operator>>(uint8_t& value
);
57 Packet
& operator>>(uint16_t& value
);
58 Packet
& operator>>(uint32_t& value
);
59 Packet
& operator>>(uint64_t& value
);
60 Packet
& operator>>(float& value
);
61 Packet
& operator>>(double& value
);
63 size_t read(void* bytes
, size_t size
);
66 const char* bytes() const
92 inline Packet
& operator<<(Packet
& packet
, const char* value
)
94 uint16_t length
= strlen(value
);
96 packet
.write(value
, length
);
101 inline Packet
& operator<<(Packet
& packet
, const std::basic_string
<T
>& value
)
103 packet
<< (uint16_t)value
.length();
104 packet
.write(value
.data(), value
.length() * sizeof(T
));
109 inline Packet
& operator>>(Packet
& packet
, std::basic_string
<T
>& value
)
115 size_t charsRead
= packet
.read(str
, length
* sizeof(T
));
116 value
.assign(str
, charsRead
);
122 inline Packet
& operator<<(Packet
& packet
, const std::vector
<T
>& value
)
124 packet
<< (uint16_t)value
.size();
125 typename
std::vector
<T
>::const_iterator it
;
126 for (it
= value
.begin(); it
!= value
.end(); ++it
)
134 inline Packet
& operator>>(Packet
& packet
, std::vector
<T
>& value
)
140 for (uint16_t i
= 0; i
< size
; ++i
)
144 value
.push_back(item
);
152 #endif // _MOOF_PACKET_HH_
This page took 0.041957 seconds and 4 git commands to generate.