RFC - `deserialize/1` does not accept iodata. Should it?
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)
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.
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.