From bb1c35235b71079b20f469421a895b038bcfa0db Mon Sep 17 00:00:00 2001 From: Daniel Friesel Date: Wed, 5 Dec 2018 08:23:06 +0100 Subject: XDR: Add proper get_string method --- include/object/xdrinput.h | 1 + src/os/object/xdrinput.cc | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/include/object/xdrinput.h b/include/object/xdrinput.h index 7b8ac40..5f99169 100644 --- a/include/object/xdrinput.h +++ b/include/object/xdrinput.h @@ -19,6 +19,7 @@ class XDRInput { double get_double(); uint32_t get_opaque_length(); char* get_opaque(uint32_t length); + void get_string(char *target); }; #endif diff --git a/src/os/object/xdrinput.cc b/src/os/object/xdrinput.cc index 077f695..5fb17bf 100644 --- a/src/os/object/xdrinput.cc +++ b/src/os/object/xdrinput.cc @@ -61,3 +61,17 @@ char *XDRInput::get_opaque(uint32_t length) } return ret; } + +void XDRInput::get_string(char* target) +{ + uint16_t length = get_opaque_length(); + uint16_t i; + for (i = 0; i < length; i++) { + target[i] = data[pos + i]; + } + target[i] = 0; + pos += length; + if (length % 4) { + pos += 4 - (length % 4); + } +} -- cgit v1.2.3