You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Maybe what I am asking doesn't make sense, but is there a way to use PacketCodec to decode into a struct that doesn't own, but instead references a slice in the input Packet<'_>?
I am struggling a bit with the lifetimes. The only way I got this to work is like:
structTcpPacket{pubsrc:SocketAddr,pubdst:SocketAddr,pubpayload:Box<[u8]>,}structCodec;implPacketCodecforCodec{typeItem = TcpPacket;fndecode(&mutself,packet:Packet<'_>) -> Self::Item{// Use `etherparse` to get the stuff I want.TcpPacket{src:(src_ip, src_port).into(),dst:(dst_ip, dst_port).into(),payload: tcp.payload().into(),// payload has same lifetime as Packet. Turn into Boxed slice to get ownership}}}
structCodec<'a>{phantom:PhantomData<&'a()>,}impl<'a>PacketCodecforCodec<'a>{typeItem = TcpPacket<'a>;fndecode(&mutself,packet:Packet<'_>) -> Self::Item{// But if I return the slice in payload it complains about lifetimestodo!()}}
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
-
Maybe what I am asking doesn't make sense, but is there a way to use
PacketCodecto decode into a struct that doesn't own, but instead references a slice in the input Packet<'_>?I am struggling a bit with the lifetimes. The only way I got this to work is like:
Is there a way to get e.g.:
I can't get the lifetimes to not complain.
The closest I got was:
Beta Was this translation helpful? Give feedback.
All reactions