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

Test loading JLSO files using Python's bson library #76

Open
rofinn opened this issue Oct 26, 2020 · 0 comments
Open

Test loading JLSO files using Python's bson library #76

rofinn opened this issue Oct 26, 2020 · 0 comments

Comments

@rofinn
Copy link
Member

rofinn commented Oct 26, 2020

This should ensure that:

  1. We aren't using custom Julia specific types in the header
  2. Demonstrate how to extract raw data from from a JLSO file outside of this library

Snippet:

using JLSO

julia> JLSO.save("python-test.jlso", :scores => Int64[1, 2, 3, 4]; format=:bson, compression=:none)
import bson
import struct

f = open("python-test.jlso", "rb")
fbytes = f.read()
header = bson.loads(fbytes)

obj_names = header['data'][1][0]

# Obviously you could generalize this to iterate over the `obj_names`
obj_nbytes = struct.unpack('l', header['data'][1][1]['data'])
obj_pos = struct.unpack('l', header['data'][1][2]['data'])

# Example extracting a bson data object
f.seek(obj_pos[0])
bson_data = bson.loads(f.read(obj_nbytes[0]))
scores = struct.unpack('llll', bson_data['data'][1][0]['data'])

f.close()
@rofinn rofinn mentioned this issue Oct 26, 2020
@rofinn rofinn mentioned this issue Nov 10, 2020
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

1 participant