Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add serde derive macros where applicable #45

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions etherparse/src/internet/ip_auth_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ pub type IpAuthenticationHeader = IpAuthHeader;

/// IP Authentication Header (rfc4302)
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IpAuthHeader {
/// IP protocol number specifying the next header or transport layer protocol.
///
Expand Down
5 changes: 5 additions & 0 deletions etherparse/src/internet/ip_auth_icv.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#[derive(Clone)]
pub struct IpAuthIcv {
pub(crate) len: u8,
pub(crate) buf: [u8; 40],
}
1 change: 1 addition & 0 deletions etherparse/src/internet/ip_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::err::{Layer, LenError, LenSource, ValueTooBigError};

/// Internet protocol headers version 4 & 6.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
#[allow(clippy::large_enum_variant)]
pub enum IpHeader {
/// IPv4 header & extension headers.
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/internet/ipv4_exts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ use crate::{err::ipv4_exts::ExtsWalkError, *};
/// Currently not supported:
/// - Encapsulating Security Payload Header (ESP)
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv4Extensions {
pub auth: Option<IpAuthHeader>,
}
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/internet/ipv4_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ use arrayvec::ArrayVec;
/// assert_eq!(slice_rest, &[]);
/// ```
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv4Header {
/// Differentiated Services Code Point
pub dscp: Ipv4Dscp,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/internet/ipv6_exts.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ use crate::{err::ipv6_exts::*, *};
/// * IP Mobility
/// * Site Multihoming by IPv6 Intermediation (SHIM6)
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6Extensions {
pub hop_by_hop_options: Option<Ipv6RawExtHeader>,
pub destination_options: Option<Ipv6RawExtHeader>,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/internet/ipv6_fragment_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::super::*;

/// IPv6 fragment header.
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6FragmentHeader {
/// IP protocol number specifying the next header or transport layer protocol.
///
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/internet/ipv6_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{err::ValueTooBigError, *};

/// IPv6 header according to rfc8200.
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6Header {
pub traffic_class: u8,
/// If non 0 serves as a hint to router and switches with multiple outbound paths that these packets should stay on the same path, so that they will not be reordered.
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/internet/ipv6_raw_ext_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ pub type Ipv6RawExtensionHeader = Ipv6RawExtHeader;
/// * Host Identity Protocol
/// * Shim6 Protocol
#[derive(Clone)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ipv6RawExtHeader {
/// IP protocol number specifying the next header or transport layer protocol.
///
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/double_vlan_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// IEEE 802.1Q double VLAN Tagging Header
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct DoubleVlanHeader {
/// The outer vlan tagging header
pub outer: SingleVlanHeader,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/ether_type_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
/// ```
///
#[derive(Default, PartialEq, Eq, Clone, Copy, Hash, Ord, PartialOrd)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct EtherType(pub u16);

impl EtherType {
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/ethernet2_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{err::Layer, err::SliceWriteSpaceError, *};

/// Ethernet II header.
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Ethernet2Header {
/// Source MAC Address
pub source: [u8; 6],
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/single_vlan_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// IEEE 802.1Q VLAN Tagging Header
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct SingleVlanHeader {
/// A 3 bit number which refers to the IEEE 802.1p class of service and maps to the frame priority level.
pub pcp: VlanPcp,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/link/vlan_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::*;

/// IEEE 802.1Q VLAN Tagging Header (can be single or double tagged).
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum VlanHeader {
/// IEEE 802.1Q VLAN Tagging Header
Single(SingleVlanHeader),
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmp_echo_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
/// originating Echo Requests and receiving Echo Replies, for diagnostic
/// purposes.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct IcmpEchoHeader {
/// An identifier to aid in matching Echo Replies to Echo Requests. May be zero.
pub id: u16,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv4/dest_unreachable_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
/// Codes 0, 1, 4, and 5 may be received from a gateway. Codes 2 and
/// 3 may be received from a host.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DestUnreachableHeader {
/// Network unreachable error.
Network,
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/// The header of an ICMPv4 Parameter Problems (contents up to
/// the offending ip header).
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ParameterProblemHeader {
/// Identifies the octet where an error was detected.
///
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv4/redirect_code.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// Code value in an ICMPv4 Redirect message.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum RedirectCode {
/// Redirect Datagram for the Network (or subnet)
RedirectForNetwork = 0,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv4/redirect_header.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
use super::*;

#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct RedirectHeader {
pub code: RedirectCode,
pub gateway_internet_address: [u8; 4],
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv4/time_exceeded_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

/// Code values for ICMPv4 time exceeded message.
#[derive(Copy, Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TimeExceededCode {
/// Time-to-live exceeded in transit.
TtlExceededInTransit = 0,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv4/timestamp_message.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/// A ICMPv4 timestamp or timestamp response message.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TimestampMessage {
pub id: u16,
pub seq: u16,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv4_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ use arrayvec::ArrayVec;
/// and code. But usually the static sized elements are part
/// of the header.
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Icmpv4Header {
/// Type & type specific values & code.
pub icmp_type: Icmpv4Type,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv6/dest_unreachable_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use super::*;
/// than congestion. (An ICMPv6 message MUST NOT be generated if a
/// packet is dropped due to congestion.)
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum DestUnreachableCode {
/// No route to destination
NoRoute = 0,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv6/parameter_problem_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use super::*;
///
/// Source: <https://www.iana.org/assignments/icmpv6-parameters/icmpv6-parameters.xhtml#icmpv6-parameters-codes-5>
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum ParameterProblemCode {
/// Erroneous header field encountered (from [RFC 4443](https://tools.ietf.org/html/rfc4443))
ErroneousHeaderField = 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

/// ICMPv6 parameter problem header.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct ParameterProblemHeader {
/// The code can offer additional informations about what kind of parameter
/// problem caused the error.
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv6/time_exceeded_code.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use super::*;

/// Code values for ICMPv6 time exceeded message.
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TimeExceededCode {
/// "hop limit exceeded in transit"
HopLimitExceeded = 0,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv6_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ use arrayvec::ArrayVec;

/// The statically sized data at the start of an ICMPv6 packet (at least the first 8 bytes of an ICMPv6 packet).
#[derive(Clone, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct Icmpv6Header {
/// Type & type specific values & code.
pub icmp_type: Icmpv6Type,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/icmpv6_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ use crate::{
/// # }
/// ```
#[derive(Clone, Copy, Debug, PartialEq, Eq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum Icmpv6Type {
/// In case of an unknown icmp type is received the header elements of
/// the first 8 bytes/octets are stored raw in this enum value.
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/tcp_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ pub const TCP_MAXIMUM_DATA_OFFSET: u8 = 0xf;
///
/// Field descriptions copied from RFC 793 page 15++
#[derive(Clone, Debug, Eq, PartialEq, Hash)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct TcpHeader {
/// The source port number.
pub source_port: u16,
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/transport_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::{

/// The possible headers on the transport layer
#[derive(Clone, Debug, Eq, PartialEq)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub enum TransportHeader {
Udp(UdpHeader),
Tcp(TcpHeader),
Expand Down
1 change: 1 addition & 0 deletions etherparse/src/transport/udp_header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ use crate::{err::ValueTooBigError, *};

/// Udp header according to rfc768.
#[derive(Clone, Debug, Eq, PartialEq, Default)]
#[cfg_attr(feature = "serde", derive(serde::Serialize, serde::Deserialize))]
pub struct UdpHeader {
/// Source port of the packet (optional).
pub source_port: u16,
Expand Down