56 * number of remainin items in the fixed-size container (map or array) at current tree-level |
56 * number of remainin items in the fixed-size container (map or array) at current tree-level |
57 */ |
57 */ |
58 std::vector<ssize_t> remainingItems; |
58 std::vector<ssize_t> remainingItems; |
59 #define INDEFINITE -1 |
59 #define INDEFINITE -1 |
60 |
60 |
|
61 #define ATTR_VALUE_TYPE "value-type" |
|
62 #define ATTR_KEY_TYPE "key-type" |
|
63 #define ATTR_TAG "tag" |
|
64 #define ATTR_BYTES_READ "bytes-read" |
|
65 |
61 std::stringstream currentIndefiniteString; |
66 std::stringstream currentIndefiniteString; |
62 |
67 |
63 uint64_t currentTag; |
68 uint64_t currentTag; |
64 bool currentTagPresent = false; |
69 bool currentTagPresent = false; |
65 |
70 |
85 } |
90 } |
86 } |
91 } |
87 |
92 |
88 void writeCurrentTag(xmlpp::Element* element) { |
93 void writeCurrentTag(xmlpp::Element* element) { |
89 if (currentTagPresent) { |
94 if (currentTagPresent) { |
90 element->set_attribute("tag", std::to_string(currentTag)); |
95 element->set_attribute(ATTR_TAG, std::to_string(currentTag)); |
91 currentTagPresent = false; |
96 currentTagPresent = false; |
92 } |
97 } |
93 } |
98 } |
94 |
99 |
95 void appendScalarValue(Glib::ustring value, Glib::ustring cborType) { |
100 void appendScalarValue(Glib::ustring value, Glib::ustring cborType) { |
96 if (mode.back() == Mode::ARRAY) { |
101 if (mode.back() == Mode::ARRAY) { |
97 xmlpp::Element* element = current->add_child(nameCodec.encode(itemName)); |
102 xmlpp::Element* element = current->add_child(nameCodec.encode(itemName)); |
98 element->add_child_text(value); |
103 element->add_child_text(value); |
99 element->set_attribute("value-type", cborType); |
104 element->set_attribute(ATTR_VALUE_TYPE, cborType); |
100 writeCurrentTag(element); |
105 writeCurrentTag(element); |
101 } else if (mode.back() == Mode::MAP_KEY) { |
106 } else if (mode.back() == Mode::MAP_KEY) { |
102 current = current->add_child(nameCodec.encode(value)); |
107 current = current->add_child(nameCodec.encode(value)); |
103 current->set_attribute("key-type", cborType); |
108 current->set_attribute(ATTR_KEY_TYPE, cborType); |
104 writeCurrentTag(current); |
109 writeCurrentTag(current); |
105 mode.push_back(Mode::MAP_VALUE); |
110 mode.push_back(Mode::MAP_VALUE); |
106 } else if (mode.back() == Mode::MAP_VALUE) { |
111 } else if (mode.back() == Mode::MAP_VALUE) { |
107 current->add_child_text(value); |
112 current->add_child_text(value); |
108 current->set_attribute("value-type", cborType); |
113 current->set_attribute(ATTR_VALUE_TYPE, cborType); |
109 writeCurrentTag(current); |
114 writeCurrentTag(current); |
110 current = parentOrSelf(current); |
115 current = parentOrSelf(current); |
111 mode.pop_back(); |
116 mode.pop_back(); |
112 } else if (mode.back() == Mode::ROOT) { |
117 } else if (mode.back() == Mode::ROOT) { |
113 current->add_child_text(value); |
118 current->add_child_text(value); |
114 current->set_attribute("value-type", cborType); |
119 current->set_attribute(ATTR_VALUE_TYPE, cborType); |
115 writeCurrentTag(current); |
120 writeCurrentTag(current); |
116 } else if (mode.back() == Mode::BYTE_STRING || mode.back() == Mode::CHAR_STRING) { |
121 } else if (mode.back() == Mode::BYTE_STRING || mode.back() == Mode::CHAR_STRING) { |
117 currentIndefiniteString << value; |
122 currentIndefiniteString << value; |
118 } else { |
123 } else { |
119 // TODO: throw exception? |
124 // TODO: throw exception? |
122 checkRemainingItems(); |
127 checkRemainingItems(); |
123 } |
128 } |
124 |
129 |
125 void arrayStart(ssize_t size) { |
130 void arrayStart(ssize_t size) { |
126 if (mode.back() == Mode::ROOT) { |
131 if (mode.back() == Mode::ROOT) { |
127 current->set_attribute("value-type", "array"); |
132 current->set_attribute(ATTR_VALUE_TYPE, "array"); |
128 itemName = "item"; |
133 itemName = "item"; |
129 } else if (mode.back() == Mode::ARRAY) { |
134 } else if (mode.back() == Mode::ARRAY) { |
130 current = current->add_child(nameCodec.encode(itemName)); |
135 current = current->add_child(nameCodec.encode(itemName)); |
131 itemName = "item"; |
136 itemName = "item"; |
132 } else if (mode.back() == Mode::MAP_VALUE) { |
137 } else if (mode.back() == Mode::MAP_VALUE) { |