mat64: implement a stream-oriented binary (de)serialization
sbinet opened this issue · comments
Sebastien Binet commented
the whole discussion about #342 and the []byte
size implications made me think about implementing a more memory-wise efficient approach.
why not also provide:
// pseudo-code
func (d *Dense) MarshalBinaryStream(w io.Writer) error {
binary.Write(w, littleEndian, nrows)
binary.Write(w, littleEndian, ncols)
for i := range nrows {
for j := range ncols {
binary.Write(w, littleEndian, data.at(i,j))
}
}
return err
}
func (d *Dense) UnmarshalBinaryStream(r io.Reader) error {
// ...
}
and then implement MarshalBinary
in terms of MarshalBinaryStream
.
people not wanting to get beaten by the possibly large temporary []byte
slice could just use the stream oriented version.
Dan Kortschak commented
I think this is reasonable. bikeshed: MarshalBinaryTo(io.Writer) error
and UnmarshalBinaryFrom(io.Reader) error
Sebastien Binet commented
SGTM.
I'll prepare a CL once #342 has landed.
Brendan Tracey commented
They may as well return (n int, err error), right?
Sebastien Binet commented
yes. they could.
Dan Kortschak commented
Good point.