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

rocksdb and yas #151

Open
Martin-Lierschof opened this issue Dec 20, 2023 · 1 comment
Open

rocksdb and yas #151

Martin-Lierschof opened this issue Dec 20, 2023 · 1 comment

Comments

@Martin-Lierschof
Copy link

rocksdb is really sometimes of a good serialization techique. Here yas can really shine in combination with rocksdb:slice.

rocksdb slice is functionally the same as yas::intrusive_buffer, so just to let you know and maybe put it in the documentation.

deserialization:

template <typename T>
T deserializeYas(const rocksdb::Slice& slice)
{
    T instance;
    if (slice->empty()) {
        return instance;
    }
    const yas::intrusive_buffer buf(slice.data(), slice.size());
    yas::load<yas::binary | yas::mem>(buf, instance);
    return instance;
}
const rocksdb::Slice sliceIn
MYSuperObject mysuperobject= rocksdb_tools::deserializeYas<std::vector<MYSuperObject >>(sliceIn);

serialization:

 template <typename T>
void serializeYas(const T& instance, yas::shared_buffer& buf)
{
      buf = yas::save<yas::binary | yas::mem>(instance);
}
yas::shared_buffer buf;
rocksdb_tools::serializeYas<MYSuperObject>(mysuperobject, buf);
db.Put(item.first, rocksdb::Slice(buf.data.get(), buf.size));

Obviously we could improve this behaviour by directly adding support for rocksdb::slice to to be used as input and output buffer.
Therefore you would need to find a way to manage the shared_buffer inside the scope of a rocksdb::slice.

@niXman
Copy link
Owner

niXman commented Dec 20, 2023

hi,

yeah, it looks like std::span<char>: https://en.cppreference.com/w/cpp/container/span

but I don't see any point in adding support for this type because it's a very rare case...
I have a plan to add support for std::span to YAS, and I think it would be a good idea for the RockDB developers to also switch to using std::span instead of rocksdb::Slice.

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

No branches or pull requests

2 participants