The documentation for Serialization is pretty sparse, and I am wondering if I am using it correctly. I will write up what I learn here as a PR for the docs.
I want to serialize multiple objects to a stream from an iterator. Should I construct a
Serializer, then write them individually?
Do I need a header if I keep the object in memory (non-persistent)?
The following works:
using Serialization function writedata(itr) io = IOBuffer() s = Serializer(io) Serialization.writeheader(s) for elt in itr serialize(s, elt) end take!(io) end function readdata(data) io = IOBuffer(data) while !eof(io) @show deserialize(io) end end
julia> data = writedata((42, "a fish", Float64(π))); julia> readdata(data) deserialize(io) = 42 deserialize(io) = "a fish" deserialize(io) = 3.141592653589793