elixir-thrift icon indicating copy to clipboard operation
elixir-thrift copied to clipboard

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

Open dantswain opened this issue 8 years ago • 2 comments

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)

dantswain avatar Apr 12 '17 14:04 dantswain

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.

pguillory avatar Apr 12 '17 15:04 pguillory

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.

fishcakez avatar Apr 12 '17 16:04 fishcakez