@@ -62,6 +62,8 @@ void Serializer::setSerializerMethods() {
62
62
setSerializerMethod (data::mapping::type::__class::Float64::CLASS_ID, &Serializer::serializeFloat64);
63
63
setSerializerMethod (data::mapping::type::__class::Boolean::CLASS_ID, &Serializer::serializeBoolean);
64
64
65
+ setSerializerMethod (data::mapping::type::__class::AbstractEnum::CLASS_ID, &Serializer::serializeEnum);
66
+
65
67
// //
66
68
67
69
setSerializerMethod (postgresql::mapping::type::__class::Uuid::CLASS_ID, &Serializer::serializeUuid);
@@ -89,6 +91,8 @@ void Serializer::setTypeOidMethods() {
89
91
setTypeOidMethod (data::mapping::type::__class::Float64::CLASS_ID, &Serializer::getTypeOid<FLOAT8OID>);
90
92
setTypeOidMethod (data::mapping::type::__class::Boolean::CLASS_ID, &Serializer::getTypeOid<BOOLOID>);
91
93
94
+ setTypeOidMethod (data::mapping::type::__class::AbstractEnum::CLASS_ID, &Serializer::getEnumTypeOid);
95
+
92
96
// //
93
97
94
98
setTypeOidMethod (postgresql::mapping::type::__class::Uuid::CLASS_ID, &Serializer::getTypeOid<UUIDOID>);
@@ -117,7 +121,7 @@ void Serializer::serialize(OutputData& outData, const oatpp::Void& polymorph) co
117
121
auto id = polymorph.valueType ->classId .id ;
118
122
auto & method = m_methods[id];
119
123
if (method) {
120
- (*method)(outData, polymorph);
124
+ (*method)(this , outData, polymorph);
121
125
} else {
122
126
throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serialize()]: "
123
127
" Error. No serialize method for type '" + std::string (polymorph.valueType ->classId .name ) +
@@ -180,7 +184,10 @@ void Serializer::serInt8(OutputData& outData, v_int64 value) {
180
184
// //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
181
185
// Serializer functions
182
186
183
- void Serializer::serializeString (OutputData& outData, const oatpp::Void& polymorph) {
187
+ void Serializer::serializeString (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
188
+
189
+ (void ) _this;
190
+
184
191
if (polymorph) {
185
192
base::StrBuffer *buff = static_cast <base::StrBuffer *>(polymorph.get ());
186
193
outData.data = (char *)buff->getData ();
@@ -192,7 +199,10 @@ void Serializer::serializeString(OutputData& outData, const oatpp::Void& polymor
192
199
}
193
200
}
194
201
195
- void Serializer::serializeInt8 (OutputData& outData, const oatpp::Void& polymorph) {
202
+ void Serializer::serializeInt8 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
203
+
204
+ (void ) _this;
205
+
196
206
if (polymorph) {
197
207
auto v = polymorph.staticCast <oatpp::Int8>();
198
208
serInt2 (outData, *v);
@@ -202,7 +212,10 @@ void Serializer::serializeInt8(OutputData& outData, const oatpp::Void& polymorph
202
212
}
203
213
}
204
214
205
- void Serializer::serializeUInt8 (OutputData& outData, const oatpp::Void& polymorph) {
215
+ void Serializer::serializeUInt8 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
216
+
217
+ (void ) _this;
218
+
206
219
if (polymorph) {
207
220
auto v = polymorph.staticCast <oatpp::UInt8>();
208
221
serInt2 (outData, *v);
@@ -212,7 +225,10 @@ void Serializer::serializeUInt8(OutputData& outData, const oatpp::Void& polymorp
212
225
}
213
226
}
214
227
215
- void Serializer::serializeInt16 (OutputData& outData, const oatpp::Void& polymorph) {
228
+ void Serializer::serializeInt16 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
229
+
230
+ (void ) _this;
231
+
216
232
if (polymorph) {
217
233
auto v = polymorph.staticCast <oatpp::Int16>();
218
234
serInt2 (outData, *v);
@@ -222,7 +238,10 @@ void Serializer::serializeInt16(OutputData& outData, const oatpp::Void& polymorp
222
238
}
223
239
}
224
240
225
- void Serializer::serializeUInt16 (OutputData& outData, const oatpp::Void& polymorph) {
241
+ void Serializer::serializeUInt16 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
242
+
243
+ (void ) _this;
244
+
226
245
if (polymorph) {
227
246
auto v = polymorph.staticCast <oatpp::UInt16>();
228
247
serInt4 (outData, *v);
@@ -232,7 +251,10 @@ void Serializer::serializeUInt16(OutputData& outData, const oatpp::Void& polymor
232
251
}
233
252
}
234
253
235
- void Serializer::serializeInt32 (OutputData& outData, const oatpp::Void& polymorph) {
254
+ void Serializer::serializeInt32 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
255
+
256
+ (void ) _this;
257
+
236
258
if (polymorph) {
237
259
auto v = polymorph.staticCast <oatpp::Int32>();
238
260
serInt4 (outData, *v);
@@ -242,7 +264,10 @@ void Serializer::serializeInt32(OutputData& outData, const oatpp::Void& polymorp
242
264
}
243
265
}
244
266
245
- void Serializer::serializeUInt32 (OutputData& outData, const oatpp::Void& polymorph) {
267
+ void Serializer::serializeUInt32 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
268
+
269
+ (void ) _this;
270
+
246
271
if (polymorph) {
247
272
auto v = polymorph.staticCast <oatpp::UInt32>();
248
273
serInt8 (outData, *v);
@@ -252,7 +277,10 @@ void Serializer::serializeUInt32(OutputData& outData, const oatpp::Void& polymor
252
277
}
253
278
}
254
279
255
- void Serializer::serializeInt64 (OutputData& outData, const oatpp::Void& polymorph) {
280
+ void Serializer::serializeInt64 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
281
+
282
+ (void ) _this;
283
+
256
284
if (polymorph) {
257
285
auto v = polymorph.staticCast <oatpp::Int64>();
258
286
serInt8 (outData, *v);
@@ -262,11 +290,17 @@ void Serializer::serializeInt64(OutputData& outData, const oatpp::Void& polymorp
262
290
}
263
291
}
264
292
265
- void Serializer::serializeUInt64 (OutputData& outData, const oatpp::Void& polymorph) {
293
+ void Serializer::serializeUInt64 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
294
+ (void ) _this;
295
+ (void ) outData;
296
+ (void ) polymorph;
266
297
throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serializeUInt64()]: Error. Not implemented!" );
267
298
}
268
299
269
- void Serializer::serializeFloat32 (OutputData& outData, const oatpp::Void& polymorph) {
300
+ void Serializer::serializeFloat32 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
301
+
302
+ (void ) _this;
303
+
270
304
if (polymorph) {
271
305
auto v = polymorph.staticCast <oatpp::Float32>();
272
306
serInt4 (outData, *((p_int32) v.get ()));
@@ -276,7 +310,10 @@ void Serializer::serializeFloat32(OutputData& outData, const oatpp::Void& polymo
276
310
}
277
311
}
278
312
279
- void Serializer::serializeFloat64 (OutputData& outData, const oatpp::Void& polymorph) {
313
+ void Serializer::serializeFloat64 (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
314
+
315
+ (void ) _this;
316
+
280
317
if (polymorph) {
281
318
auto v = polymorph.staticCast <oatpp::Float64>();
282
319
serInt8 (outData, *((p_int64) v.get ()));
@@ -286,7 +323,10 @@ void Serializer::serializeFloat64(OutputData& outData, const oatpp::Void& polymo
286
323
}
287
324
}
288
325
289
- void Serializer::serializeBoolean (OutputData& outData, const oatpp::Void& polymorph) {
326
+ void Serializer::serializeBoolean (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
327
+
328
+ (void ) _this;
329
+
290
330
if (polymorph) {
291
331
auto v = polymorph.staticCast <oatpp::Boolean>();
292
332
outData.dataBuffer .reset (new char [1 ]);
@@ -300,7 +340,44 @@ void Serializer::serializeBoolean(OutputData& outData, const oatpp::Void& polymo
300
340
}
301
341
}
302
342
303
- void Serializer::serializeUuid (OutputData& outData, const oatpp::Void& polymorph) {
343
+ void Serializer::serializeEnum (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
344
+
345
+ auto polymorphicDispatcher = static_cast <const data::mapping::type::__class::AbstractEnum::PolymorphicDispatcher*>(
346
+ polymorph.valueType ->polymorphicDispatcher
347
+ );
348
+
349
+ data::mapping::type::EnumInterpreterError e = data::mapping::type::EnumInterpreterError::OK;
350
+ const auto & enumInterpretation = polymorphicDispatcher->toInterpretation (polymorph, e);
351
+
352
+ if (e == data::mapping::type::EnumInterpreterError::OK) {
353
+ _this->serialize (outData, enumInterpretation);
354
+ return ;
355
+ }
356
+
357
+ switch (e) {
358
+ case data::mapping::type::EnumInterpreterError::CONSTRAINT_NOT_NULL:
359
+ throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serializeEnum()]: Error. Enum constraint violated - 'NotNull'." );
360
+ default :
361
+ throw std::runtime_error (" [oatpp::postgresql::mapping::Serializer::serializeEnum()]: Error. Can't serialize Enum." );
362
+ }
363
+
364
+ }
365
+
366
+ Oid Serializer::getEnumTypeOid (const Serializer* _this, const oatpp::Type* type) {
367
+
368
+ auto polymorphicDispatcher = static_cast <const data::mapping::type::__class::AbstractEnum::PolymorphicDispatcher*>(
369
+ type->polymorphicDispatcher
370
+ );
371
+
372
+ const oatpp::Type* enumInterType = polymorphicDispatcher->getInterpretationType ();
373
+ return _this->getTypeOid (enumInterType);
374
+
375
+ }
376
+
377
+ void Serializer::serializeUuid (const Serializer* _this, OutputData& outData, const oatpp::Void& polymorph) {
378
+
379
+ (void ) _this;
380
+
304
381
if (polymorph) {
305
382
auto v = polymorph.staticCast <postgresql::Uuid>();
306
383
outData.data = (char *) v->getData ();
0 commit comments