From f3be91741a5f56a208ea274ed03e4fe25bdea521 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jon=20H=C3=A4ggblad?= Date: Mon, 25 Mar 2024 07:26:21 +0100 Subject: [PATCH] Add ability to create a single bundles IP packet directly --- common/ip-packet-requests/src/codec.rs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/ip-packet-requests/src/codec.rs b/common/ip-packet-requests/src/codec.rs index 86df1ce8f7..4047fec8e7 100644 --- a/common/ip-packet-requests/src/codec.rs +++ b/common/ip-packet-requests/src/codec.rs @@ -34,6 +34,13 @@ impl MultiIpPacketCodec { } } + pub fn bundle_one_packet(packet: Bytes) -> Bytes { + let mut bundled_packets = BytesMut::new(); + bundled_packets.extend_from_slice(&(packet.len() as u16).to_be_bytes()); + bundled_packets.extend_from_slice(&packet); + bundled_packets.freeze() + } + // Append a packet to the buffer and return the buffer if it's full pub fn append_packet(&mut self, packet: Bytes) -> Option { let mut bundled_packets = BytesMut::new(); @@ -47,7 +54,7 @@ impl MultiIpPacketCodec { } // Flush the current buffer and return it. - fn flush_current_buffer(&mut self) -> Bytes { + pub fn flush_current_buffer(&mut self) -> Bytes { let mut output_buffer = BytesMut::new(); std::mem::swap(&mut output_buffer, &mut self.buffer); output_buffer.freeze()