summaryrefslogtreecommitdiff
path: root/src/protocol/udp.rs
diff options
context:
space:
mode:
authorluwenpeng <[email protected]>2023-08-14 11:03:42 +0800
committerluwenpeng <[email protected]>2023-08-14 11:03:42 +0800
commit53e184805feabca2724841dcf45f356d427ea6e6 (patch)
treea81915365369350eb007ff3a0f645cbc84bdc4d3 /src/protocol/udp.rs
parent85973cd021fda0d62c5f3e786e2abb8c8296a1df (diff)
[feature] Add Decode trait
Diffstat (limited to 'src/protocol/udp.rs')
-rw-r--r--src/protocol/udp.rs6
1 files changed, 4 insertions, 2 deletions
diff --git a/src/protocol/udp.rs b/src/protocol/udp.rs
index c5fab65..d5302eb 100644
--- a/src/protocol/udp.rs
+++ b/src/protocol/udp.rs
@@ -1,3 +1,4 @@
+use crate::protocol::codec::Decode;
use nom::number;
use nom::IResult;
@@ -31,8 +32,8 @@ pub struct UdpHeader {
* API
******************************************************************************/
-impl UdpHeader {
- pub fn decode(input: &[u8]) -> IResult<&[u8], UdpHeader> {
+impl Decode<UdpHeader> for UdpHeader {
+ fn decode(input: &[u8]) -> IResult<&[u8], UdpHeader> {
let (input, source_port) = number::streaming::be_u16(input)?;
let (input, dest_port) = number::streaming::be_u16(input)?;
let (input, length) = number::streaming::be_u16(input)?;
@@ -57,6 +58,7 @@ impl UdpHeader {
#[cfg(test)]
mod tests {
use super::UdpHeader;
+ use crate::protocol::codec::Decode;
const LAST_SLICE: &'static [u8] = &[0xff];