diff -r 01dd90eeedbb -r 03750aff8619 src/StringDataTypeWriter.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/StringDataTypeWriter.h Sun Jul 15 00:45:21 2018 +0200 @@ -0,0 +1,43 @@ +#pragma once + +#include +#include +#include +#include +#include +#include + +#include "../include/DataTypeWriter.h" +#include "format.h" + +namespace relpipe { +namespace writer { + +/** + * The prototype does not recognize any encoding, + * it just works with c++ strings in encoding default to given platform. + * In the real implementation of relational pipes, there will be DataTypes for particular encodings. + */ +class StringDataTypeWriter : public DataTypeWriter { +private: + IntegerDataTypeWriter integerType; + std::wstring_convert> convertor; // TODO: support also other encodings. +public: + + StringDataTypeWriter() : DataTypeWriter(DATA_TYPE_ID_STRING, DATA_TYPE_CODE_STRING) { + } + + void writeValue(std::ostream &output, const string_t &value) override { + std::string s = convertor.to_bytes(value); + integerType.writeValue(output, s.length()); + output << s.c_str(); + } + + wstring toValue(const string_t &stringValue) override { + return stringValue; + } + +}; + +} +} \ No newline at end of file