pub struct ChannelCodec {
link_version: u16,
}Expand description
This object can be used to encode and decode channel cells.
NOTE: only link protocol versions 4 and higher are supported. VERSIONS cells are not supported via the encoder/decoder, since VERSIONS cells always use a two-byte circuit-ID for backwards compatibility with protocol versions < 4.
The implemented format is one of the following:
Variable-length cells:
u32 circid;
u8 command;
u16 len;
u8 body[len];Fixed-width cells:
u32 circid;
u8 command;
u8 body[509];Fields§
§link_version: u16The link protocol version being used for this channel.
(We don’t currently support any versions of the link protocol where this version matters, but for protocol versions below 4, it would have affected the length of the circuit ID.)
Implementations§
Source§impl ChannelCodec
impl ChannelCodec
Sourcepub fn new(link_version: u16) -> Self
pub fn new(link_version: u16) -> Self
Create a new ChannelCodec with a given link protocol version
Sourcepub fn link_version(&self) -> u16
pub fn link_version(&self) -> u16
Return the link protocol version of this codec.
Sourcepub fn write_cell<M: ChanMsg>(
&mut self,
item: ChanCell<M>,
dst: &mut BytesMut,
) -> Result<()>
pub fn write_cell<M: ChanMsg>( &mut self, item: ChanCell<M>, dst: &mut BytesMut, ) -> Result<()>
Write the given cell into the provided BytesMut object.
Sourcepub fn decode_cell<M: ChanMsg>(
&mut self,
src: &mut BytesMut,
) -> Result<Option<(ChanCell<M>, Bytes)>>
pub fn decode_cell<M: ChanMsg>( &mut self, src: &mut BytesMut, ) -> Result<Option<(ChanCell<M>, Bytes)>>
Try to decode a cell from the provided BytesMut object.
On a definite decoding error, return Err(_).
On a cell that might just be truncated, return Ok(None).
Returns both the cell and the bytes that the cell were decoded from. These bytes are intended for SLOG/CLOG calculations.
Auto Trait Implementations§
impl Freeze for ChannelCodec
impl RefUnwindSafe for ChannelCodec
impl Send for ChannelCodec
impl Sync for ChannelCodec
impl Unpin for ChannelCodec
impl UnsafeUnpin for ChannelCodec
impl UnwindSafe for ChannelCodec
Blanket Implementations§
Source§impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedExplicit<'a, E> for Twhere
T: 'a,
Source§impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
impl<'a, T, E> AsTaggedImplicit<'a, E> for Twhere
T: 'a,
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.Source§impl<T> DowncastSend for T
impl<T> DowncastSend for T
Source§impl<T> DowncastSync for T
impl<T> DowncastSync for T
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more