use crate::offers::payer::{PAYER_METADATA_TYPE, PayerTlvStream, PayerTlvStreamRef};
use crate::offers::refund::{IV_BYTES_WITH_METADATA as REFUND_IV_BYTES_WITH_METADATA, IV_BYTES_WITHOUT_METADATA as REFUND_IV_BYTES_WITHOUT_METADATA, Refund, RefundContents};
use crate::offers::signer::{Metadata, self};
-use crate::util::ser::{HighZeroBytesDroppedBigSize, Iterable, Readable, SeekReadable, WithoutLength, Writeable, Writer};
+use crate::util::ser::{CursorReadable, HighZeroBytesDroppedBigSize, Iterable, Readable, WithoutLength, Writeable, Writer};
use crate::util::string::PrintableString;
#[allow(unused_imports)]
SignatureTlvStreamRef<'a>,
);
-impl SeekReadable for FullInvoiceTlvStream {
- fn read<R: io::Read + io::Seek>(r: &mut R) -> Result<Self, DecodeError> {
- let payer = SeekReadable::read(r)?;
- let offer = SeekReadable::read(r)?;
- let invoice_request = SeekReadable::read(r)?;
- let invoice = SeekReadable::read(r)?;
- let signature = SeekReadable::read(r)?;
+impl CursorReadable for FullInvoiceTlvStream {
+ fn read<R: AsRef<[u8]>>(r: &mut io::Cursor<R>) -> Result<Self, DecodeError> {
+ let payer = CursorReadable::read(r)?;
+ let offer = CursorReadable::read(r)?;
+ let invoice_request = CursorReadable::read(r)?;
+ let invoice = CursorReadable::read(r)?;
+ let signature = CursorReadable::read(r)?;
Ok((payer, offer, invoice_request, invoice, signature))
}
InvoiceTlvStreamRef<'a>,
);
-impl SeekReadable for PartialInvoiceTlvStream {
- fn read<R: io::Read + io::Seek>(r: &mut R) -> Result<Self, DecodeError> {
- let payer = SeekReadable::read(r)?;
- let offer = SeekReadable::read(r)?;
- let invoice_request = SeekReadable::read(r)?;
- let invoice = SeekReadable::read(r)?;
+impl CursorReadable for PartialInvoiceTlvStream {
+ fn read<R: AsRef<[u8]>>(r: &mut io::Cursor<R>) -> Result<Self, DecodeError> {
+ let payer = CursorReadable::read(r)?;
+ let offer = CursorReadable::read(r)?;
+ let invoice_request = CursorReadable::read(r)?;
+ let invoice = CursorReadable::read(r)?;
Ok((payer, offer, invoice_request, invoice))
}
use crate::offers::parse::{Bolt12ParseError, ParsedMessage, Bolt12SemanticError};
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
use crate::offers::signer::{Metadata, MetadataMaterial};
-use crate::util::ser::{HighZeroBytesDroppedBigSize, Readable, SeekReadable, WithoutLength, Writeable, Writer};
+use crate::util::ser::{CursorReadable, HighZeroBytesDroppedBigSize, Readable, WithoutLength, Writeable, Writer};
use crate::util::string::{PrintableString, UntrustedString};
#[cfg(not(c_bindings))]
SignatureTlvStreamRef<'a>,
);
-impl SeekReadable for FullInvoiceRequestTlvStream {
- fn read<R: io::Read + io::Seek>(r: &mut R) -> Result<Self, DecodeError> {
- let payer = SeekReadable::read(r)?;
- let offer = SeekReadable::read(r)?;
- let invoice_request = SeekReadable::read(r)?;
- let signature = SeekReadable::read(r)?;
+impl CursorReadable for FullInvoiceRequestTlvStream {
+ fn read<R: AsRef<[u8]>>(r: &mut io::Cursor<R>) -> Result<Self, DecodeError> {
+ let payer = CursorReadable::read(r)?;
+ let offer = CursorReadable::read(r)?;
+ let invoice_request = CursorReadable::read(r)?;
+ let signature = CursorReadable::read(r)?;
Ok((payer, offer, invoice_request, signature))
}
use bitcoin::secp256k1;
use crate::io;
use crate::ln::msgs::DecodeError;
-use crate::util::ser::SeekReadable;
+use crate::util::ser::CursorReadable;
#[allow(unused_imports)]
use crate::prelude::*;
/// A wrapper for reading a message as a TLV stream `T` from a byte sequence, while still
/// maintaining ownership of the bytes for later use.
-pub(super) struct ParsedMessage<T: SeekReadable> {
+pub(super) struct ParsedMessage<T: CursorReadable> {
pub bytes: Vec<u8>,
pub tlv_stream: T,
}
-impl<T: SeekReadable> TryFrom<Vec<u8>> for ParsedMessage<T> {
+impl<T: CursorReadable> TryFrom<Vec<u8>> for ParsedMessage<T> {
type Error = DecodeError;
fn try_from(bytes: Vec<u8>) -> Result<Self, Self::Error> {
let mut cursor = io::Cursor::new(bytes);
- let tlv_stream: T = SeekReadable::read(&mut cursor)?;
+ let tlv_stream: T = CursorReadable::read(&mut cursor)?;
// Ensure that there are no more TLV records left to parse.
if cursor.position() < cursor.get_ref().len() as u64 {
use crate::offers::parse::{Bech32Encode, Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
use crate::offers::payer::{PayerContents, PayerTlvStream, PayerTlvStreamRef};
use crate::offers::signer::{Metadata, MetadataMaterial, self};
-use crate::util::ser::{SeekReadable, Readable, WithoutLength, Writeable, Writer};
+use crate::util::ser::{CursorReadable, Readable, WithoutLength, Writeable, Writer};
use crate::util::string::PrintableString;
#[cfg(not(c_bindings))]
InvoiceRequestTlvStreamRef<'a>,
);
-impl SeekReadable for RefundTlvStream {
- fn read<R: io::Read + io::Seek>(r: &mut R) -> Result<Self, DecodeError> {
- let payer = SeekReadable::read(r)?;
- let offer = SeekReadable::read(r)?;
- let invoice_request = SeekReadable::read(r)?;
+impl CursorReadable for RefundTlvStream {
+ fn read<R: AsRef<[u8]>>(r: &mut io::Cursor<R>) -> Result<Self, DecodeError> {
+ let payer = CursorReadable::read(r)?;
+ let offer = CursorReadable::read(r)?;
+ let invoice_request = CursorReadable::read(r)?;
Ok((payer, offer, invoice_request))
}
Amount, Offer, OfferContents, OfferTlvStream, OfferTlvStreamRef, Quantity,
};
use crate::offers::parse::{Bolt12ParseError, Bolt12SemanticError, ParsedMessage};
-use crate::util::ser::{Iterable, SeekReadable, WithoutLength, Writeable, Writer};
+use crate::util::ser::{CursorReadable, Iterable, WithoutLength, Writeable, Writer};
use crate::util::string::PrintableString;
use bitcoin::address::Address;
use bitcoin::constants::ChainHash;
type FullInvoiceTlvStream = (OfferTlvStream, InvoiceTlvStream, SignatureTlvStream);
-impl SeekReadable for FullInvoiceTlvStream {
- fn read<R: io::Read + io::Seek>(r: &mut R) -> Result<Self, DecodeError> {
- let offer = SeekReadable::read(r)?;
- let invoice = SeekReadable::read(r)?;
- let signature = SeekReadable::read(r)?;
+impl CursorReadable for FullInvoiceTlvStream {
+ fn read<R: AsRef<[u8]>>(r: &mut io::Cursor<R>) -> Result<Self, DecodeError> {
+ let offer = CursorReadable::read(r)?;
+ let invoice = CursorReadable::read(r)?;
+ let signature = CursorReadable::read(r)?;
Ok((offer, invoice, signature))
}
//! [`ChannelMonitor`]: crate::chain::channelmonitor::ChannelMonitor
use crate::prelude::*;
-use crate::io::{self, Read, Seek, Write};
+use crate::io::{self, Read, Write};
use crate::io_extras::{copy, sink};
use core::hash::Hash;
use crate::sync::{Mutex, RwLock};
}
/// A trait that various LDK types implement allowing them to be read in from a
-/// [`Read`]` + `[`Seek`].
-pub(crate) trait SeekReadable where Self: Sized {
+/// [`io::Cursor`].
+pub(crate) trait CursorReadable where Self: Sized {
/// Reads a `Self` in from the given [`Read`].
- fn read<R: Read + Seek>(reader: &mut R) -> Result<Self, DecodeError>;
+ fn read<R: AsRef<[u8]>>(reader: &mut io::Cursor<R>) -> Result<Self, DecodeError>;
}
/// A trait that various higher-level LDK types implement allowing them to be read in
}
}
- impl $crate::util::ser::SeekReadable for $name {
- fn read<R: $crate::io::Read + $crate::io::Seek>(reader: &mut R) -> Result<Self, $crate::ln::msgs::DecodeError> {
+ impl $crate::util::ser::CursorReadable for $name {
+ fn read<R: AsRef<[u8]>>(reader: &mut crate::io::Cursor<R>) -> Result<Self, $crate::ln::msgs::DecodeError> {
$(
_init_tlv_field_var!($field, option);
)*
- let rewind = |cursor: &mut R, offset: usize| {
- cursor.seek($crate::io::SeekFrom::Current(-(offset as i64))).expect("");
+ let rewind = |cursor: &mut crate::io::Cursor<R>, offset: usize| {
+ cursor.set_position(cursor.position().checked_sub(offset as u64).expect("Cannot rewind past 0."));
};
_decode_tlv_stream_range!(reader, $range, rewind, {
$(($type, $field, (option, encoding: $fieldty))),*