Skip to content

Commit

Permalink
Additional fixes from tnull review
Browse files Browse the repository at this point in the history
  • Loading branch information
mariocynicys committed Jan 6, 2023
1 parent 59dce84 commit 1f1e432
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 11 deletions.
4 changes: 2 additions & 2 deletions lightning/src/ln/msgs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -821,8 +821,8 @@ pub struct CommitmentUpdate {
}

/// Messages could have optional fields to use with extended features
/// As we wish to serialize these differently from Option<T>s (Options get a tag byte, but
/// OptionalField simply gets Present if there are enough bytes to read into it), we have a
/// As we wish to serialize these differently from `Option<T>`s (`Options` get a tag byte, but
/// [`OptionalField`] simply gets `Present` if there are enough bytes to read into it), we have a
/// separate enum type for them.
/// (C-not exported) due to a free generic in T
#[derive(Clone, Debug, PartialEq, Eq)]
Expand Down
10 changes: 5 additions & 5 deletions lightning/src/util/ser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -93,15 +93,15 @@ impl Writer for LengthCalculatingWriter {
}
}

/// Essentially std::io::Take but a bit simpler and with a method to walk the underlying stream
/// 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.
pub struct FixedLengthReader<R: Read> {
read: R,
bytes_read: u64,
total_bytes: u64,
}
impl<R: Read> FixedLengthReader<R> {
/// Returns a new FixedLengthReader.
/// Returns a new [`FixedLengthReader`].
pub fn new(read: R, total_bytes: u64) -> Self {
Self { read, bytes_read: 0, total_bytes }
}
Expand Down Expand Up @@ -148,15 +148,15 @@ impl<R: Read> LengthRead for FixedLengthReader<R> {
}
}

/// A Read which tracks whether any bytes have been read at all. This allows us to distinguish
/// 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".
pub struct ReadTrackingReader<R: Read> {
read: R,
/// Tells whether we have read from this reader or not yet.
/// Returns whether we have read from this reader or not yet.
pub have_read: bool,
}
impl<R: Read> ReadTrackingReader<R> {
/// Returns a new ReadTrackingReader.
/// Returns a new [`ReadTrackingReader`].
pub fn new(read: R) -> Self {
Self { read, have_read: false }
}
Expand Down
11 changes: 7 additions & 4 deletions lightning/src/util/ser_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,11 @@
// You may not use this file except in accordance with one or both of these
// licenses.

//! Some macros that implement Readable/Writeable traits for lightning messages.
//! Some macros that implement [`Readable`]/[`Writeable`] traits for lightning messages.
//! They also handle serialization and deserialization of TLVs.
//!
//! [`Readable`]: crate::util::ser::Readable
//! [`Writeable`]: crate::util::ser::Writeable
/// Implements serialization for a single TLV record.
/// This is exported for use by other exported macros, do not use directly.
Expand Down Expand Up @@ -406,7 +409,7 @@ macro_rules! _decode_tlv_stream_range {
},
_ => {},
}
// As we read types, make sure we hit every required type between last_seen_type and typ:
// As we read types, make sure we hit every required type between `last_seen_type` and `typ`:
$({
$crate::_check_decoded_tlv_order!(last_seen_type, typ, $type, $field, $fieldty);
})*
Expand Down Expand Up @@ -504,7 +507,7 @@ macro_rules! impl_writeable {
/// serialized object. Previous versions will simply err with a
/// [`DecodeError::UnknownVersion`].
///
/// Updates to either $this_version or $min_version_that_can_read_this should be included in
/// Updates to either `$this_version` or `$min_version_that_can_read_this` should be included in
/// release notes.
///
/// Both version fields can be specific to this type of object.
Expand Down Expand Up @@ -536,7 +539,7 @@ macro_rules! write_tlv_fields {

/// Reads a prefix added by [`write_ver_prefix`], above. Takes the current version of the
/// serialization logic for this object. This is compared against the
/// $min_version_that_can_read_this added by [`write_ver_prefix`].
/// `$min_version_that_can_read_this` added by [`write_ver_prefix`].
macro_rules! read_ver_prefix {
($stream: expr, $this_version: expr) => { {
let ver: u8 = Readable::read($stream)?;
Expand Down

0 comments on commit 1f1e432

Please sign in to comment.