Skip to content

read methods are extremely confusing #41

Open
@ExpandingMan

Description

@ExpandingMan

Hey guys, I've been having an issue with reading from buffers which I've finally figured out.

So, I'm trying to read something which has a 4-byte Int32 followed by a flatbuffer. It seems that opinions differ somewhat on "where the flatbuffer starts". The first part of the flatbuffer as defined in the reference was the start of the first offset. I was therefore extremely confused when I attempted to call

FB.read(Meta.Message, buf, 4)

to get an error, later to find that

FB.read(Meta.Message, buf, 20)

works. It was initially not at all apparent to me that there was anything special about byte 20 whatsoever, since you have to read the first offset at byte 4 to know to go to byte 20.

So, it only really makes sense for a user to call FB.read if he is calling it on a buffer that is perfectly aligned with the flatbuffer (including its initial offset). This means that the typical use case for most users would be calling, for example, FB.read(Meta.Message, buf[5:144]) rather than FB.read(Meta.Message, buf, 4) (remember, I was told by the documentation that the flatbuffer starts at byte 4).

I'm not really sure what the best solution is here, certainly there is a risk of breaking existing code in extremely ugly ways if the read methods are changed. I would say that, at a bare minimum, the documentation needs to be greatly expanded to describe exactly what one ought to call to deserialize their data.

I'd be glad to help out, even if that only involves expanding the documentation. What thoughts do the maintainers have on this?

Thanks! (btw, I realize that this probably made perfect sense when you were designing it, so it's perfectly understandable! it just took me a while to realize what was going on in my case)

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