Add {h,n}to{h,n}{s,l} to Bytes
This commit is contained in:
parent
bd5a1666a5
commit
c53125384d
15
Bytes.cpp
15
Bytes.cpp
|
@ -12,6 +12,7 @@
|
||||||
#include "Bytes.h"
|
#include "Bytes.h"
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
#include <arpa/inet.h>
|
||||||
using namespace std;
|
using namespace std;
|
||||||
|
|
||||||
Bytes::Bytes() : data(), firstIndex(0) {}
|
Bytes::Bytes() : data(), firstIndex(0) {}
|
||||||
|
@ -52,11 +53,15 @@ Bytes& Bytes::operator<<(u8 v) {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Bytes& Bytes::operator<<(u16 v) {
|
Bytes& Bytes::operator<<(u16 v) {
|
||||||
insertData<u16>(v);
|
insertData<u16>(htons(v));
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Bytes& Bytes::operator<<(u32 v) {
|
Bytes& Bytes::operator<<(u32 v) {
|
||||||
insertData<u32>(v);
|
insertData<u32>(htonl(v));
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Bytes& Bytes::operator<<(u64 v) {
|
||||||
|
insertData<u64>(v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Bytes& Bytes::operator<<(const Bytes& v) {
|
Bytes& Bytes::operator<<(const Bytes& v) {
|
||||||
|
@ -79,10 +84,16 @@ Bytes& Bytes::operator>>(u8& v) {
|
||||||
}
|
}
|
||||||
Bytes& Bytes::operator>>(u16& v) {
|
Bytes& Bytes::operator>>(u16& v) {
|
||||||
extractData<u16>(v);
|
extractData<u16>(v);
|
||||||
|
htons(v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Bytes& Bytes::operator>>(u32& v) {
|
Bytes& Bytes::operator>>(u32& v) {
|
||||||
extractData<u32>(v);
|
extractData<u32>(v);
|
||||||
|
htonl(v);
|
||||||
|
return *this;
|
||||||
|
}
|
||||||
|
Bytes& Bytes::operator>>(u64& v) {
|
||||||
|
extractData<u64>(v);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
Bytes& Bytes::operator>>(char& v) {
|
Bytes& Bytes::operator>>(char& v) {
|
||||||
|
|
2
Bytes.h
2
Bytes.h
|
@ -41,6 +41,7 @@ class Bytes {
|
||||||
Bytes& operator<<(u8 v);
|
Bytes& operator<<(u8 v);
|
||||||
Bytes& operator<<(u16 v);
|
Bytes& operator<<(u16 v);
|
||||||
Bytes& operator<<(u32 v);
|
Bytes& operator<<(u32 v);
|
||||||
|
Bytes& operator<<(u64 v);
|
||||||
Bytes& operator<<(const Bytes& v);
|
Bytes& operator<<(const Bytes& v);
|
||||||
Bytes& operator<<(const char* str);
|
Bytes& operator<<(const char* str);
|
||||||
/// Appends the given data to the vector. Returns *this to allow
|
/// Appends the given data to the vector. Returns *this to allow
|
||||||
|
@ -49,6 +50,7 @@ class Bytes {
|
||||||
Bytes& operator>>(u8& v);
|
Bytes& operator>>(u8& v);
|
||||||
Bytes& operator>>(u16& v);
|
Bytes& operator>>(u16& v);
|
||||||
Bytes& operator>>(u32& v);
|
Bytes& operator>>(u32& v);
|
||||||
|
Bytes& operator>>(u64& v);
|
||||||
Bytes& operator>>(char& c);
|
Bytes& operator>>(char& c);
|
||||||
/// Extracts the given data type from the vector. Returns *this to
|
/// Extracts the given data type from the vector. Returns *this to
|
||||||
/// allow chaining.
|
/// allow chaining.
|
||||||
|
|
Loading…
Reference in a new issue