# HG changeset patch # User František Kučera # Date 1622996963 -7200 # Node ID ba850b20fe0da8f9e82e62967f58ff24c3df2b61 # Parent cae9eedf41802cbf60633eb0e4ab2924b5532802 basic tag support diff -r cae9eedf4180 -r ba850b20fe0d src/XMLDocumentConstructor.h --- a/src/XMLDocumentConstructor.h Sun Jun 06 11:46:26 2021 +0200 +++ b/src/XMLDocumentConstructor.h Sun Jun 06 18:29:23 2021 +0200 @@ -60,6 +60,9 @@ std::stringstream currentIndefiniteString; + uint64_t currentTag; + bool currentTagPresent; + cbor_callbacks callbacks = cbor_empty_callbacks; /** @@ -82,26 +85,37 @@ } } + void writeCurrentTag(xmlpp::Element* element) { + if (currentTagPresent) { + element->set_attribute("tag", std::to_string(currentTag)); + currentTagPresent = false; + } + } + void appendScalarValue(Glib::ustring value, Glib::ustring cborType) { if (mode.back() == Mode::ARRAY) { xmlpp::Element* element = current->add_child(nameCodec.encode(itemName)); element->add_child_text(value); element->set_attribute("value-type", cborType); + writeCurrentTag(element); } else if (mode.back() == Mode::MAP_KEY) { current = current->add_child(nameCodec.encode(value)); current->set_attribute("key-type", cborType); + writeCurrentTag(current); mode.push_back(Mode::MAP_VALUE); } else if (mode.back() == Mode::MAP_VALUE) { current->add_child_text(value); current->set_attribute("value-type", cborType); + writeCurrentTag(current); current = parentOrSelf(current); mode.pop_back(); } else if (mode.back() == Mode::ROOT) { current->add_child_text(value); + writeCurrentTag(current); } else if (mode.back() == Mode::BYTE_STRING || mode.back() == Mode::CHAR_STRING) { currentIndefiniteString << value; } else { - // TODO: process YAML_SCALAR_EVENT + // TODO: throw exception? } checkRemainingItems(); @@ -120,6 +134,7 @@ if (mode.back() == Mode::MAP_KEY) mode.pop_back(); mode.push_back(Mode::ARRAY); remainingItems.push_back(size); + writeCurrentTag(current); } void mapStart(ssize_t size) { @@ -137,6 +152,7 @@ mode.push_back(Mode::MAP_KEY); remainingItems.push_back(size); + writeCurrentTag(current); } void flushCurrentIndefiniteString(Glib::ustring cborType) { @@ -243,9 +259,8 @@ callbacks.tag = [](void* context, uint64_t value) { CBOR_CALLBACK_START - // TODO: implement - xmlpp::Element* element = instance->current->add_child("tag"); - element->add_child_text(std::to_string(value)); + instance->currentTag = value; + instance->currentTagPresent = true; CBOR_CALLBACK_END };