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

Immutable struct cannot be read back #29

Open
dm3 opened this issue Aug 17, 2018 · 1 comment
Open

Immutable struct cannot be read back #29

dm3 opened this issue Aug 17, 2018 · 1 comment

Comments

@dm3
Copy link

dm3 commented Aug 17, 2018

Are immutable structs supposed to work with FlatBuffers? I couldn't make the serialization/deserialization work both with and without the @STRUCT annotation.

I've added the following code under the TestInt8I struct definition in test/runtests.jl to get a smallest reproducible case:

struct TestInt8I
    x::Int8
end

inst2 = TestInt8I(2)
b = FlatBuffers.Builder(TestInt8I)
FlatBuffers.build!(b, inst2)
t = FlatBuffers.Table(b)
inst2_1 = FlatBuffers.read(t)

@test inst2.x == inst2_1.x

The the test fails with:

ERROR: LoadError: EOFError: read end of file
Stacktrace:
 [1] unsafe_read(::Base.AbstractIOBuffer{SubArray{UInt8,1,Array{UInt8,1},Tuple{UnitRange{Int64}},true}}, ::Ptr{UInt8}, ::UInt64) at ./iobuffer.jl:105
 [2] unsafe_read(::Base.AbstractIOBuffer{SubArray{UInt8,1,Array{UInt8,1},Tuple{UnitRange{Int64}},true}}, ::Base.RefValue{Int32}, ::Int64) at ./io.jl:361
 [3] read at ./io.jl:363 [inlined]
 [4] read at ./io.jl:367 [inlined]
 [5] get(::FlatBuffers.Table{TestInt8I}, ::Int64, ::Type{Int32}) at /Users/dm3/.julia/v0.6/FlatBuffers/src/internals.jl:8
 [6] offset(::FlatBuffers.Table{TestInt8I}, ::Int64) at /Users/dm3/.julia/v0.6/FlatBuffers/src/internals.jl:18
 [7] read(::FlatBuffers.Table{TestInt8I}, ::Type{TestInt8I}) at /Users/dm3/.julia/v0.6/FlatBuffers/src/FlatBuffers.jl:218
 [8] read(::FlatBuffers.Table{TestInt8I}) at /Users/dm3/.julia/v0.6/FlatBuffers/src/FlatBuffers.jl:210
 [9] include_from_node1(::String) at ./loading.jl:576
 [10] include(::String) at ./sysimg.jl:14
 [11] process_options(::Base.JLOptions) at ./client.jl:305
 [12] _start() at ./client.jl:371
while loading /Users/dm3/.julia/v0.6/FlatBuffers/test/runtests.jl, in expression starting on line 64
@rjkat
Copy link
Contributor

rjkat commented Nov 25, 2018

Immutable structs are supposed to work, but they can’t be the “root type”. See
google/flatbuffers#4657

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