send "text" and "data" attributes v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Tue, 15 Mar 2022 00:28:13 +0100
branchv_0
changeset 4 8a5b86415d80
parent 3 be6f2e307a65
child 5 5a6828cfad41
send "text" and "data" attributes
src/PosixMQHandler.h
--- a/src/PosixMQHandler.h	Fri Mar 04 21:30:08 2022 +0100
+++ b/src/PosixMQHandler.h	Tue Mar 15 00:28:13 2022 +0100
@@ -42,6 +42,23 @@
 	Configuration configuration;
 	shared_ptr<PosixMQ> mq;
 
+	struct CurrentRelation {
+		relpipe::common::type::StringX name;
+		std::vector<relpipe::reader::handlers::AttributeMetadata> attributes;
+		relpipe::common::type::Integer attributeIndex = 0;
+		std::string currentValue;
+	} currentRelation;
+
+	std::string formatText(relpipe::common::type::StringX value) {
+		// TODO: check valid UTF-8; if invalid, return only ASCII characters
+		return convertor.to_bytes(value);
+	}
+
+	std::string formatData(relpipe::common::type::StringX value) {
+		// TODO: decode HEX if type is string; return original octets if type is octet-string (not yet implemented)
+		return convertor.to_bytes(value);
+	}
+
 public:
 
 	PosixMQHandler(Configuration configuration) : configuration(configuration) {
@@ -49,12 +66,21 @@
 	}
 
 	void startRelation(relpipe::common::type::StringX name, std::vector<relpipe::reader::handlers::AttributeMetadata> attributes) override {
-
+		currentRelation = CurrentRelation{name, attributes};
 	}
 
 	void attribute(const relpipe::common::type::StringX& value) override {
-		// TODO: send only certain attributes
-		mq->send(convertor.to_bytes(value));
+
+		auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName();
+		if (attributeName == L"text") currentRelation.currentValue = formatText(value);
+		else if (attributeName == L"data") currentRelation.currentValue = formatData(value);
+
+		currentRelation.attributeIndex++;
+		if (currentRelation.attributeIndex == currentRelation.attributes.size()) {
+			currentRelation.attributeIndex = 0;
+			mq->send(currentRelation.currentValue);
+		}
+
 	}
 
 	void endOfPipe() {