Skip to content

Commit 6b09235

Browse files
committed
Extend and expose TlvRecord and TlvStream
To avoid implementing another TLV struct needed for custom TLV logic, we slightly modify and expose these existing types.
1 parent 498f233 commit 6b09235

File tree

2 files changed

+16
-2
lines changed

2 files changed

+16
-2
lines changed

lightning/src/offers/merkle.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn tagged_branch_hash_from_engine(
144144
/// [`Iterator`] over a sequence of bytes yielding [`TlvRecord`]s. The input is assumed to be a
145145
/// well-formed TLV stream.
146146
#[derive(Clone)]
147-
pub(super) struct TlvStream<'a> {
147+
pub(crate) struct TlvStream<'a> {
148148
data: io::Cursor<&'a [u8]>,
149149
}
150150

@@ -170,13 +170,26 @@ impl<'a> TlvStream<'a> {
170170
}
171171

172172
/// A slice into a [`TlvStream`] for a record.
173-
pub(super) struct TlvRecord<'a> {
173+
#[derive(PartialEq)]
174+
pub(crate) struct TlvRecord<'a> {
174175
pub(super) r#type: u64,
175176
type_bytes: &'a [u8],
176177
// The entire TLV record.
177178
pub(super) record_bytes: &'a [u8],
178179
}
179180

181+
impl TlvRecord<'_> {
182+
pub(crate) fn get_type(&self) -> u64 {
183+
self.r#type
184+
}
185+
}
186+
187+
impl Writeable for TlvRecord<'_> {
188+
fn write<W: Writer>(&self, writer: &mut W) -> Result<(), io::Error> {
189+
writer.write_all(self.record_bytes)
190+
}
191+
}
192+
180193
impl<'a> Iterator for TlvStream<'a> {
181194
type Item = TlvRecord<'a>;
182195

lightning/src/offers/mod.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
pub mod invoice;
1616
pub mod invoice_request;
1717
mod merkle;
18+
pub(crate) use merkle::{TlvRecord, TlvStream};
1819
pub mod offer;
1920
pub mod parse;
2021
mod payer;

0 commit comments

Comments
 (0)