mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-05-03 01: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
|
@ -21,16 +21,16 @@ func (vs *Validator) RegisteredAndHasVotes() bool {
|
|||
// EncodeBinary encodes Validator to the given BinWriter.
|
||||
func (vs *Validator) EncodeBinary(bw *io.BinWriter) {
|
||||
vs.PublicKey.EncodeBinary(bw)
|
||||
bw.WriteLE(vs.Registered)
|
||||
bw.WriteLE(vs.Votes)
|
||||
bw.WriteBool(vs.Registered)
|
||||
vs.Votes.EncodeBinary(bw)
|
||||
}
|
||||
|
||||
// DecodeBinary decodes Validator from the given BinReader.
|
||||
func (vs *Validator) DecodeBinary(reader *io.BinReader) {
|
||||
vs.PublicKey = &keys.PublicKey{}
|
||||
vs.PublicKey.DecodeBinary(reader)
|
||||
reader.ReadLE(&vs.Registered)
|
||||
reader.ReadLE(&vs.Votes)
|
||||
vs.Registered = reader.ReadBool()
|
||||
vs.Votes.DecodeBinary(reader)
|
||||
}
|
||||
|
||||
// GetValidatorsWeightedAverage applies weighted filter based on votes for validator and returns number of validators.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue