lnwire: refactor Encode to use specific writers - III

This commit refactors the remaining usage of WriteElements. By
replacing the interface types with concrete types for the params used in
the methods, most of the encoding of the messages now takes zero heap
allocations.
This commit is contained in:
yyforyongyu
2021-06-18 15:15:44 +08:00
parent c1ad9cc60f
commit 2cf6969dbc
12 changed files with 289 additions and 133 deletions

View File

@@ -87,22 +87,28 @@ func (c *ReplyChannelRange) Decode(r io.Reader, pver uint32) error {
//
// This is part of the lnwire.Message interface.
func (c *ReplyChannelRange) Encode(w *bytes.Buffer, pver uint32) error {
err := WriteElements(w,
c.ChainHash[:],
c.FirstBlockHeight,
c.NumBlocks,
c.Complete,
)
if err := WriteBytes(w, c.ChainHash[:]); err != nil {
return err
}
if err := WriteUint32(w, c.FirstBlockHeight); err != nil {
return err
}
if err := WriteUint32(w, c.NumBlocks); err != nil {
return err
}
if err := WriteUint8(w, c.Complete); err != nil {
return err
}
err := encodeShortChanIDs(w, c.EncodingType, c.ShortChanIDs, c.noSort)
if err != nil {
return err
}
err = encodeShortChanIDs(w, c.EncodingType, c.ShortChanIDs, c.noSort)
if err != nil {
return err
}
return c.ExtraData.Encode(w)
return WriteBytes(w, c.ExtraData)
}
// MsgType returns the integer uniquely identifying this message type on the