forked from TrueCloudLab/neoneo-go
network: use optimized decoder for transactions
NewTransactionFromBytes() works a bit faster and uses less memory.
This commit is contained in:
parent
892c9785ad
commit
1b186e046b
1 changed files with 7 additions and 2 deletions
|
@ -130,7 +130,6 @@ func (m *Message) decodePayload() error {
|
|||
buf = d
|
||||
}
|
||||
|
||||
r := io.NewBinReaderFromBuf(buf)
|
||||
var p payload.Payload
|
||||
switch m.Command {
|
||||
case CMDVersion:
|
||||
|
@ -154,7 +153,12 @@ func (m *Message) decodePayload() error {
|
|||
case CMDHeaders:
|
||||
p = &payload.Headers{StateRootInHeader: m.StateRootInHeader}
|
||||
case CMDTX:
|
||||
p = &transaction.Transaction{}
|
||||
p, err := transaction.NewTransactionFromBytes(buf)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
m.Payload = p
|
||||
return nil
|
||||
case CMDMerkleBlock:
|
||||
p = &payload.MerkleBlock{}
|
||||
case CMDPing, CMDPong:
|
||||
|
@ -164,6 +168,7 @@ func (m *Message) decodePayload() error {
|
|||
default:
|
||||
return fmt.Errorf("can't decode command %s", m.Command.String())
|
||||
}
|
||||
r := io.NewBinReaderFromBuf(buf)
|
||||
p.DecodeBinary(r)
|
||||
if r.Err == nil || r.Err == payload.ErrTooManyHeaders {
|
||||
m.Payload = p
|
||||
|
|
Loading…
Reference in a new issue