not-fl3 / nanoserde

Serialisation library with zero dependencies

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Add ser/deser from Read/Write

Yamakaky opened this issue · comments

For the binary serialization especially, it would be nice to be able to serde using the standard Read and Write traits instead of using Vec and slice.

I'm working on interaction between rust and wasm (using wasmer). On the host, I first have to serialize the value to Vec then copy it to wasm. Same thing for deser. With custom Read/Write types, I could do it in one pass.

One other advantage is that you could do streaming deserialization with custom parsers, for example if you want to add all the u32 in a very big file with low constant memory usage.

It can be added as a backward compatible method since Vec is Read + Write. Then, in a future version, the Vec version can be dropped.

Example of what it could look like: master...Yamakaky:read-write

The Result<Result<>> is ugly, it would be merged in one Error type in a final version.

Would you be willing to merge such feature? If not, I won't bother putting it in order.

Sorry for such a delayed response on this.

I do agree that this is a great feature that would be nice to have, but I am not quite sure about the proposed API.

Do you mean the Result<Result<>>?

ser_bin and de_bin could be put as free functions unless we find a usecase where the default implementation could be optimized.