From c53125384d977a0fa1569f90bdb718973ab00c72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophile=20Bastian?= Date: Sun, 20 Nov 2016 00:14:40 +0100 Subject: [PATCH] Add {h,n}to{h,n}{s,l} to Bytes --- Bytes.cpp | 15 +++++++++++++-- Bytes.h | 2 ++ 2 files changed, 15 insertions(+), 2 deletions(-) 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.