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

[Rust] Way to copy/access a tables' buffer from a generated type #7724

Closed
dsxmachina opened this issue Dec 19, 2022 · 3 comments
Closed

[Rust] Way to copy/access a tables' buffer from a generated type #7724

dsxmachina opened this issue Dec 19, 2022 · 3 comments

Comments

@dsxmachina
Copy link

Hello,

I just recently tried to update from the Rust flatbuffer Version 2.1.2 to the newest 22.10.26.
However, one change kind of broke my entire design:

In 2.1.2 the buf: &'a [u8] field inside the Table struct was public.
So you could easily create a real copy of your Flatbuffer-Object, just by cloning the inner table:

fn encode(&self) -> Bytes {
  Bytes::copy_from_slice(self._tab.buf)
}

Here I "encode" a generated flatbuffer object, so I have a Vec<u8> or in this case Bytes Object,
which I can freely move around (as it lives on the heap), and reinterpret as my flatbuffer type with

root_unchecked::<MyType>( bytes )

Which is kind of nice, as it allows me to move the flatbuffer objects around and pass copies of it to functions pretty easy.

However - in 22.10.26 this is not possible anymore, and I am wondering why, because I really miss the feature of getting access to the underlying buffer object.
Am I missing an obvious way of how you should handle these objects ?

Would it be possible to re-add the old interface ?
(Maybe the field does not need to be public, but instead a getter-function to the inner buffer ?)
I would happily create a pull request, if this is desired.

Please let me know, and keep up your amazing work with this project.
Thank you !

@enum-class
Copy link
Contributor

Please check this links, maybe helps:
#7700
3be296e

@dsxmachina
Copy link
Author

Nice - this should solve it :).
Out of curiosity - do you have any Idea when this will be released ?
In https://crates.io/crates/flatbuffers the Version is still at 22.10.26 - the commit that fixes it comes after that.

@dsxmachina
Copy link
Author

Anyway, the issue can be closed.
If you have any information regarding the release, please let me know.

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