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

RFC - deserialize/1 does not accept iodata. Should it? #266

Open
dantswain opened this issue Apr 12, 2017 · 2 comments
Open

RFC - deserialize/1 does not accept iodata. Should it? #266

dantswain opened this issue Apr 12, 2017 · 2 comments
Labels

Comments

@dantswain
Copy link
Collaborator

I came across this trying to do something like the following.

serialized = BusinessObject.serialize(%BusinessObject{})
deserialized = BusinessObject.deserialize(serialized)

The second line produces :error because serialized is iodata and deserialize expects a binary.

This is a little bit of a contrived use case, but I imagine there are other cases where one might be feeding iodata into the deserializer?

This raises another question, as well. Should there be a way to handle partial messages? I can imagine cases where a server is listening to a data stream, and due to the way that the data is chunked one may receive a partial message. I imagine the API would look something like updated_object = Mod.deserialize(new_data, partial_object_from_previous_data)

@pguillory
Copy link
Collaborator

We skipped it when implementing binary protocol because it's unnecessary for clients/servers using framed transport and it would have complicated the deserialization logic quite a bit. Or at least I didn't see a simple way to do it.

@fishcakez
Copy link
Member

Quite a few deserialises will do the following as a convenience:

def deserialize(iodata), do: deserialize_binary(IO.iodata_to_binary(iodata))

This is nice if the deserializer is decoupled from the server/framing, and the expectation is for the user to implement either or both of those because it allows the user to efficiently receiving the data.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants