src/PosixMQCommand.cpp
branchv_0
changeset 4 f9d43c5adae9
parent 3 b71fc3b5e56b
child 5 c6ef2463e100
equal deleted inserted replaced
3:b71fc3b5e56b 4:f9d43c5adae9
    19 #include <memory>
    19 #include <memory>
    20 #include <locale>
    20 #include <locale>
    21 #include <regex>
    21 #include <regex>
    22 #include <algorithm>
    22 #include <algorithm>
    23 #include <unistd.h>
    23 #include <unistd.h>
       
    24 #include <sstream>
       
    25 #include <iomanip>
    24 
    26 
    25 #include <relpipe/writer/RelationalWriter.h>
    27 #include <relpipe/writer/RelationalWriter.h>
    26 #include <relpipe/writer/RelpipeWriterException.h>
    28 #include <relpipe/writer/RelpipeWriterException.h>
    27 #include <relpipe/writer/AttributeMetadata.h>
    29 #include <relpipe/writer/AttributeMetadata.h>
    28 #include <relpipe/writer/Factory.h>
    30 #include <relpipe/writer/Factory.h>
    46 
    48 
    47 	std::shared_ptr<PosixMQ> mq(PosixMQ::open(convertor.to_bytes(configuration.queue), configuration.unlinkOnClose));
    49 	std::shared_ptr<PosixMQ> mq(PosixMQ::open(convertor.to_bytes(configuration.queue), configuration.unlinkOnClose));
    48 
    50 
    49 	writer->startRelation(configuration.relation,{
    51 	writer->startRelation(configuration.relation,{
    50 		{L"queue", TypeId::STRING},
    52 		{L"queue", TypeId::STRING},
    51 		{L"message", TypeId::STRING}
    53 		{L"text", TypeId::STRING},
       
    54 		{L"data", TypeId::STRING}
    52 	}, true);
    55 	}, true);
    53 
    56 
    54 	for (int i = configuration.messageCount; i > 0; i--) {
    57 	for (int i = configuration.messageCount; i > 0; i--) {
       
    58 		std::string message = mq->receive();
       
    59 
       
    60 		std::stringstream hex;
       
    61 		hex << std::hex << std::setfill('0');
       
    62 		for (uint8_t b : message) hex << std::setw(2) << (int) b;
       
    63 
    55 		writer->writeAttribute(configuration.queue);
    64 		writer->writeAttribute(configuration.queue);
    56 		writer->writeAttribute(convertor.from_bytes(mq->receive()));
    65 		writer->writeAttribute(convertor.from_bytes(message)); // Show at least ASCII characters + ... if UTF-8 decoding fails
       
    66 		writer->writeAttribute(convertor.from_bytes(hex.str()));
    57 	}
    67 	}
    58 
    68 
    59 }
    69 }
    60 
    70 
    61 PosixMQCommand::~PosixMQCommand() {
    71 PosixMQCommand::~PosixMQCommand() {