Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

API question: other types #3

Open
dsmyth opened this issue Dec 30, 2020 · 3 comments
Open

API question: other types #3

dsmyth opened this issue Dec 30, 2020 · 3 comments
Labels
enhancement New feature or request

Comments

@dsmyth
Copy link
Contributor

dsmyth commented Dec 30, 2020

In file: oatpp-postgresql/Types.hpp

Question

What is your roadmap for supporting other types? I'm particularly interested in json, jsonb and arrays (of floats).

Thanks -- Don

@lganzzzo
Copy link
Member

Hello @dsmyth ,

Just updated the readme with the list of supported data-types. :)

What is your roadmap for supporting other types? I'm particularly interested in json, jsonb and arrays (of floats).

At the moment there is no roadmap for this.
A better types-support will be developed dynamically based on community requests/PRs/and ease of implementation.

My estimations:

  • Arrays - easy - might be added pretty soon (others also asked for array support).
  • JSON - hard - investigation needed.
  • JSONB - hard - investigation needed.

Also, if you'd like to contribute - I'll provide the necessary assistance.

Best Regards,
Leonid

@lganzzzo lganzzzo added the enhancement New feature or request label Dec 30, 2020
@dsmyth
Copy link
Contributor Author

dsmyth commented Jan 1, 2021

I'm willing to try adding arrays -- my current need is a float4 array.
If I catch it in the deserializer, I can see my data in memory:
In pgsql:

twdb=# select boxbounds from captures where captureid=1;
        boxbounds        
-------------------------
 {0,1.1,2.2,3.3,4.4,5.5}

In gdb:

(gdb) x/68xb data.data
0x7f45c40f8740:	0x00	0x00	0x00	0x01	0x00	0x00	0x00	0x00
0x7f45c40f8748:	0x00	0x00	0x02	0xbc	0x00	0x00	0x00	0x06
0x7f45c40f8750:	0x00	0x00	0x00	0x01	0x00	0x00	0x00	0x04
0x7f45c40f8758:	0x00	0x00	0x00	0x00	0x00	0x00	0x00	0x04
0x7f45c40f8760:	0x3f	0x8c	0xcc	0xcd	0x00	0x00	0x00	0x04
0x7f45c40f8768:	0x40	0x0c	0xcc	0xcd	0x00	0x00	0x00	0x04
0x7f45c40f8770:	0x40	0x53	0x33	0x33	0x00	0x00	0x00	0x04
0x7f45c40f8778:	0x40	0x8c	0xcc	0xcd	0x00	0x00	0x00	0x04
0x7f45c40f8780:	0x40	0xb0	0x00	0x00

Offset 58, 68, 70, 78 and 80 are the IEEE754 representation of the 4 byte floating point numbers in the field. Can you point me to how to parse this data structure?

Here's my start at adding the deserializer method:

oatpp::Void Deserializer::deserializeArray(const Deserializer* _this, const InData& data, const Type* type) {

    (void) _this;
    (void) type;

    switch(data.oid) {
        case FLOAT4ARRAYOID: return oatpp::Vector<Float32>();
        case FLOAT8ARRAYOID: return oatpp::Vector<Float64>();
    }

    if(data.isNull) {
        return oatpp::postgresql::Uuid();
    }

    return postgresql::Uuid((p_char8)data.data);
}

@lganzzzo
Copy link
Member

lganzzzo commented Jan 1, 2021

Hey @dsmyth ,

Please create a draft PR so that we can collaborate on this feature.

Can you point me to how to parse this data structure?

First, let's start by creating a template method for parsing arrays to oatpp::Vector, oatpp::List, oatpp::UnorderedSet.
We ganna have a template method because functionality will be mostly the same:

Let's use JSON deserializer as a reference - See JSON array deserialization

template<class Collection> 
oatpp::Void Deserializer::deserializeArray(const Deserializer* _this, const InData& data, const Type* type) {

  auto polymorphicDispatcher = static_cast<const typename Collection::Class::PolymorphicDispatcher*>(type->polymorphicDispatcher);
  
  auto itemType = *type->params.begin(); // Get "wanted" type of the list item

  // TODO - check that wanted itemType is compatible with the data OID item type.

  if(data.isNull) {
    // return nullptr with the type. - after we've checked the type.
    return oatpp::Void(nullptr, type);
  }

  auto listWrapper = polymorphicDispatcher->createObject(); // Instantiate list of the "wanted" type
  const auto& list = listWrapper.template staticCast<Collection>();

  // TODO - read "InData data" and push items to list

  return list;

}

Then, reference this method by referencing it here - https://github.com/oatpp/oatpp-postgresql/blob/master/src/oatpp-postgresql/mapping/Deserializer.cpp#L72 - for Vector, List, and UnorderedSet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants