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

@ -26,8 +26,8 @@ type Contract struct {
func (cs *Contract) DecodeBinary(br *io.BinReader) {
cs.Script = br.ReadVarBytes()
br.ReadArray(&cs.ParamList)
br.ReadLE(&cs.ReturnType)
br.ReadLE(&cs.Properties)
cs.ReturnType = smartcontract.ParamType(br.ReadByte())
cs.Properties = smartcontract.PropertyState(br.ReadByte())
cs.Name = br.ReadString()
cs.CodeVersion = br.ReadString()
cs.Author = br.ReadString()
@ -40,8 +40,8 @@ func (cs *Contract) DecodeBinary(br *io.BinReader) {
func (cs *Contract) EncodeBinary(bw *io.BinWriter) {
bw.WriteVarBytes(cs.Script)
bw.WriteArray(cs.ParamList)
bw.WriteLE(cs.ReturnType)
bw.WriteLE(cs.Properties)
bw.WriteByte(byte(cs.ReturnType))
bw.WriteByte(byte(cs.Properties))
bw.WriteString(cs.Name)
bw.WriteString(cs.CodeVersion)
bw.WriteString(cs.Author)