diff options
author | Daniel Friesel <derf@finalrewind.org> | 2018-12-05 08:23:06 +0100 |
---|---|---|
committer | Daniel Friesel <derf@finalrewind.org> | 2018-12-05 08:23:06 +0100 |
commit | bb1c35235b71079b20f469421a895b038bcfa0db (patch) | |
tree | 73e75e99815dbf97c9f4aafec89633d2767d7217 | |
parent | 7a0173db5f0acf0848ccc0589f64f08f44782337 (diff) |
XDR: Add proper get_string method
-rw-r--r-- | include/object/xdrinput.h | 1 | ||||
-rw-r--r-- | src/os/object/xdrinput.cc | 14 |
2 files changed, 15 insertions, 0 deletions
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); + } +} |