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

Flexbuffer or bytearray support for python [python 3.x, flatc 1.7.1, Ubuntu 16.04 LTS, flatbuffers 2015.5.14] #4447

Closed
jfinken opened this issue Oct 3, 2017 · 4 comments

Comments

@jfinken
Copy link

jfinken commented Oct 3, 2017

  • python 3.X
  • flatc version 1.7.1 (Sep 27 2017)
  • Ubuntu 16.04.2 LTS
  • flatbuffers serialization format for Python: INSTALLED: 2015.5.14.0

I would like to store a python bytearray in a flatbuffer vector of type byte without having to iterate over the incoming bytearray invoking builder.PrependByte, e.g.:

for j in reversed(range(0, len(buf))):
        builder.PrependByte(buf[j])  

Is this possible via Flexbuffers or other given the current implementation(s)? Otherwise, for serialization performance reasons the above prevents usage within my use case.

Many thanks in advance.

@aardappel
Copy link
Collaborator

We should really just add a special purpose function for byte arrays.
I believe this was discussed elsewhere too, not sure why it didn't happen.. @rw?

@rw
Copy link
Contributor

rw commented Oct 5, 2017

We have functions for reading byte arrays (from #4390) but not yet for writing them.

I've created a PR that implements your request: #4453

Please try it out and provide feedback.

(Also, you'll want to default to installing the python package from git (using pip3 install -e git+ssh://...) to get more up-to-date code.)

@aardappel
Copy link
Collaborator

Fixed here: #4453

@adsharma
Copy link

https://github.com/adsharma/flexpy has some python3 compatible code to read flexbuffers.
Warning: hot off the press, needs more review.
Could use numpy to avoid copies.

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

4 participants