Skip to content

FlatBuffers.jl is writing unreadable flatbuffers #51

Open
@ExpandingMan

Description

@ExpandingMan

Alright, no clue what's happening here:

I'm trying to write

table Field {
  /// Name is not required, in i.e. a List
  name: string;

  /// Whether or not this field can contain nulls. Should be true in general.
  nullable: bool;

  /// This is the type of the decoded value if the field is dictionary encoded.
  type: Type;

  /// Present only if the field is dictionary encoded.
  dictionary: DictionaryEncoding;

  /// children apply only to nested data types like Struct, List and Union. For
  /// primitive types children will have length 0.
  children: [ Field ];

  /// User-defined metadata
  custom_metadata: [ KeyValue ];
}

which I've written in Julia as

@with_kw mutable struct Field
    name::String = ""
    nullable::Bool = false
    dtype_type::UInt8 = 0
    dtype::DType = nothing
    dictionary::Union{DictionaryEncoding,Nothing} = nothing
    children::Vector{Field} = []
    custom_metadata::Vector{KeyValue} = []
end
@ALIGN(Field, 1)
FB.slot_offsets(::Type{Field}) = UInt32[4,6,8,10,12,14,16]

specifically, I'm writing

Arrow.Metadata.Field
  name: String "col1"
  nullable: Bool true
  dtype_type: UInt8 0x02
  dtype: Arrow.Metadata.Int_
  dictionary: Nothing nothing
  children: Array{Arrow.Metadata.Field}((0,))
  custom_metadata: Array{Arrow.Metadata.KeyValue}((0,))

Note that both dictionary and custom_metadata are empty, so the definitions of these shouldn't matter.

Note that I've just read this in form a C++ source that presumably wrote it correctly. When I write it back however, I get something different than what I originally read.

What FlatBuffers.jl wrote was

julia> foreach(x -> print(" $x"), wtf)
 16 0 0 0 12 0 16 0 12 0 11 0 10 0 4 0 12 0 0 0 28 0 0 0 0 0 2 1 32 0 0 0 0 0 0 0 0 0 0 0 8 0 12 0 8 0 7 0 8 0 0 0 0 0 0 1 64 0 0 0 4 0 0 0 99 111 108 49 0 0 0 0

The original data was

julia> foreach(x -> print(" $x"), orig)
 16 0 0 0 0 0 10 0 12 0 6 0 5 0 8 0 10 0 0 0 0 1 3 0 12 0 0 0 8 0 8 0 0 0 4 0 8 0 0 0 4 0 0 0 1 0 0 0 20 0 0 0 16 0 20 0 8 0 6 0 7 0 12 0 0 0 16 0 16 0 0 0

FlatBuffers.jl was apparently able to read the original data correctly.

Note that I wrote wtf using FlatBuffers.bytes(Flatbuffers.build!(obj)).

I'm going to start digging into the format to see if I can figure out what in the world is going on here. Anyone have any ideas?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions