Module ser

Source
Expand description

A very simple serialization framework which is used to serialize/deserialize messages as well as ChannelManagers and ChannelMonitors.

Structs§

BigSize
Lightning TLV uses a custom variable-length integer called BigSize. It is similar to Bitcoin’s variable-length integers except that it is serialized in big-endian instead of little-endian.
CollectionLength
The lightning protocol uses u16s for lengths in most cases. As our serialization framework primarily targets that, we must as well. However, because we may serialize objects that have more than 65K entries, we need to be able to store larger values. Thus, we define a variable length integer here that is backwards-compatible for values < 0xffff. We treat 0xffff as “read eight more bytes”.
FixedLengthReader
Essentially std::io::Take but a bit simpler and with a method to walk the underlying stream forward to ensure we always consume exactly the fixed length specified.
Hostname
Represents a hostname for serialization purposes. Only the character set and length will be validated. The character set consists of ASCII alphanumeric characters, hyphens, and periods. Its length is guaranteed to be representable by a single byte. This serialization is used by BOLT 7 hostnames.
LengthCalculatingWriter
Writer that only tracks the amount of data written - useful if you need to calculate the length of some data when serialized but don’t yet need the full data.
ReadTrackingReader
A Read implementation which tracks whether any bytes have been read at all. This allows us to distinguish between “EOF reached before we started” and “EOF reached mid-read”.
RequiredWrapper
Wrapper to read a required (non-optional) TLV record.
UpgradableRequired
Wrapper to read a required (non-optional) TLV record that may have been upgraded without backwards compat.
WithoutLength
A type for variable-length values within TLV record where the length is encoded as part of the record. Used to prevent encoding the length twice.

Constants§

MAX_BUF_SIZE
serialization buffer size

Traits§

LengthLimitedRead
A io::Read that limits the amount of bytes that can be read. Implementations should ensure that the object being read will only consume a fixed number of bytes from the underlying io::Read, see FixedLengthReader for an example.
LengthReadable
A trait that allows the implementer to be read in from a LengthLimitedRead, requiring the reader to limit the number of total bytes read from its underlying Read. Useful for structs that will always consume the entire provided Read when deserializing.
MaybeReadable
A trait that various LDK types implement allowing them to (maybe) be read in from a Read.
Readable
A trait that various LDK types implement allowing them to be read in from a Read.
ReadableArgs
A trait that various higher-level LDK types implement allowing them to be read in from a Read given some additional set of arguments which is required to deserialize.
Writeable
A trait that various LDK types implement allowing them to be written out to a Writer.
Writer
A simplified version of std::io::Write that exists largely for backwards compatibility. An impl is provided for any type that also impls std::io::Write.