summaryrefslogtreecommitdiff
path: root/src/os/object
diff options
context:
space:
mode:
authorDaniel Friesel <derf@finalrewind.org>2018-10-15 16:30:58 +0200
committerDaniel Friesel <derf@finalrewind.org>2018-10-15 16:30:58 +0200
commita1bbc3b6f2707fa808d19ad0baa035c3bac3f641 (patch)
tree7e5052ee3aec7e1b368a6098179d4fdfd4cc53ee /src/os/object
parent5471509e033abcddb078383cc4656af06c265ce6 (diff)
add preliminary xdr input driver
Diffstat (limited to 'src/os/object')
-rw-r--r--src/os/object/xdrinput.cc51
1 files changed, 51 insertions, 0 deletions
diff --git a/src/os/object/xdrinput.cc b/src/os/object/xdrinput.cc
new file mode 100644
index 0000000..561c779
--- /dev/null
+++ b/src/os/object/xdrinput.cc
@@ -0,0 +1,51 @@
+#include "object/xdrinput.h"
+
+uint32_t XDRInput::get_uint32()
+{
+ uint32_t ret = ((uint8_t)data[pos]<<24) | ((uint8_t)data[pos+1]<<16)
+ | ((uint8_t)data[pos+2]<<8) | (uint8_t)data[pos+3];
+ pos += 4;
+ return ret;
+}
+
+int32_t XDRInput::get_int32()
+{
+ int32_t ret = (data[pos]<<24) | (data[pos+1]<<16) | (data[pos+2]<<8) | data[pos+3];
+ pos += 4;
+ return ret;
+}
+
+uint64_t XDRInput::get_uint64()
+{
+ uint64_t ret0 = ((uint8_t)data[pos]<<24) | ((uint8_t)data[pos+1]<<16)
+ | ((uint8_t)data[pos+2]<<8) | (uint8_t)data[pos+3];
+ pos += 4;
+ uint64_t ret1 = ((uint8_t)data[pos]<<24) | ((uint8_t)data[pos+1]<<16)
+ | ((uint8_t)data[pos+2]<<8) | (uint8_t)data[pos+3];
+ pos += 4;
+ return (ret0 << 32) | ret1;
+}
+
+int64_t XDRInput::get_int64()
+{
+ int64_t ret0 = (data[pos]<<24) | (data[pos+1]<<16) | (data[pos+2]<<8) | data[pos+3];
+ pos += 4;
+ int64_t ret1 = (data[pos]<<24) | (data[pos+1]<<16) | (data[pos+2]<<8) | data[pos+3];
+ pos += 4;
+ return (ret0 << 32) | ret1;
+}
+
+uint32_t XDRInput::get_opaque_length()
+{
+ return get_uint32();
+}
+
+char *XDRInput::get_opaque(uint32_t length)
+{
+ char *ret = data + pos;
+ pos += length;
+ if (length % 4) {
+ pos += 4 - (length % 4);
+ }
+ return ret;
+}