From 2c001e655002ee713457342197a7005217cd16b4 Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 26 Jun 2019 14:40:30 +0200 Subject: Add a 16-bit XDR variant --- include/object/xdr16stream.h | 50 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 include/object/xdr16stream.h (limited to 'include/object/xdr16stream.h') diff --git a/include/object/xdr16stream.h b/include/object/xdr16stream.h new file mode 100644 index 0000000..7cec1b1 --- /dev/null +++ b/include/object/xdr16stream.h @@ -0,0 +1,50 @@ +#ifndef XDRSTREAM_H +#define XDRSTREAM_H + +#include + +class XDRStream { + private: + XDRStream(const XDRStream& copy); + uint16_t next_array_len; + bool is_fixed_length; + + public: + XDRStream() : next_array_len(0) {} + void setNextArrayLen(uint16_t len) {next_array_len = len;} + void setFixedLength() { is_fixed_length = true; } + void setVariableLength() { is_fixed_length = false; } + + virtual void put(char c) = 0; + + virtual void flush() {} + + XDRStream & operator<<(char c); + XDRStream & operator<<(unsigned char c); + XDRStream & operator<<(uint16_t number); + XDRStream & operator<<(int16_t number); + XDRStream & operator<<(uint32_t number); + XDRStream & operator<<(int32_t number); + XDRStream & operator<<(uint64_t number); + XDRStream & operator<<(int64_t number); + XDRStream & operator<<(float number); + XDRStream & operator<<(double number); + XDRStream & operator<<(char const *text); + template XDRStream & operator<<(char const (&text)[TSize]); + XDRStream & operator<<(XDRStream & (*fun) (XDRStream &)); +}; + + +// FLUSH: flush XDRStream buffer +XDRStream & flush(XDRStream & os); + +// TERM: zero-termination +XDRStream & term(XDRStream & os); + +template +XDRStream & opaque(XDRStream & os); + +XDRStream & fixed(XDRStream & os); +XDRStream & variable(XDRStream & os); + +#endif //OUTPUTSTREAM_H -- cgit v1.2.3