--- a/src/CMakeLists.txt Sat May 29 21:49:37 2021 +0200
+++ b/src/CMakeLists.txt Sat May 29 22:12:19 2021 +0200
@@ -17,7 +17,7 @@
# Relpipe libraries:
INCLUDE(FindPkgConfig)
-pkg_check_modules (RELPIPE_LIBS relpipe-lib-writer.cpp relpipe-lib-cli.cpp libxml++-2.6 yaml-0.1)
+pkg_check_modules (RELPIPE_LIBS relpipe-lib-writer.cpp relpipe-lib-cli.cpp libxml++-2.6)
include_directories(${RELPIPE_LIBS_INCLUDE_DIRS})
link_directories(${RELPIPE_LIBS_LIBRARY_DIRS})
@@ -33,7 +33,7 @@
)
# Link libraries:
-target_link_libraries(${EXECUTABLE_FILE} ${RELPIPE_LIBS_LIBRARIES})
+target_link_libraries(${EXECUTABLE_FILE} ${RELPIPE_LIBS_LIBRARIES} cbor)
set_property(TARGET ${EXECUTABLE_FILE} PROPERTY INSTALL_RPATH_USE_LINK_PATH TRUE)
install(TARGETS ${EXECUTABLE_FILE} DESTINATION bin)
--- a/src/XMLDocumentConstructor.h Sat May 29 21:49:37 2021 +0200
+++ b/src/XMLDocumentConstructor.h Sat May 29 22:12:19 2021 +0200
@@ -20,7 +20,7 @@
#include <vector>
#include <libxml++-2.6/libxml++/libxml++.h>
-#include <yaml.h>
+#include <cbor.h>
#include "XMLNameCodec.h"
@@ -32,36 +32,20 @@
private:
std::istream* input = nullptr;
xmlpp::DomParser* parser = nullptr;
- yaml_parser_t yamlParser;
XMLNameCodec nameCodec;
- enum class Mode {
- ROOT,
- SEQUENCE,
- MAPPING,
- MAP_KEY
- };
-
- std::string rootName = "yaml";
+ std::string rootName = "cbor";
xmlpp::Element* current;
- std::vector<Mode> mode;
-
- static int readFromInput(void* instance, unsigned char* buffer, size_t size, size_t* length) {
- std::istream* input = ((XMLDocumentConstructor*) instance)->input;
- input->read((char*) buffer, size);
- *length = input->gcount();
- return (input->good() || input->eof()) ? 1 : 0;
- }
/**
- * Both YAML and XML strings are in UTF-8.
+ * Both CBOR and XML strings are in UTF-8.
*/
- const char* y2x(yaml_char_t* value) {
+ const char* c2x(char* value) { // FIXME: cbor type
return value ? (const char*) value : "";
}
- const Glib::ustring y2xname(yaml_char_t* value) {
- return nameCodec.encode(y2x(value));
+ const Glib::ustring c2xname(char* value) { // FIXME: cbor type
+ return nameCodec.encode(c2x(value));
}
xmlpp::Element* parentOrSelf(xmlpp::Element* current) {
@@ -71,12 +55,12 @@
public:
XMLDocumentConstructor(std::istream* input, xmlpp::DomParser* parser) : input(input), parser(parser) {
- yaml_parser_initialize(&yamlParser);
- yaml_parser_set_input(&yamlParser, readFromInput, (void*) this);
+ // cbor_item_t * root = cbor_new_definite_map(2);
+ // FIXME: initialize CBOR parser
}
virtual ~XMLDocumentConstructor() {
- yaml_parser_delete(&yamlParser);
+ // FIXME: destroy CBOR parser
}
void setOption(const std::string& uri, const std::string& value) {
@@ -86,80 +70,6 @@
void process() {
current = parser->get_document()->create_root_node(rootName);
- mode.push_back(Mode::ROOT);
- std::string itemName;
-
- while (true) {
- yaml_event_t event;
-
- if (!yaml_parser_parse(&yamlParser, &event)) {
- // FIXME: throw exception
- return;
- }
-
-
- if (event.type == YAML_STREAM_END_EVENT) {
- yaml_event_delete(&event);
- break;
- } else if (event.type == YAML_STREAM_START_EVENT) {
- } else if (event.type == YAML_NO_EVENT) {
- current->add_child("null"); // TODO: null?
- } else if (event.type == YAML_DOCUMENT_START_EVENT) {
- } else if (event.type == YAML_DOCUMENT_END_EVENT) {
- } else if (event.type == YAML_ALIAS_EVENT) {
- // TODO: alias?
- } else if (event.type == YAML_SCALAR_EVENT) {
- if (mode.back() == Mode::SEQUENCE) {
- current->add_child(itemName)->add_child_text(y2x(event.data.scalar.value));
- } else if (mode.back() == Mode::MAPPING) {
- current = current->add_child(y2xname(event.data.scalar.value));
- mode.push_back(Mode::MAP_KEY);
- } else if (mode.back() == Mode::MAP_KEY) {
- current->add_child_text(y2x(event.data.scalar.value));
- current = parentOrSelf(current);
- mode.pop_back();
- } else if (mode.back() == Mode::ROOT) {
- current->add_child_text(y2x(event.data.scalar.value));
- } else {
- // TODO: process YAML_SCALAR_EVENT
- }
-
- } else if (event.type == YAML_SEQUENCE_START_EVENT) {
- xmlpp::Element* parent = current->get_parent();
- if (parent) {
- itemName = current->get_name();
- parent->remove_child(current);
- current = parent;
- } else {
- itemName = "item";
- }
- if (mode.back() == Mode::MAP_KEY) mode.pop_back();
- mode.push_back(Mode::SEQUENCE);
- } else if (event.type == YAML_SEQUENCE_END_EVENT) {
- mode.pop_back(); // TODO: assert sequence?
- } else if (event.type == YAML_MAPPING_START_EVENT) {
-
- if (mode.back() == Mode::ROOT) {
- } else if (mode.back() == Mode::SEQUENCE) {
- current = current->add_child(itemName);
- } else if (mode.back() == Mode::MAP_KEY) {
- mode.pop_back();
- } else {
- // TODO: map might be a key of another map → wrap/nest
- }
-
- mode.push_back(Mode::MAPPING);
- } else if (event.type == YAML_MAPPING_END_EVENT) {
- current = parentOrSelf(current);
- mode.pop_back(); // TODO: assert map?
- } else {
- // TODO: unsupported type?
- }
-
- yaml_event_delete(&event);
- }
-
-
}
};