reader only reads + refactoring v_0
authorFrantišek Kučera <franta-hg@frantovo.cz>
Sun, 15 Jul 2018 00:15:09 +0200
branchv_0
changeset 8 c87e9c84f7aa
parent 7 489e52138771
child 9 517888868e55
reader only reads + refactoring
include/RelpipeReaderException.h
nbproject/configurations.xml
src/BooleanDataType.h
src/BooleanDataTypeReader.h
src/DataTypeCatalog.h
src/DataTypeReader.cpp
src/DataTypeReaderCatalog.h
src/IntegerDataType.h
src/IntegerDataTypeReader.h
src/StringDataType.h
src/StringDataTypeReader.h
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/include/RelpipeReaderException.h	Sun Jul 15 00:15:09 2018 +0200
@@ -0,0 +1,26 @@
+#pragma once
+
+#include <string>
+
+#include "typedefs.h"
+
+namespace relpipe {
+namespace reader {
+
+class RelpipeReaderException {
+private:
+	string_t message;
+public:
+
+	RelpipeReaderException(string_t message) :
+	message(message) {
+	}
+
+	string_t getMessge() {
+		return message;
+	}
+
+};
+
+}
+}
\ No newline at end of file
--- a/nbproject/configurations.xml	Sat Jul 14 23:24:22 2018 +0200
+++ b/nbproject/configurations.xml	Sun Jul 15 00:15:09 2018 +0200
@@ -4,8 +4,13 @@
     <logicalFolder name="HeaderFiles"
                    displayName="Header Files"
                    projectFiles="true">
+      <itemPath>src/BooleanDataTypeReader.h</itemPath>
       <itemPath>include/DataTypeReader.h</itemPath>
       <itemPath>include/DataTypeReaderBase.h</itemPath>
+      <itemPath>src/DataTypeReaderCatalog.h</itemPath>
+      <itemPath>src/IntegerDataTypeReader.h</itemPath>
+      <itemPath>include/RelpipeReaderException.h</itemPath>
+      <itemPath>src/StringDataTypeReader.h</itemPath>
       <itemPath>src/format.h</itemPath>
       <itemPath>include/typedefs.h</itemPath>
     </logicalFolder>
@@ -45,12 +50,22 @@
       </item>
       <item path="include/DataTypeReaderBase.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="include/RelpipeReaderException.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="include/typedefs.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="src/BooleanDataTypeReader.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="src/DataTypeReader.cpp" ex="false" tool="1" flavor2="0">
       </item>
       <item path="src/DataTypeReaderBase.cpp" ex="false" tool="1" flavor2="0">
       </item>
+      <item path="src/DataTypeReaderCatalog.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="src/IntegerDataTypeReader.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="src/StringDataTypeReader.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="src/format.h" ex="false" tool="3" flavor2="0">
       </item>
     </conf>
@@ -78,12 +93,22 @@
       </item>
       <item path="include/DataTypeReaderBase.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="include/RelpipeReaderException.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="include/typedefs.h" ex="false" tool="3" flavor2="0">
       </item>
+      <item path="src/BooleanDataTypeReader.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="src/DataTypeReader.cpp" ex="false" tool="1" flavor2="0">
       </item>
       <item path="src/DataTypeReaderBase.cpp" ex="false" tool="1" flavor2="0">
       </item>
+      <item path="src/DataTypeReaderCatalog.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="src/IntegerDataTypeReader.h" ex="false" tool="3" flavor2="0">
+      </item>
+      <item path="src/StringDataTypeReader.h" ex="false" tool="3" flavor2="0">
+      </item>
       <item path="src/format.h" ex="false" tool="3" flavor2="0">
       </item>
     </conf>
--- a/src/BooleanDataType.h	Sat Jul 14 23:24:22 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,45 +0,0 @@
-#pragma once
-
-#include <string>
-#include <iostream>
-
-#include "DataType.h"
-#include "RelpipeException.h"
-
-using namespace std;
-
-namespace rp_prototype {
-
-class BooleanDataType : public DataType<bool> {
-private:
-	const wstring TRUE = L"true";
-	const wstring FALSE = L"false";
-public:
-
-	BooleanDataType() : DataType<bool>(DATA_TYPE_ID_BOOLEAN, DATA_TYPE_CODE_BOOLEAN) {
-	}
-
-	bool readValue(istream &input) override {
-		auto value = input.get(); // TODO: check failbit
-		if (value == 0) return false;
-		else if (value == 1) return true;
-		else throw RelpipeException(L"Unable to convert the octet to boolean", EXIT_CODE_DATA_ERROR);
-	}
-
-	void writeValue(ostream &output, const bool &value) override {
-		output.put(value ? 1 : 0);
-	}
-
-	bool toValue(const wstring &stringValue) override {
-		if (stringValue == TRUE) return true;
-		else if (stringValue == FALSE) return false;
-		else throw RelpipeException(L"Unable to convert the string to boolean", EXIT_CODE_DATA_ERROR);
-	}
-
-	wstring toString(const bool &value) override {
-		return value ? TRUE : FALSE;
-	}
-
-};
-
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/BooleanDataTypeReader.h	Sun Jul 15 00:15:09 2018 +0200
@@ -0,0 +1,37 @@
+#pragma once
+
+#include <string>
+#include <iostream>
+
+#include "../include/typedefs.h"
+#include "../include/DataTypeReader.h"
+#include "../include/DataTypeReader.h"
+#include "format.h"
+
+namespace relpipe {
+namespace reader {
+
+class BooleanDataTypeReader : public DataTypeReader<boolean_t> {
+private:
+	const string_t TRUE = L"true";
+	const string_t FALSE = L"false";
+public:
+
+	BooleanDataTypeReader() : DataTypeReader<boolean_t>(DATA_TYPE_ID_BOOLEAN, DATA_TYPE_CODE_BOOLEAN) {
+	}
+
+	bool readValue(std::istream &input) override {
+		auto value = input.get(); // TODO: check failbit
+		if (value == 0) return false;
+		else if (value == 1) return true;
+		else throw RelpipeReaderException(L"Unable to convert the octet to boolean");
+	}
+
+	string_t toString(const boolean_t &value) override {
+		return value ? TRUE : FALSE;
+	}
+
+};
+
+}
+}
\ No newline at end of file
--- a/src/DataTypeCatalog.h	Sat Jul 14 23:24:22 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,47 +0,0 @@
-#pragma once
-
-#include <string>
-#include <iostream>
-#include <vector>
-
-#include "common.h"
-#include "DataType.h"
-#include "BooleanDataType.h"
-#include "IntegerDataType.h"
-#include "StringDataType.h"
-
-using namespace std;
-
-namespace rp_prototype {
-
-class DataTypeCatalog {
-private:
-	BooleanDataType booleanType;
-	IntegerDataType integerType;
-	StringDataType stringType;
-	vector<DataTypeBase*> types = {&booleanType, &integerType, &stringType};
-public:
-
-	integer_t toTypeId(const wstring typeCode) {
-		for (DataTypeBase* dataType : types) if (dataType->supports(typeCode)) return dataType->getTypeId();
-		throw RelpipeException(L"Unsupported data type: " + typeCode, EXIT_CODE_DATA_ERROR);
-	}
-
-	wstring toTypeCode(const integer_t typeId) {
-		for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->getTypeCode();
-		throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR);
-	}
-
-	void writeString(ostream &output, const wstring &stringValue, const integer_t typeId) {
-		for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->writeString(output, stringValue);
-		throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR);
-	}
-
-	wstring readString(istream &input, const integer_t typeId) {
-		for (DataTypeBase* dataType : types) if (dataType->supports(typeId)) return dataType->readString(input);
-		throw RelpipeException(L"Unsupported data type: " + typeId, EXIT_CODE_DATA_ERROR);
-	}
-
-};
-
-}
\ No newline at end of file
--- a/src/DataTypeReader.cpp	Sat Jul 14 23:24:22 2018 +0200
+++ b/src/DataTypeReader.cpp	Sun Jul 15 00:15:09 2018 +0200
@@ -1,4 +1,5 @@
 #include "../include/DataTypeReader.h"
+#include "DataTypeReaderCatalog.h"
 
 namespace relpipe {
 namespace reader {
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/DataTypeReaderCatalog.h	Sun Jul 15 00:15:09 2018 +0200
@@ -0,0 +1,46 @@
+#pragma once
+
+#include <string>
+#include <iostream>
+#include <vector>
+
+#include "../include/typedefs.h"
+#include "../include/DataTypeReaderBase.h"
+#include "../include/RelpipeReaderException.h"
+
+#include "BooleanDataTypeReader.h"
+#include "IntegerDataTypeReader.h"
+#include "StringDataTypeReader.h"
+
+using namespace std;
+
+namespace relpipe {
+namespace reader {
+
+class DataTypeReaderCatalog {
+private:
+	BooleanDataTypeReader booleanReader;
+	IntegerDataTypeReader integerReader;
+	StringDataTypeReader stringReader;
+	vector<DataTypeReaderBase*> readers = {&booleanReader, &integerReader, &stringReader};
+public:
+
+	integer_t toTypeId(const wstring typeCode) {
+		for (DataTypeReaderBase* reader : readers) if (reader->supports(typeCode)) return reader->getTypeId();
+		throw RelpipeReaderException(L"Unsupported data type: " + typeCode);
+	}
+
+	wstring toTypeCode(const integer_t typeId) {
+		for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->getTypeCode();
+		throw RelpipeReaderException(L"Unsupported data type: " + typeId);
+	}
+
+	wstring readString(istream &input, const integer_t typeId) {
+		for (DataTypeReaderBase* reader : readers) if (reader->supports(typeId)) return reader->readString(input);
+		throw RelpipeReaderException(L"Unsupported data type: " + typeId);
+	}
+
+};
+
+}
+}
\ No newline at end of file
--- a/src/IntegerDataType.h	Sat Jul 14 23:24:22 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,131 +0,0 @@
-#pragma once
-
-#include <string>
-#include <iostream>
-#include <cassert>
-#include <limits>
-
-#include "common.h"
-#include "DataType.h"
-#include "RelpipeException.h"
-
-using namespace std;
-
-namespace rp_prototype {
-
-/**
- * The prototype does not have various integer and other numeric data types,
- * it just works with one type of integer.
- * But this integer has variable length -- smaller values occupy only one byte, bigger ones, more bytes 1,2,4,8 + first byte (contains length signalization).
- * In the real implementation of relational pipes, there will be DataTypes for particular numeric types.
- * 
- * TODO: support also big endian architectures.
- * TODO: throw exception if a value was stored in bigger type than needed (while reading – there should be only one supported way how to encode a single value)
- * 
- * Example of encoded values:
- * -------------------------------------------------------------------------------------------------
- * $ for n in 0 1 10 250 251 252 65535 65536 4294967295 4294967296 18446744073709551615; do printf '%20s = ' $n; dist/Debug/GNU-Linux/rp-prototype write integer $n | hd | head -n 1; done
- *                    0 = 00000000  00                                                |.|
- *                    1 = 00000000  01                                                |.|
- *                   10 = 00000000  0a                                                |.|
- *                  250 = 00000000  fa                                                |.|
- *                  251 = 00000000  fb fb                                             |..|
- *                  252 = 00000000  fb fc                                             |..|
- *                65535 = 00000000  fc ff ff                                          |...|
- *                65536 = 00000000  fd 00 00 01 00                                    |.....|
- *           4294967295 = 00000000  fd ff ff ff ff                                    |.....|
- *           4294967296 = 00000000  fe 00 00 00 00 01 00 00  00                       |.........|
- * 18446744073709551615 = 00000000  fe ff ff ff ff ff ff ff  ff                       |.........|
- * -------------------------------------------------------------------------------------------------
- * 
- * Example of decoded values:
- * -------------------------------------------------------------------------------------------------
- * $ for n in 0 1 10 250 251 252 65535 65536 4294967295 4294967296 18446744073709551615; do dist/Debug/GNU-Linux/rp-prototype write integer $n | dist/Debug/GNU-Linux/rp-prototype read integer; done;
- * 0
- * 1
- * 10
- * 250
- * 251
- * 252
- * 65535
- * 65536
- * 4294967295
- * 4294967296
- * 18446744073709551615
- * -------------------------------------------------------------------------------------------------
- * 
- * Note: similar format as original idea: https://en.wikipedia.org/wiki/X.690#Length_octets
- * 
- */
-class IntegerDataType : public DataType<integer_t> {
-private:
-	static const uint8_t INTEGER_TYPE_UINT8 = 251;
-	static const uint8_t INTEGER_TYPE_UINT16 = 252;
-	static const uint8_t INTEGER_TYPE_UINT32 = 253;
-	static const uint8_t INTEGER_TYPE_UINT64 = 254;
-	static const uint8_t INTEGER_TYPE_RESERVED = 255;
-
-	template<typename T> integer_t read(istream &input) {
-		T value = 0;
-		input.read(reinterpret_cast<char *> (&value), sizeof (value));
-		return value;
-	}
-
-	template<typename T> void write(ostream &output, const integer_t &value) {
-		assert(sizeof (T) <= sizeof (value));
-		output.write(reinterpret_cast<const char *> (&value), sizeof (T));
-	}
-
-	template<typename T> void write(ostream &output, const uint8_t type, const integer_t &value) {
-		write<uint8_t>(output, type);
-		write<T>(output, value);
-	}
-
-	template<typename T> bool fits(const integer_t &value) {
-		return value <= numeric_limits<T>::max();
-	}
-
-public:
-
-	IntegerDataType() : DataType<integer_t>(DATA_TYPE_ID_INTEGER, DATA_TYPE_CODE_INTEGER) {
-	}
-
-	integer_t readValue(istream &input) override {
-		uint8_t first;
-		input.read(reinterpret_cast<char *> (&first), sizeof (first));
-		if (input.good()) {
-
-			if (first < INTEGER_TYPE_UINT8) return first;
-			else if (first == INTEGER_TYPE_UINT8) return read<uint8_t>(input);
-			else if (first == INTEGER_TYPE_UINT16) return read<uint16_t>(input);
-			else if (first == INTEGER_TYPE_UINT32) return read<uint32_t>(input);
-			else if (first == INTEGER_TYPE_UINT64) return read<uint64_t>(input);
-			else throw RelpipeException(L"Error while parsing integer type: unsupported type", EXIT_CODE_DATA_ERROR);
-		} else {
-			throw RelpipeException(L"Error while reading integer from the stream.", EXIT_CODE_DATA_ERROR);
-		}
-	}
-
-	void writeValue(ostream &output, const integer_t &value) override {
-		// output << value; // by zapsalo číslo jako ASII text
-
-		if (value < INTEGER_TYPE_UINT8) write<uint8_t>(output, value);
-		else if (fits<uint8_t>(value)) write<uint8_t>(output, INTEGER_TYPE_UINT8, value);
-		else if (fits<uint16_t>(value)) write<uint16_t>(output, INTEGER_TYPE_UINT16, value);
-		else if (fits<uint32_t>(value)) write<uint32_t>(output, INTEGER_TYPE_UINT32, value);
-		else if (fits<uint64_t>(value)) write<uint64_t>(output, INTEGER_TYPE_UINT64, value);
-		else throw RelpipeException(L"Error while writing integer type: value too long", EXIT_CODE_DATA_ERROR);
-	}
-
-	integer_t toValue(const wstring &stringValue) override {
-		// throws „terminate called after throwing an instance of 'std::invalid_argument'“ SIGABRT, core dumped on invalid number
-		return stoul(stringValue);
-	}
-
-	wstring toString(const integer_t &value) override {
-		return to_wstring(value);
-	}
-
-};
-
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/IntegerDataTypeReader.h	Sun Jul 15 00:15:09 2018 +0200
@@ -0,0 +1,102 @@
+#pragma once
+
+#include <string>
+#include <iostream>
+#include <cassert>
+#include <limits>
+
+#include "../include/typedefs.h"
+#include "../include/DataTypeReader.h"
+#include "../include/DataTypeReader.h"
+#include "format.h"
+
+namespace relpipe {
+namespace reader {
+
+/**
+ * The prototype does not have various integer and other numeric data types,
+ * it just works with one type of integer.
+ * But this integer has variable length -- smaller values occupy only one byte, bigger ones, more bytes 1,2,4,8 + first byte (contains length signalization).
+ * In the real implementation of relational pipes, there will be DataTypes for particular numeric types.
+ * 
+ * TODO: support also big endian architectures.
+ * TODO: throw exception if a value was stored in bigger type than needed (while reading – there should be only one supported way how to encode a single value)
+ * 
+ * Example of encoded values:
+ * -------------------------------------------------------------------------------------------------
+ * $ for n in 0 1 10 250 251 252 65535 65536 4294967295 4294967296 18446744073709551615; do printf '%20s = ' $n; dist/Debug/GNU-Linux/rp-prototype write integer $n | hd | head -n 1; done
+ *                    0 = 00000000  00                                                |.|
+ *                    1 = 00000000  01                                                |.|
+ *                   10 = 00000000  0a                                                |.|
+ *                  250 = 00000000  fa                                                |.|
+ *                  251 = 00000000  fb fb                                             |..|
+ *                  252 = 00000000  fb fc                                             |..|
+ *                65535 = 00000000  fc ff ff                                          |...|
+ *                65536 = 00000000  fd 00 00 01 00                                    |.....|
+ *           4294967295 = 00000000  fd ff ff ff ff                                    |.....|
+ *           4294967296 = 00000000  fe 00 00 00 00 01 00 00  00                       |.........|
+ * 18446744073709551615 = 00000000  fe ff ff ff ff ff ff ff  ff                       |.........|
+ * -------------------------------------------------------------------------------------------------
+ * 
+ * Example of decoded values:
+ * -------------------------------------------------------------------------------------------------
+ * $ for n in 0 1 10 250 251 252 65535 65536 4294967295 4294967296 18446744073709551615; do dist/Debug/GNU-Linux/rp-prototype write integer $n | dist/Debug/GNU-Linux/rp-prototype read integer; done;
+ * 0
+ * 1
+ * 10
+ * 250
+ * 251
+ * 252
+ * 65535
+ * 65536
+ * 4294967295
+ * 4294967296
+ * 18446744073709551615
+ * -------------------------------------------------------------------------------------------------
+ * 
+ * Note: similar format as original idea: https://en.wikipedia.org/wiki/X.690#Length_octets
+ * 
+ */
+class IntegerDataTypeReader : public DataTypeReader<integer_t> {
+private:
+	static const uint8_t INTEGER_TYPE_UINT8 = 251;
+	static const uint8_t INTEGER_TYPE_UINT16 = 252;
+	static const uint8_t INTEGER_TYPE_UINT32 = 253;
+	static const uint8_t INTEGER_TYPE_UINT64 = 254;
+	static const uint8_t INTEGER_TYPE_RESERVED = 255;
+
+	template<typename T> integer_t read(std::istream &input) {
+		T value = 0;
+		input.read(reinterpret_cast<char *> (&value), sizeof (value));
+		return value;
+	}
+
+public:
+
+	IntegerDataTypeReader() : DataTypeReader<integer_t>(DATA_TYPE_ID_INTEGER, DATA_TYPE_CODE_INTEGER) {
+	}
+
+	integer_t readValue(std::istream &input) override {
+		uint8_t first;
+		input.read(reinterpret_cast<char *> (&first), sizeof (first));
+		if (input.good()) {
+
+			if (first < INTEGER_TYPE_UINT8) return first;
+			else if (first == INTEGER_TYPE_UINT8) return read<uint8_t>(input);
+			else if (first == INTEGER_TYPE_UINT16) return read<uint16_t>(input);
+			else if (first == INTEGER_TYPE_UINT32) return read<uint32_t>(input);
+			else if (first == INTEGER_TYPE_UINT64) return read<uint64_t>(input);
+			else throw RelpipeReaderException(L"Error while parsing integer type: unsupported type");
+		} else {
+			throw RelpipeReaderException(L"Error while reading integer from the stream.");
+		}
+	}
+
+	string_t toString(const integer_t &value) override {
+		return std::to_wstring(value);
+	}
+
+};
+
+}
+}
\ No newline at end of file
--- a/src/StringDataType.h	Sat Jul 14 23:24:22 2018 +0200
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,61 +0,0 @@
-#pragma once
-
-#include <string>
-#include <sstream>
-#include <iostream>
-#include <vector>
-#include <locale>
-#include <codecvt>
-
-#include "DataType.h"
-#include "RelpipeException.h"
-#include "IntegerDataType.h"
-
-using namespace std;
-
-namespace rp_prototype {
-
-/**
- * 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 StringDataType : public DataType<wstring> {
-private:
-	IntegerDataType integerType;
-	wstring_convert<codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
-public:
-
-	StringDataType() : DataType<wstring>(DATA_TYPE_ID_STRING, DATA_TYPE_CODE_STRING) {
-	}
-
-	wstring readValue(istream &input) override {
-		integer_t length = integerType.readValue(input);
-		// TODO: check maximum length of single field
-		// if (length > 4000) throw RelpipeException("data too long", EXIT_CODE_DATA_ERROR);
-		vector<char> buf(length);
-		input.read(buf.data(), length);
-		if (input.good()) {
-			return convertor.from_bytes(string(buf.data(), length));
-		} else {
-			throw RelpipeException(L"Error while reading string from the stream.", EXIT_CODE_DATA_ERROR);
-		}
-	}
-
-	void writeValue(ostream &output, const wstring &value) override {
-		string s = convertor.to_bytes(value);
-		integerType.writeValue(output, s.length());
-		output << s.c_str();
-	}
-
-	wstring toValue(const wstring &stringValue) override {
-		return stringValue;
-	}
-
-	wstring toString(const wstring &value) override {
-		return value;
-	}
-
-};
-
-}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/StringDataTypeReader.h	Sun Jul 15 00:15:09 2018 +0200
@@ -0,0 +1,52 @@
+#pragma once
+
+#include <string>
+#include <sstream>
+#include <iostream>
+#include <vector>
+#include <locale>
+#include <codecvt>
+
+#include "../include/typedefs.h"
+#include "../include/DataTypeReader.h"
+#include "../include/DataTypeReader.h"
+#include "format.h"
+
+namespace relpipe {
+namespace reader {
+
+/**
+ * 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 StringDataTypeReader : public DataTypeReader<string_t> {
+private:
+	IntegerDataTypeReader integerType;
+	std::wstring_convert<std::codecvt_utf8<wchar_t>> convertor; // TODO: support also other encodings.
+public:
+
+	StringDataTypeReader() : DataTypeReader<string_t>(DATA_TYPE_ID_STRING, DATA_TYPE_CODE_STRING) {
+	}
+
+	string_t readValue(std::istream &input) override {
+		integer_t length = integerType.readValue(input);
+		// TODO: check maximum length of single field
+		// if (length > 4000) throw RelpipeException("data too long", EXIT_CODE_DATA_ERROR);
+		std::vector<char> buf(length);
+		input.read(buf.data(), length);
+		if (input.good()) {
+			return convertor.from_bytes(std::string(buf.data(), length));
+		} else {
+			throw RelpipeReaderException(L"Error while reading string from the stream.");
+		}
+	}
+
+	string_t toString(const string_t &value) override {
+		return value;
+	}
+
+};
+
+}
+}
\ No newline at end of file