summaryrefslogtreecommitdiff
path: root/include/object
diff options
context:
space:
mode:
authorDaniel Friesel <daniel.friesel@uos.de>2019-06-26 14:40:30 +0200
committerDaniel Friesel <daniel.friesel@uos.de>2019-06-26 14:40:30 +0200
commit2c001e655002ee713457342197a7005217cd16b4 (patch)
treef97ee9055aa89aa065f29bf078426bd27480ccc4 /include/object
parentf4394afb4e7915457f0a901e9c3d9d0f08470593 (diff)
Add a 16-bit XDR variant
Diffstat (limited to 'include/object')
-rw-r--r--include/object/xdr16input.h27
-rw-r--r--include/object/xdr16stream.h50
2 files changed, 77 insertions, 0 deletions
diff --git a/include/object/xdr16input.h b/include/object/xdr16input.h
new file mode 100644
index 0000000..66b2c56
--- /dev/null
+++ b/include/object/xdr16input.h
@@ -0,0 +1,27 @@
+#ifndef XDRINPUT_H
+#define XDRINPUT_H
+
+#include <stdint.h>
+
+class XDRInput {
+ private:
+ XDRInput(const XDRInput& copy);
+ char *data;
+ uint32_t pos;
+
+ public:
+ XDRInput(char *d) : pos(0) { data = d; }
+ uint16_t get_uint16();
+ int16_t get_int16();
+ uint32_t get_uint32();
+ int32_t get_int32();
+ uint64_t get_uint64();
+ int64_t get_int64();
+ float get_float();
+ double get_double();
+ uint16_t get_opaque_length();
+ char* get_opaque(uint16_t length);
+ void get_string(char *target);
+};
+
+#endif
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 <stdint.h>
+
+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<uint16_t TSize> 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<int TSize>
+XDRStream & opaque(XDRStream & os);
+
+XDRStream & fixed(XDRStream & os);
+XDRStream & variable(XDRStream & os);
+
+#endif //OUTPUTSTREAM_H