equal
deleted
inserted
replaced
30 #include <relpipe/writer/Factory.h> |
30 #include <relpipe/writer/Factory.h> |
31 |
31 |
32 #include <relpipe/cli/RelpipeCLIException.h> |
32 #include <relpipe/cli/RelpipeCLIException.h> |
33 |
33 |
34 #include "Configuration.h" |
34 #include "Configuration.h" |
|
35 #include "Hex.h" |
35 |
36 |
36 namespace relpipe { |
37 namespace relpipe { |
37 namespace tr { |
38 namespace tr { |
38 namespace serialize { |
39 namespace serialize { |
39 |
40 |
54 public: |
55 public: |
55 std::stringstream buffer; |
56 std::stringstream buffer; |
56 shared_ptr<relpipe::writer::RelationalWriter> writer; |
57 shared_ptr<relpipe::writer::RelationalWriter> writer; |
57 size_t attributeIndex = 0; |
58 size_t attributeIndex = 0; |
58 } recordContext; |
59 } recordContext; |
59 |
|
60 relpipe::common::type::StringX toHex(const std::string& octets) { |
|
61 std::stringstream hex; |
|
62 hex << std::hex << std::setfill('0') << std::hex; |
|
63 for (size_t i = 0, size = octets.size(); i < size; i++) hex << std::setw(2) << (0xff & octets[i]); |
|
64 return convertor.from_bytes(hex.str()); |
|
65 } |
|
66 |
60 |
67 public: |
61 public: |
68 |
62 |
69 SerializeHandler(shared_ptr<relpipe::writer::RelationalWriter> writer, Configuration configuration) : writer(writer), configuration(configuration) { |
63 SerializeHandler(shared_ptr<relpipe::writer::RelationalWriter> writer, Configuration configuration) : writer(writer), configuration(configuration) { |
70 // TODO: configurable relation name |
64 // TODO: configurable relation name |
101 |
95 |
102 recordContext.writer->writeAttribute(value, type); |
96 recordContext.writer->writeAttribute(value, type); |
103 recordContext.attributeIndex++; |
97 recordContext.attributeIndex++; |
104 |
98 |
105 if (recordContext.attributeIndex % relationContext.readerMetadata.size() == 0) { |
99 if (recordContext.attributeIndex % relationContext.readerMetadata.size() == 0) { |
106 writer->writeAttribute(toHex(recordContext.buffer.str())); |
100 writer->writeAttribute(Hex::toHex(recordContext.buffer.str())); |
107 recordContext.attributeIndex = 0; |
101 recordContext.attributeIndex = 0; |
108 } |
102 } |
109 } |
103 } |
110 |
104 |
111 void endOfPipe() { |
105 void endOfPipe() { |