A lot of structures are (de)serialized via offsets like this:
copy(q.TheirPub[:], b[:33])
copy(q.TheirRefundPub[:], b[33:66])
copy(q.TheirHAKDBase[:], b[66:99])
tsbuf := make([]byte, 8)
copy(tsbuf, b[99:107])
q.LastUpdate = binary.BigEndian.Uint64(tsbuf)
u, err := portxo.PorTxoFromBytes(b[107:])
if err != nil {
return q, err
}
It would be much better to use a Reader and Writer that lets you read a set number of bytes at a time either from a buffer or from a fd instead of blindly copying a buffer of some size and then taking chunks of that into memory.
Example the BinaryComponent system from Jiyunet where subtypes (like outpoints in our case) have there IO routines called out to by their owners:
A lot of structures are (de)serialized via offsets like this:
It would be much better to use a
Reader
andWriter
that lets you read a set number of bytes at a time either from a buffer or from a fd instead of blindly copying a buffer of some size and then taking chunks of that into memory.Example the
BinaryComponent
system from Jiyunet where subtypes (like outpoints in our case) have there IO routines called out to by their owners:Trait def: https://gitlab.com/jiyunet/jiyunet/blob/master/core/src/io.rs#L32
Example impl: https://gitlab.com/jiyunet/jiyunet/blob/master/dag/src/segment.rs#L21-55