diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-09-24 16:34:15 +0200 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-09-24 16:34:15 +0200 |
commit | b682dc0cde9c7054174c083f44d6739f9648bd66 (patch) | |
tree | bbc0827cb94b2234a4e6d31605d5bdc73313e66e /src/os/object | |
parent | af0e76deef42154fd9914aceb31e5ca80465410e (diff) |
Start work on XDR Stream output
Diffstat (limited to 'src/os/object')
-rw-r--r-- | src/os/object/xdrstream.cc | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/src/os/object/xdrstream.cc b/src/os/object/xdrstream.cc new file mode 100644 index 0000000..eb5ca87 --- /dev/null +++ b/src/os/object/xdrstream.cc @@ -0,0 +1,106 @@ +#include "object/xdrstream.h" + +XDRStream & XDRStream::operator<<(unsigned char c) +{ + *this << (uint32_t)c; + return *this; +} + +XDRStream & XDRStream::operator<<(char c) +{ + *this << (int32_t)c; + return *this; +} + +XDRStream & XDRStream::operator<<(uint16_t number) +{ + *this << (uint32_t)number; + return *this; +} + +XDRStream & XDRStream::operator<<(int16_t number) +{ + *this << (int32_t)number; + return *this; +} + +XDRStream & XDRStream::operator<<(uint32_t number) +{ + put((number >> 24) & 0xffU); + put((number >> 16) & 0xffU); + put((number >> 8) & 0xffU); + put(number & 0xffU); + return *this; +} + +XDRStream & XDRStream::operator<<(int32_t number) +{ + put((number >> 24) & 0xffU); + put((number >> 16) & 0xffU); + put((number >> 8) & 0xffU); + put(number & 0xffU); + return *this; +} + +XDRStream & XDRStream::operator<<(uint64_t number) +{ + put((number >> 56) & 0xffU); + put((number >> 48) & 0xffU); + put((number >> 40) & 0xffU); + put((number >> 32) & 0xffU); + put((number >> 24) & 0xffU); + put((number >> 16) & 0xffU); + put((number >> 8) & 0xffU); + put(number & 0xffU); + return *this; +} + +XDRStream & XDRStream::operator<<(int64_t number) +{ + put((number >> 56) & 0xffU); + put((number >> 48) & 0xffU); + put((number >> 40) & 0xffU); + put((number >> 32) & 0xffU); + put((number >> 24) & 0xffU); + put((number >> 16) & 0xffU); + put((number >> 8) & 0xffU); + put(number & 0xffU); + return *this; +} + +XDRStream & XDRStream::operator<<(char const *data){ + uint32_t i; + for (i = 0; i < next_array_len; i++) { + put(data[i]); + } + while ((i++) % 4 != 0){ + put('\0'); + } + return *this; +} + +XDRStream & XDRStream::operator<<(XDRStream & (*fkt) (XDRStream &)) +{ + return fkt(*this); +} + +// FLUSH +XDRStream & flush(XDRStream & os) +{ + os.flush(); + return os; +} + +// TERM: null-termination +XDRStream & term(XDRStream & os) +{ + os.put('\0'); + os.flush(); + return os; +} + +XDRStream & opaque(XDRStream & os) +{ + os.setNextArrayLen(3); + return os; +} |