use 'text' or 'data' attribute according to presence of value v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sat, 30 Apr 2022 23:22:48 +0200
branchv_0
changeset 7 68b93b82f1cc
parent 6 b0b7b6f1bc88
child 8 9f89ecc071bf
use 'text' or 'data' attribute according to presence of value
src/PosixMQHandler.h
--- a/src/PosixMQHandler.h	Wed Apr 20 20:59:48 2022 +0200
+++ b/src/PosixMQHandler.h	Sat Apr 30 23:22:48 2022 +0200
@@ -53,6 +53,7 @@
 public:
 
 	PosixMQHandler(Configuration configuration) : configuration(configuration) {
+		// TODO: do not throw exception from the constructor: PosixMQ::open()
 		mq.reset(PosixMQ::open(convertor.to_bytes(configuration.queue), configuration.unlinkOnClose));
 	}
 
@@ -63,8 +64,10 @@
 	void attribute(const relpipe::common::type::StringX& value) override {
 
 		auto attributeName = currentRelation.attributes[currentRelation.attributeIndex].getAttributeName();
-		if (attributeName == L"text") currentRelation.currentValue = convertor.to_bytes(value);
-		else if (attributeName == L"data") currentRelation.currentValue = Hex::fromHex(value).str();
+		if (attributeName == L"text" && value.size()) currentRelation.currentValue = convertor.to_bytes(value);
+		else if (attributeName == L"data" && value.size()) currentRelation.currentValue = Hex::fromHex(value).str();
+		else if (attributeName == L"text"); // keep empty or value from 'data'
+		else if (attributeName == L"data"); // keep empty or value from 'text'
 
 		currentRelation.attributeIndex++;
 		if (currentRelation.attributeIndex == currentRelation.attributes.size()) {