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
|
@ -5,6 +5,8 @@ import (
|
|||
"errors"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
"github.com/CityOfZion/neo-go/pkg/io"
|
||||
)
|
||||
|
||||
const (
|
||||
|
@ -109,6 +111,16 @@ func (f Fixed8) MarshalJSON() ([]byte, error) {
|
|||
return []byte(`"` + f.String() + `"`), nil
|
||||
}
|
||||
|
||||
// DecodeBinary implements the io.Serializable interface.
|
||||
func (f *Fixed8) DecodeBinary(r *io.BinReader) {
|
||||
*f = Fixed8(r.ReadU64LE())
|
||||
}
|
||||
|
||||
// EncodeBinary implements the io.Serializable interface.
|
||||
func (f *Fixed8) EncodeBinary(w *io.BinWriter) {
|
||||
w.WriteU64LE(uint64(*f))
|
||||
}
|
||||
|
||||
// Satoshi defines the value of a 'Satoshi'.
|
||||
func Satoshi() Fixed8 {
|
||||
return Fixed8(1)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue