80 if (remainingItems.back() < 1) containerEnd(); |
83 if (remainingItems.back() < 1) containerEnd(); |
81 } |
84 } |
82 } |
85 } |
83 } |
86 } |
84 |
87 |
|
88 void writeCurrentTag(xmlpp::Element* element) { |
|
89 if (currentTagPresent) { |
|
90 element->set_attribute("tag", std::to_string(currentTag)); |
|
91 currentTagPresent = false; |
|
92 } |
|
93 } |
|
94 |
85 void appendScalarValue(Glib::ustring value, Glib::ustring cborType) { |
95 void appendScalarValue(Glib::ustring value, Glib::ustring cborType) { |
86 if (mode.back() == Mode::ARRAY) { |
96 if (mode.back() == Mode::ARRAY) { |
87 xmlpp::Element* element = current->add_child(nameCodec.encode(itemName)); |
97 xmlpp::Element* element = current->add_child(nameCodec.encode(itemName)); |
88 element->add_child_text(value); |
98 element->add_child_text(value); |
89 element->set_attribute("value-type", cborType); |
99 element->set_attribute("value-type", cborType); |
|
100 writeCurrentTag(element); |
90 } else if (mode.back() == Mode::MAP_KEY) { |
101 } else if (mode.back() == Mode::MAP_KEY) { |
91 current = current->add_child(nameCodec.encode(value)); |
102 current = current->add_child(nameCodec.encode(value)); |
92 current->set_attribute("key-type", cborType); |
103 current->set_attribute("key-type", cborType); |
|
104 writeCurrentTag(current); |
93 mode.push_back(Mode::MAP_VALUE); |
105 mode.push_back(Mode::MAP_VALUE); |
94 } else if (mode.back() == Mode::MAP_VALUE) { |
106 } else if (mode.back() == Mode::MAP_VALUE) { |
95 current->add_child_text(value); |
107 current->add_child_text(value); |
96 current->set_attribute("value-type", cborType); |
108 current->set_attribute("value-type", cborType); |
|
109 writeCurrentTag(current); |
97 current = parentOrSelf(current); |
110 current = parentOrSelf(current); |
98 mode.pop_back(); |
111 mode.pop_back(); |
99 } else if (mode.back() == Mode::ROOT) { |
112 } else if (mode.back() == Mode::ROOT) { |
100 current->add_child_text(value); |
113 current->add_child_text(value); |
|
114 writeCurrentTag(current); |
101 } else if (mode.back() == Mode::BYTE_STRING || mode.back() == Mode::CHAR_STRING) { |
115 } else if (mode.back() == Mode::BYTE_STRING || mode.back() == Mode::CHAR_STRING) { |
102 currentIndefiniteString << value; |
116 currentIndefiniteString << value; |
103 } else { |
117 } else { |
104 // TODO: process YAML_SCALAR_EVENT |
118 // TODO: throw exception? |
105 } |
119 } |
106 |
120 |
107 checkRemainingItems(); |
121 checkRemainingItems(); |
108 } |
122 } |
109 |
123 |
118 } |
132 } |
119 |
133 |
120 if (mode.back() == Mode::MAP_KEY) mode.pop_back(); |
134 if (mode.back() == Mode::MAP_KEY) mode.pop_back(); |
121 mode.push_back(Mode::ARRAY); |
135 mode.push_back(Mode::ARRAY); |
122 remainingItems.push_back(size); |
136 remainingItems.push_back(size); |
|
137 writeCurrentTag(current); |
123 } |
138 } |
124 |
139 |
125 void mapStart(ssize_t size) { |
140 void mapStart(ssize_t size) { |
126 if (mode.back() == Mode::ROOT) { |
141 if (mode.back() == Mode::ROOT) { |
127 } else if (mode.back() == Mode::ARRAY) { |
142 } else if (mode.back() == Mode::ARRAY) { |
241 CBOR_CALLBACK_END |
257 CBOR_CALLBACK_END |
242 }; |
258 }; |
243 |
259 |
244 callbacks.tag = [](void* context, uint64_t value) { |
260 callbacks.tag = [](void* context, uint64_t value) { |
245 CBOR_CALLBACK_START |
261 CBOR_CALLBACK_START |
246 // TODO: implement |
262 instance->currentTag = value; |
247 xmlpp::Element* element = instance->current->add_child("tag"); |
263 instance->currentTagPresent = true; |
248 element->add_child_text(std::to_string(value)); |
|
249 CBOR_CALLBACK_END |
264 CBOR_CALLBACK_END |
250 }; |
265 }; |
251 |
266 |
252 callbacks.uint8 = NUMERIC_CALLBACK(uint8_t, "uint8"); |
267 callbacks.uint8 = NUMERIC_CALLBACK(uint8_t, "uint8"); |
253 callbacks.uint16 = NUMERIC_CALLBACK(uint16_t, "uint16"); |
268 callbacks.uint16 = NUMERIC_CALLBACK(uint16_t, "uint16"); |