lnwire: use write buffer in Encode methods

This commit changes the WriteElement and WriteElements methods to take a
write buffer instead of io.Writer. The corresponding Encode methods are
changed to use the write buffer.
This commit is contained in:
yyforyongyu
2021-06-17 14:17:30 +08:00
parent 879d3cc86c
commit aa1561c60d
36 changed files with 139 additions and 76 deletions

View File

@@ -2,6 +2,7 @@ package channeldb
import (
"encoding/binary"
"fmt"
"sync"
"io"
@@ -232,7 +233,14 @@ func (p *WaitingProof) Encode(w io.Writer) error {
return err
}
if err := p.AnnounceSignatures.Encode(w, 0); err != nil {
// TODO(yy): remove the type assertion when we finished refactoring db
// into using write buffer.
buf, ok := w.(*bytes.Buffer)
if !ok {
return fmt.Errorf("expect io.Writer to be *bytes.Buffer")
}
if err := p.AnnounceSignatures.Encode(buf, 0); err != nil {
return err
}