From 7f5744da2d973273cc1de891c69e4564716b9ef3 Mon Sep 17 00:00:00 2001 From: jyelon Date: Tue, 24 Oct 2023 01:54:17 -0400 Subject: [PATCH] Add read_simple_dynamic_tag and write_simple_dynamic_tag --- luprex/ext/base-buffer.hpp | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/luprex/ext/base-buffer.hpp b/luprex/ext/base-buffer.hpp index 2b45fa4d..b31b3991 100644 --- a/luprex/ext/base-buffer.hpp +++ b/luprex/ext/base-buffer.hpp @@ -478,6 +478,12 @@ public: write_bytes(s); } + // Write a SimpleDynamicTag. + // + void write_simple_dynamic_tag(SimpleDynamicTag tag) { + write_uint8(uint8_t(tag)); + } + // Write a SimpleDynamic value. // // This works regardless of what kind of string is present in the @@ -485,7 +491,7 @@ public: // template void write_simple_dynamic(const SimpleDynamic &sd) { - write_uint8(uint8_t(sd.type)); + write_simple_dynamic_tag(sd.type); switch(sd.type) { case SimpleDynamicTag::NUMBER: write_double(sd.x); break; case SimpleDynamicTag::BOOLEAN: write_bool(sd.x == 1.0); break; @@ -595,11 +601,17 @@ public: return read_string_limit(0x1000000); } + // Read a SimpleDynamicTag + // + SimpleDynamicTag read_simple_dynamic_tag() { + return SimpleDynamicTag(read_uint8()); + } + // Read a SimpleDynamic // template void read_simple_dynamic(SimpleDynamic *result) { - SimpleDynamicTag type = SimpleDynamicTag(read_uint8()); + SimpleDynamicTag type = read_simple_dynamic_tag(); switch (type) { case SimpleDynamicTag::NUMBER: result->set_number(read_double()); break; case SimpleDynamicTag::BOOLEAN: result->set_boolean(read_bool()); break;