1 | #include <DataTypes/DataTypeCustomSimpleTextSerialization.h> |
2 | |
3 | #include <IO/ReadBufferFromString.h> |
4 | #include <IO/ReadHelpers.h> |
5 | #include <IO/WriteBufferFromString.h> |
6 | #include <IO/WriteHelpers.h> |
7 | |
8 | namespace |
9 | { |
10 | using namespace DB; |
11 | |
12 | static String serializeToString(const DataTypeCustomSimpleTextSerialization & domain, const IColumn & column, size_t row_num, const FormatSettings & settings) |
13 | { |
14 | WriteBufferFromOwnString buffer; |
15 | domain.serializeText(column, row_num, buffer, settings); |
16 | |
17 | return buffer.str(); |
18 | } |
19 | |
20 | static void deserializeFromString(const DataTypeCustomSimpleTextSerialization & domain, IColumn & column, const String & s, const FormatSettings & settings) |
21 | { |
22 | ReadBufferFromString istr(s); |
23 | domain.deserializeText(column, istr, settings); |
24 | } |
25 | |
26 | } |
27 | |
28 | namespace DB |
29 | { |
30 | |
31 | DataTypeCustomSimpleTextSerialization::~DataTypeCustomSimpleTextSerialization() |
32 | { |
33 | } |
34 | |
35 | void DataTypeCustomSimpleTextSerialization::deserializeWholeText(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const |
36 | { |
37 | String str; |
38 | readString(str, istr); |
39 | deserializeFromString(*this, column, str, settings); |
40 | } |
41 | |
42 | void DataTypeCustomSimpleTextSerialization::serializeTextEscaped(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const |
43 | { |
44 | writeEscapedString(serializeToString(*this, column, row_num, settings), ostr); |
45 | } |
46 | |
47 | void DataTypeCustomSimpleTextSerialization::deserializeTextEscaped(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const |
48 | { |
49 | String str; |
50 | readEscapedString(str, istr); |
51 | deserializeFromString(*this, column, str, settings); |
52 | } |
53 | |
54 | void DataTypeCustomSimpleTextSerialization::serializeTextQuoted(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const |
55 | { |
56 | writeQuotedString(serializeToString(*this, column, row_num, settings), ostr); |
57 | } |
58 | |
59 | void DataTypeCustomSimpleTextSerialization::deserializeTextQuoted(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const |
60 | { |
61 | String str; |
62 | readQuotedString(str, istr); |
63 | deserializeFromString(*this, column, str, settings); |
64 | } |
65 | |
66 | void DataTypeCustomSimpleTextSerialization::serializeTextCSV(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const |
67 | { |
68 | writeCSVString(serializeToString(*this, column, row_num, settings), ostr); |
69 | } |
70 | |
71 | void DataTypeCustomSimpleTextSerialization::deserializeTextCSV(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const |
72 | { |
73 | String str; |
74 | readCSVString(str, istr, settings.csv); |
75 | deserializeFromString(*this, column, str, settings); |
76 | } |
77 | |
78 | void DataTypeCustomSimpleTextSerialization::serializeTextJSON(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const |
79 | { |
80 | writeJSONString(serializeToString(*this, column, row_num, settings), ostr, settings); |
81 | } |
82 | |
83 | void DataTypeCustomSimpleTextSerialization::deserializeTextJSON(IColumn & column, ReadBuffer & istr, const FormatSettings & settings) const |
84 | { |
85 | String str; |
86 | readJSONString(str, istr); |
87 | deserializeFromString(*this, column, str, settings); |
88 | } |
89 | |
90 | void DataTypeCustomSimpleTextSerialization::serializeTextXML(const IColumn & column, size_t row_num, WriteBuffer & ostr, const FormatSettings & settings) const |
91 | { |
92 | writeXMLString(serializeToString(*this, column, row_num, settings), ostr); |
93 | } |
94 | |
95 | } |
96 | |