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

Support for vectors of int16/32/64 #50

Open
black-inc-service opened this issue Sep 5, 2024 · 3 comments
Open

Support for vectors of int16/32/64 #50

black-inc-service opened this issue Sep 5, 2024 · 3 comments
Labels
enhancement New feature or request

Comments

@black-inc-service
Copy link

Looking at the schema example:
https://github.com/objectbox/objectbox-generator/blob/main/test/comparison/testdata/fbs/typeful/schema.fbs
There is only support for vector of string, byte, ubyte and recently float in v4 beat.
Are there plans to support vector of: int16, int32, int64, uint16, uint32 and uint64.

I have a system that needs a vector of uint64 and have had to resort to using a vector of strings and perform conversion when reading and writing to this field, this is not ideal. Would rather not have to create a new table and have each row store one item of the vector and make a relationship to the parent table.

@greenrobot
Copy link
Member

Yes, there are plans to support all vector types.

vector of uint64 and have had to resort to using a vector of strings

or a byte vector; may be easier (just a cast)?

@greenrobot greenrobot added the enhancement New feature or request label Sep 5, 2024
@greenrobot greenrobot changed the title Is there planned support for vector of int16/32/64 Support for vectors of int16/32/64 Sep 5, 2024
@black-inc-service
Copy link
Author

Not sure what you mean by casting.
I tried a byte vector and objectbox-generator creates in database.obx.hpp:

struct TestTable{
    ...
    std::vector<int8_t> testvector;
};

Test code, note: int8_t range: −128 to +127

TestTable record = {};
record.testvector.emplace_back(100); // In range of int8_t
record.testvector.emplace_back(999); // out of range of int8_t
obx_id id = testTable.put(record);
testTable.get(id); // print contents of testvector

After putting this in table and reading back get: 100 and 231(999 overflow as expected)

std::vector<int8_t> cannot be cast to std::vector<uint32_t>
I'm getting overflow behavior (which is what I expected), getting
(uint32_t)testvector[1] equals 4294967271, not 999 as the other bits are set to 1 in this case

Vector support for the other datatypes would be most appreciate.

@greenrobot
Copy link
Member

You need to look at this from the memory perspective; anything is stored in memory, and C/C++ gives you flexibility what is stored in memory.

Example:

std::vector<int8_t> testvector{42, 0, 0, 0, 0, 0, 0, 0, -128, 0, 0, 0, 0, 0, 0, 0};  // 16 bytes
uint64_t* ptr = (uint64_t*) testvector.data();
size_t size = testvector.size() / sizeof(uint64_t);
assert(size == 2);
assert(ptr[0] == 42);
assert(ptr[1] == 255);

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