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:
Roman Khimov 2019-12-12 18:52:23 +03:00
parent 89d7f6d26e
commit 54d888ba70
43 changed files with 441 additions and 205 deletions

View file

@ -39,9 +39,9 @@ func (ne *NotificationEvent) DecodeBinary(r *io.BinReader) {
// EncodeBinary implements the Serializable interface.
func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) {
w.WriteBytes(aer.TxHash[:])
w.WriteLE(aer.Trigger)
w.WriteByte(aer.Trigger)
w.WriteString(aer.VMState)
w.WriteLE(aer.GasConsumed)
aer.GasConsumed.EncodeBinary(w)
w.WriteString(aer.Stack)
w.WriteArray(aer.Events)
}
@ -49,9 +49,9 @@ func (aer *AppExecResult) EncodeBinary(w *io.BinWriter) {
// DecodeBinary implements the Serializable interface.
func (aer *AppExecResult) DecodeBinary(r *io.BinReader) {
r.ReadBytes(aer.TxHash[:])
r.ReadLE(&aer.Trigger)
aer.Trigger = r.ReadByte()
aer.VMState = r.ReadString()
r.ReadLE(&aer.GasConsumed)
aer.GasConsumed.DecodeBinary(r)
aer.Stack = r.ReadString()
r.ReadArray(&aer.Events)
}