1#pragma once
2#include <DataTypes/IDataType.h>
3
4namespace DB
5{
6
7/// Helper class to define same IDataType text (de)serialization for all the variants (escaped, quoted, JSON, CSV).
8/// You need to define serializeText() and deserializeText() in derived class.
9class DataTypeWithSimpleSerialization : public IDataType
10{
11protected:
12 DataTypeWithSimpleSerialization()
13 {}
14
15 void serializeTextEscaped(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override
16 {
17 serializeText(column, row_num, ostr, settings);
18 }
19
20 void serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override
21 {
22 serializeText(column, row_num, ostr, settings);
23 }
24
25 void serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override
26 {
27 serializeText(column, row_num, ostr, settings);
28 }
29
30 void serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const override
31 {
32 serializeText(column, row_num, ostr, settings);
33 }
34
35 void deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override
36 {
37 deserializeText(column, istr, settings);
38 }
39
40 void deserializeTextEscaped(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override
41 {
42 deserializeText(column, istr, settings);
43 }
44
45 void deserializeTextQuoted(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override
46 {
47 deserializeText(column, istr, settings);
48 }
49
50 void deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override
51 {
52 deserializeText(column, istr, settings);
53 }
54
55 void deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const override
56 {
57 deserializeText(column, istr, settings);
58 }
59
60 virtual void deserializeText(IColumn & column, ReadBuffer & istr, const FormatSettings &) const = 0;
61};
62
63}
64