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

@@ -265,8 +265,15 @@ func (s *Single) Serialize(w io.Writer) error {
return err
}
// 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")
}
return lnwire.WriteElements(
w,
buf,
byte(s.Version),
uint16(len(singleBytes.Bytes())),
singleBytes.Bytes(),