Add read_simple_dynamic_tag and write_simple_dynamic_tag

This commit is contained in:
2023-10-24 01:54:17 -04:00
parent d68a1dd0fe
commit 7f5744da2d

View File

@@ -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<class STRING>
void write_simple_dynamic(const SimpleDynamic<STRING> &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<class STRING>
void read_simple_dynamic(SimpleDynamic<STRING> *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;