1
0
Fork 0

stream read operators for integer data types

This commit is contained in:
Kevin Matz 2021-07-26 13:33:14 -04:00
parent d1ee4e1dae
commit 237943489f
1 changed files with 12 additions and 0 deletions

View File

@ -72,6 +72,18 @@ public:
}
uint32_t available() { return in_avail(); }
uint8_t * data() { return gptr(); };
pdu_stream& operator>> (uint8_t& val) {
val = readType<uint8_t>();
return *this;
};
pdu_stream& operator>> (uint16_t& val) {
val = readType<uint16_t>();
return *this;
};
pdu_stream& operator>> (uint32_t& val) {
val = readType<uint32_t>();
return *this;
};
template<typename T> T readType() {
if (in_avail() < sizeof(T)) {
setstate(std::ios_base::failbit);