mirror of
https://github.com/oatpp/oatpp-postgresql.git
synced 2024-12-15 03:19:54 +08:00
Remove obsolete DeserializeArray, move arpa/inet.h include to
Deserializer.hpp
This commit is contained in:
parent
54bf0a958c
commit
5301580346
@ -28,12 +28,6 @@
|
||||
#include "PgArray.hpp"
|
||||
#include "oatpp-postgresql/Types.hpp"
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
#include <WinSock2.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
namespace oatpp { namespace postgresql { namespace mapping {
|
||||
|
||||
Deserializer::InData::InData(PGresult* dbres, int row, int col, const std::shared_ptr<const data::mapping::TypeResolver>& pTypeResolver) {
|
||||
@ -333,65 +327,4 @@ oatpp::Void Deserializer::deserializeUuid(const Deserializer* _this, const InDat
|
||||
|
||||
}
|
||||
|
||||
oatpp::Void Deserializer::deserializeArray(const Deserializer* _this, const InData& data, const Type* type) {
|
||||
|
||||
(void) _this;
|
||||
(void) type;
|
||||
|
||||
// Place to put our data
|
||||
oatpp::Void retval = nullptr;
|
||||
|
||||
// see if we handle this type
|
||||
switch (data.oid) {
|
||||
case FLOAT8ARRAYOID:
|
||||
break;
|
||||
default:
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::Deserializer::deserializeArray()]: Unhandled array type.");
|
||||
}
|
||||
|
||||
// parse out the array
|
||||
if (!data.isNull) {
|
||||
auto *pgArray = reinterpret_cast<const PgArray *>(data.data);
|
||||
|
||||
// everything is in network order!!!
|
||||
// only handle 1d array for now
|
||||
if (ntohl(pgArray->header.ndim) > 1) {
|
||||
throw std::runtime_error("[oatpp::postgresql::mapping::Deserializer::deserializeArray()]: Dimension > 1");
|
||||
}
|
||||
|
||||
// make sure data is the right type
|
||||
if (ntohl(pgArray->header.oid) == FLOAT8OID) {
|
||||
// build the array
|
||||
auto vec = oatpp::Vector<Float64>::createShared();
|
||||
auto nElem = ntohl(pgArray->header.size);
|
||||
for (int i = 0; i < nElem; i++) {
|
||||
// get element size, point to element data
|
||||
auto elemSize = ntohl(pgArray->elem[i].size);
|
||||
// quit if we get an empty element
|
||||
if (elemSize == 0) {
|
||||
break;
|
||||
}
|
||||
// make sure element size matches the data size
|
||||
if (elemSize != sizeof(v_float64)) {
|
||||
throw std::runtime_error(
|
||||
"[oatpp::postgresql::mapping::Deserializer::deserializeArray()]: Bad element size");
|
||||
}
|
||||
// get the 64 bit host order data, pointing to next element
|
||||
// TODO: make sure this matches element size
|
||||
v_int64 l1 = ntohl(pgArray->elem[i].value[0]);
|
||||
v_int64 l2 = ntohl(pgArray->elem[i].value[1]);
|
||||
v_int64 intVal = (l1 << 32) | l2 ;
|
||||
v_float64 val = *reinterpret_cast<p_float64>(&intVal);
|
||||
vec->push_back(val);
|
||||
}
|
||||
retval = vec;
|
||||
} else {
|
||||
throw std::runtime_error(
|
||||
"[oatpp::postgresql::mapping::Deserializer::deserializeArray()]: Unhandled array value type.");
|
||||
}
|
||||
}
|
||||
|
||||
return retval;
|
||||
}
|
||||
|
||||
}}}
|
||||
|
@ -32,6 +32,12 @@
|
||||
|
||||
#include <libpq-fe.h>
|
||||
|
||||
#if defined(WIN32) || defined(_WIN32)
|
||||
#include <WinSock2.h>
|
||||
#else
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
namespace oatpp { namespace postgresql { namespace mapping {
|
||||
|
||||
/**
|
||||
@ -100,8 +106,6 @@ private:
|
||||
|
||||
static oatpp::Void deserializeUuid(const Deserializer* _this, const InData& data, const Type* type);
|
||||
|
||||
static oatpp::Void deserializeArray(const Deserializer* _this, const InData& data, const Type* type);
|
||||
|
||||
template<class Collection>
|
||||
static oatpp::Void deserializeArray2(const Deserializer* _this, const InData& data, const Type* type) {
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user