# HG changeset patch # User František Kučera # Date 1647300493 -3600 # Node ID 8a5b86415d8085936f85caf09ce77fd1eba4192c # Parent be6f2e307a651c32f1015eb20aa175925f5fab28 send "text" and "data" attributes diff -r be6f2e307a65 -r 8a5b86415d80 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 mq; + struct CurrentRelation { + relpipe::common::type::StringX name; + std::vector 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 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() {