perlin-network / noise

A decentralized P2P networking stack written in Go.
https://godoc.org/github.com/perlin-network/noise
MIT License
1.79k stars 211 forks source link

Use Readers/Writers instead of bytes #298

Open elgohr opened 3 years ago

elgohr commented 3 years ago

It would be great to have Readers/Writers instead of []byte when (de-)serializing data. For bigger files, like you mentioned BitTorrent (https://medium.com/perlin-network/noise-an-opinionated-p2p-networking-stack-for-decentralized-protocols-in-go-bfc6fecf157d), it would be good to not blow up the heap, but stream the data directly (e.g. using io.Copy). Maybe we could end up with something like

type SerializableStream interface {
    Marshal() io.ReadWriter
}