mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 11:41:48 +00:00
io: add type-specific read/write methods
This seriously improves the serialization/deserialization performance for several reasons: * no time spent in `binary` reflection * no memory allocations being made on every read/write * uses fast ReadBytes everywhere it's appropriate It also makes Fixed8 Serializable just for convenience.
This commit is contained in:
parent
89d7f6d26e
commit
54d888ba70
43 changed files with 441 additions and 205 deletions
|
@ -56,12 +56,12 @@ func NewInventory(typ InventoryType, hashes []util.Uint256) *Inventory {
|
|||
|
||||
// DecodeBinary implements Serializable interface.
|
||||
func (p *Inventory) DecodeBinary(br *io.BinReader) {
|
||||
br.ReadLE(&p.Type)
|
||||
p.Type = InventoryType(br.ReadByte())
|
||||
br.ReadArray(&p.Hashes)
|
||||
}
|
||||
|
||||
// EncodeBinary implements Serializable interface.
|
||||
func (p *Inventory) EncodeBinary(bw *io.BinWriter) {
|
||||
bw.WriteLE(p.Type)
|
||||
bw.WriteByte(byte(p.Type))
|
||||
bw.WriteArray(p.Hashes)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue