Changeset View
Changeset View
Standalone View
Standalone View
src/serialize.h
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | inline void ser_writedata16(Stream &s, uint16_t obj) { | ||||
s.write((char *)&obj, 2); | s.write((char *)&obj, 2); | ||||
} | } | ||||
template <typename Stream> | template <typename Stream> | ||||
inline void ser_writedata32(Stream &s, uint32_t obj) { | inline void ser_writedata32(Stream &s, uint32_t obj) { | ||||
obj = htole32(obj); | obj = htole32(obj); | ||||
s.write((char *)&obj, 4); | s.write((char *)&obj, 4); | ||||
} | } | ||||
template <typename Stream> | template <typename Stream> | ||||
inline void ser_writedata32be(Stream &s, uint32_t obj) { | |||||
obj = htobe32(obj); | |||||
s.write((char *)&obj, 4); | |||||
} | |||||
template <typename Stream> | |||||
inline void ser_writedata64(Stream &s, uint64_t obj) { | inline void ser_writedata64(Stream &s, uint64_t obj) { | ||||
obj = htole64(obj); | obj = htole64(obj); | ||||
s.write((char *)&obj, 8); | s.write((char *)&obj, 8); | ||||
} | } | ||||
template <typename Stream> inline uint8_t ser_readdata8(Stream &s) { | template <typename Stream> inline uint8_t ser_readdata8(Stream &s) { | ||||
uint8_t obj; | uint8_t obj; | ||||
s.read((char *)&obj, 1); | s.read((char *)&obj, 1); | ||||
return obj; | return obj; | ||||
} | } | ||||
template <typename Stream> inline uint16_t ser_readdata16(Stream &s) { | template <typename Stream> inline uint16_t ser_readdata16(Stream &s) { | ||||
uint16_t obj; | uint16_t obj; | ||||
s.read((char *)&obj, 2); | s.read((char *)&obj, 2); | ||||
return le16toh(obj); | return le16toh(obj); | ||||
} | } | ||||
template <typename Stream> inline uint32_t ser_readdata32(Stream &s) { | template <typename Stream> inline uint32_t ser_readdata32(Stream &s) { | ||||
uint32_t obj; | uint32_t obj; | ||||
s.read((char *)&obj, 4); | s.read((char *)&obj, 4); | ||||
return le32toh(obj); | return le32toh(obj); | ||||
} | } | ||||
template <typename Stream> inline uint32_t ser_readdata32be(Stream &s) { | |||||
uint32_t obj; | |||||
s.read((char *)&obj, 4); | |||||
return be32toh(obj); | |||||
} | |||||
template <typename Stream> inline uint64_t ser_readdata64(Stream &s) { | template <typename Stream> inline uint64_t ser_readdata64(Stream &s) { | ||||
uint64_t obj; | uint64_t obj; | ||||
s.read((char *)&obj, 8); | s.read((char *)&obj, 8); | ||||
return le64toh(obj); | return le64toh(obj); | ||||
} | } | ||||
inline uint64_t ser_double_to_uint64(double x) { | inline uint64_t ser_double_to_uint64(double x) { | ||||
union { | union { | ||||
double x; | double x; | ||||
▲ Show 20 Lines • Show All 818 Lines • Show Last 20 Lines |