lnwire: add new SerializedSize method to all wire messages

This'll be useful for the bandwidth based rate limiting we'll implement
in the next commit.
This commit is contained in:
Olaoluwa Osuntokun
2025-03-18 18:55:16 -05:00
parent e8875e06fe
commit 56a100123b
40 changed files with 453 additions and 4 deletions

View File

@@ -70,6 +70,10 @@ func NewError() *Error {
// interface.
var _ Message = (*Error)(nil)
// A compile time check to ensure Error implements the lnwire.SizeableMessage
// interface.
var _ SizeableMessage = (*Error)(nil)
// Error returns the string representation to Error.
//
// NOTE: Satisfies the error interface.
@@ -113,6 +117,13 @@ func (c *Error) MsgType() MessageType {
return MsgError
}
// SerializedSize returns the serialized size of the message in bytes.
//
// This is part of the lnwire.SizeableMessage interface.
func (c *Error) SerializedSize() (uint32, error) {
return MessageSerializedSize(c)
}
// isASCII is a helper method that checks whether all bytes in `data` would be
// printable ASCII characters if interpreted as a string.
func isASCII(data []byte) bool {