diff --git a/Bytes.cpp b/Bytes.cpp index b26247f..57b41ad 100644 --- a/Bytes.cpp +++ b/Bytes.cpp @@ -12,6 +12,7 @@ #include "Bytes.h" #include #include +#include using namespace std; Bytes::Bytes() : data(), firstIndex(0) {} @@ -52,11 +53,15 @@ Bytes& Bytes::operator<<(u8 v) { return *this; } Bytes& Bytes::operator<<(u16 v) { - insertData(v); + insertData(htons(v)); return *this; } Bytes& Bytes::operator<<(u32 v) { - insertData(v); + insertData(htonl(v)); + return *this; +} +Bytes& Bytes::operator<<(u64 v) { + insertData(v); return *this; } Bytes& Bytes::operator<<(const Bytes& v) { @@ -79,10 +84,16 @@ Bytes& Bytes::operator>>(u8& v) { } Bytes& Bytes::operator>>(u16& v) { extractData(v); + htons(v); return *this; } Bytes& Bytes::operator>>(u32& v) { extractData(v); + htonl(v); + return *this; +} +Bytes& Bytes::operator>>(u64& v) { + extractData(v); return *this; } Bytes& Bytes::operator>>(char& v) { diff --git a/Bytes.h b/Bytes.h index ca3436f..474c74d 100644 --- a/Bytes.h +++ b/Bytes.h @@ -41,6 +41,7 @@ class Bytes { Bytes& operator<<(u8 v); Bytes& operator<<(u16 v); Bytes& operator<<(u32 v); + Bytes& operator<<(u64 v); Bytes& operator<<(const Bytes& v); Bytes& operator<<(const char* str); /// Appends the given data to the vector. Returns *this to allow @@ -49,6 +50,7 @@ class Bytes { Bytes& operator>>(u8& v); Bytes& operator>>(u16& v); Bytes& operator>>(u32& v); + Bytes& operator>>(u64& v); Bytes& operator>>(char& c); /// Extracts the given data type from the vector. Returns *this to /// allow chaining.