Skip to content

Implememt Debug trait for the Packet enum #1

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

Merged
merged 1 commit into from
Jun 8, 2021
Merged
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
4 changes: 2 additions & 2 deletions src/packet/cbr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_cbr, pt_packet_type_ppt_cbr};

/// A CBR packet.
/// Packet: cbr
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Cbr (pt_packet_cbr);
impl Cbr {
#[inline]
Expand All @@ -18,4 +18,4 @@ impl Cbr {
}

wrap2raw!(Cbr, pt_packet_type_ppt_cbr, cbr);
raw2wrap!(Cbr, Cbr, pt_packet_cbr);
raw2wrap!(Cbr, Cbr, pt_packet_cbr);
4 changes: 2 additions & 2 deletions src/packet/cyc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_cyc, pt_packet_type_ppt_cyc};

/// A CYC packet.
/// Packet: cyc
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Cyc (pt_packet_cyc);
impl Cyc {
#[inline]
Expand All @@ -18,4 +18,4 @@ impl Cyc {
}

wrap2raw!(Cyc, pt_packet_type_ppt_cyc, cyc);
raw2wrap!(Cyc, Cyc, pt_packet_cyc);
raw2wrap!(Cyc, Cyc, pt_packet_cyc);
4 changes: 2 additions & 2 deletions src/packet/invalid.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use libipt_sys::pt_packet;

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Invalid {}

impl Into<Invalid> for pt_packet {
fn into(self) -> Invalid { Invalid{} }
}
}
12 changes: 6 additions & 6 deletions src/packet/ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ use libipt_sys::{
};

/// The IP compression
#[derive(Clone, Copy, TryFromPrimitive, IntoPrimitive)]
#[derive(Clone, Copy, Debug, TryFromPrimitive, IntoPrimitive)]
#[repr(i32)]
pub enum Compression {
/// No payload. The IP has been suppressed
Expand All @@ -39,7 +39,7 @@ pub enum Compression {

/// A packet with IP payload.
/// Packet: tip
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Tip (pt_packet_ip);
impl Tip {
#[inline]
Expand Down Expand Up @@ -71,7 +71,7 @@ impl Tip {

/// A packet with IP payload.
/// Packet: fup
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Fup (pt_packet_ip);
impl Fup {
#[inline]
Expand Down Expand Up @@ -103,7 +103,7 @@ impl Fup {

/// A packet with IP payload.
/// Packet: tip.pge
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct TipPge (pt_packet_ip);
impl TipPge {
#[inline]
Expand Down Expand Up @@ -135,7 +135,7 @@ impl TipPge {

/// A packet with IP payload.
/// Packet: tip.pgd
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct TipPgd (pt_packet_ip);
impl TipPgd {
#[inline]
Expand Down Expand Up @@ -175,4 +175,4 @@ wrap2raw!(TipPge, pt_packet_type_ppt_tip_pge, ip);
raw2wrap!(TipPge, TipPge, pt_packet_ip);

wrap2raw!(TipPgd, pt_packet_type_ppt_tip_pgd, ip);
raw2wrap!(TipPgd, TipPgd, pt_packet_ip);
raw2wrap!(TipPgd, TipPgd, pt_packet_ip);
4 changes: 2 additions & 2 deletions src/packet/mnt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_mnt, pt_packet_type_ppt_mnt};

/// A MNT packet.
/// Packet: mnt
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Mnt (pt_packet_mnt);
impl Mnt {
#[inline]
Expand All @@ -18,4 +18,4 @@ impl Mnt {
}

wrap2raw!(Mnt, pt_packet_type_ppt_mnt, mnt);
raw2wrap!(Mnt, Mnt, pt_packet_mnt);
raw2wrap!(Mnt, Mnt, pt_packet_mnt);
38 changes: 37 additions & 1 deletion src/packet/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Formatter};

use libipt_sys::{
pt_packet,
pt_packet_type_ppt_cbr as PT_PACKET_TYPE_PPT_CBR,
Expand Down Expand Up @@ -139,6 +141,40 @@ pub enum Packet<T> {
Ptw(ptw::Ptw)
}

impl<T> Debug for Packet<T> {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
match self {
Self::Invalid(pack) => f.write_fmt(format_args!("Invalid({:?})", pack)),
Self::Psbend(pack) => f.write_fmt(format_args!("Psbend({:?})", pack)),
Self::Stop(pack) => f.write_fmt(format_args!("Stop({:?})", pack)),
Self::Pad(pack) => f.write_fmt(format_args!("Pad({:?})", pack)),
Self::Psb(pack) => f.write_fmt(format_args!("Psb({:?})", pack)),
Self::Ovf(pack) => f.write_fmt(format_args!("Ovf({:?})", pack)),
Self::Unknown(_) => f.write_str("Unknown"),
Self::Fup(pack) => f.write_fmt(format_args!("Fup({:?})", pack)),
Self::Tip(pack) => f.write_fmt(format_args!("Tip({:?})", pack)),
Self::TipPge(pack) => f.write_fmt(format_args!("TipPge({:?})", pack)),
Self::TipPgd(pack) => f.write_fmt(format_args!("TipPgd({:?})", pack)),
Self::Tnt8(pack) => f.write_fmt(format_args!("Tnt8({:?})", pack)),
Self::Tnt64(pack) => f.write_fmt(format_args!("Tnt64({:?})", pack)),
Self::Mode(pack) => f.write_fmt(format_args!("Mode({:?})", pack)),
Self::Pip(pack) => f.write_fmt(format_args!("Pip({:?})", pack)),
Self::Vmcs(pack) => f.write_fmt(format_args!("Vmcs({:?})", pack)),
Self::Cbr(pack) => f.write_fmt(format_args!("Cbr({:?})", pack)),
Self::Tsc(pack) => f.write_fmt(format_args!("Tsc({:?})", pack)),
Self::Tma(pack) => f.write_fmt(format_args!("Tma({:?})", pack)),
Self::Mtc(pack) => f.write_fmt(format_args!("Mtc({:?})", pack)),
Self::Cyc(pack) => f.write_fmt(format_args!("Cyc({:?})", pack)),
Self::Mnt(pack) => f.write_fmt(format_args!("Mnt({:?})", pack)),
Self::Exstop(pack) => f.write_fmt(format_args!("Exstop({:?})", pack)),
Self::Mwait(pack) => f.write_fmt(format_args!("Mwait({:?})", pack)),
Self::Pwre(pack) => f.write_fmt(format_args!("Pwre({:?})", pack)),
Self::Pwrx(pack) => f.write_fmt(format_args!("Pwrx({:?})", pack)),
Self::Ptw(pack) => f.write_fmt(format_args!("Ptw({:?})", pack)),
}
}
}

impl<T> From<pt_packet> for Packet<T> {
fn from(pkt: pt_packet) -> Self {
unsafe {
Expand Down Expand Up @@ -174,4 +210,4 @@ impl<T> From<pt_packet> for Packet<T> {
}
}
}
}
}
12 changes: 10 additions & 2 deletions src/packet/mode.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use std::fmt::{Debug, Formatter};

use bitflags::bitflags;
use libipt_sys::{
pt_mode_leaf_pt_mol_exec as PT_MODE_LEAF_PT_MOL_EXEC,
Expand Down Expand Up @@ -107,7 +109,13 @@ impl Mode {
Payload::Tsx(t) => self.0.bits = t.into()
}
}
}
}

impl Debug for Mode {
fn fmt(&self, f: &mut Formatter) -> std::fmt::Result {
f.write_fmt(format_args!("Mode({{ leaf: {:?} }})", self.0.leaf))
}
}

wrap2raw!(Mode, pt_packet_type_ppt_mode, mode);
raw2wrap!(Mode, Mode, pt_packet_mode);
raw2wrap!(Mode, Mode, pt_packet_mode);
4 changes: 2 additions & 2 deletions src/packet/mtc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_mtc, pt_packet_type_ppt_mtc};

/// A MTC packet.
/// Packet: mtc
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Mtc (pt_packet_mtc);
impl Mtc {
#[inline]
Expand All @@ -18,4 +18,4 @@ impl Mtc {
}

wrap2raw!(Mtc, pt_packet_type_ppt_mtc, mtc);
raw2wrap!(Mtc, Mtc, pt_packet_mtc);
raw2wrap!(Mtc, Mtc, pt_packet_mtc);
4 changes: 2 additions & 2 deletions src/packet/ovf.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::mem;
use libipt_sys::{pt_packet, pt_packet_type_ppt_ovf};

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Ovf {}

impl Ovf {
Expand All @@ -20,4 +20,4 @@ impl From<Ovf> for pt_packet {

impl Into<Ovf> for pt_packet {
fn into(self) -> Ovf{ Ovf{} }
}
}
4 changes: 2 additions & 2 deletions src/packet/pad.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::mem;
use libipt_sys::{pt_packet, pt_packet_type_ppt_pad};

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Pad {}

impl Pad {
Expand All @@ -20,4 +20,4 @@ impl From<Pad> for pt_packet {

impl Into<Pad> for pt_packet {
fn into(self) -> Pad { Pad{} }
}
}
4 changes: 2 additions & 2 deletions src/packet/pip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use libipt_sys::{

/// A PIP packet.
/// Packet: pip
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Pip (pt_packet_pip);
impl Pip {
#[inline]
Expand Down Expand Up @@ -34,4 +34,4 @@ impl Pip {
}

wrap2raw!(Pip, pt_packet_type_ppt_pip, pip);
raw2wrap!(Pip, Pip, pt_packet_pip);
raw2wrap!(Pip, Pip, pt_packet_pip);
4 changes: 2 additions & 2 deletions src/packet/psb.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::mem;
use libipt_sys::{pt_packet, pt_packet_type_ppt_psb};

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Psb {}

impl Psb {
Expand All @@ -20,4 +20,4 @@ impl From<Psb> for pt_packet {

impl Into<Psb> for pt_packet {
fn into(self) -> Psb { Psb{} }
}
}
4 changes: 2 additions & 2 deletions src/packet/psbend.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::mem;
use libipt_sys::{pt_packet, pt_packet_type_ppt_psbend};

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Psbend {}

impl Psbend {
Expand All @@ -20,4 +20,4 @@ impl From<Psbend> for pt_packet {

impl Into<Psbend> for pt_packet {
fn into(self) -> Psbend { Psbend{} }
}
}
4 changes: 2 additions & 2 deletions src/packet/ptw.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use libipt_sys::{

/// A PTW packet.
/// Packet: ptw
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Ptw (pt_packet_ptw);
impl Ptw {
#[inline]
Expand Down Expand Up @@ -46,4 +46,4 @@ impl Ptw {
}

wrap2raw!(Ptw, pt_packet_type_ppt_ptw, ptw);
raw2wrap!(Ptw, Ptw, pt_packet_ptw);
raw2wrap!(Ptw, Ptw, pt_packet_ptw);
4 changes: 2 additions & 2 deletions src/packet/pwrx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_pwrx, pt_packet_type_ppt_pwrx};

/// A PWRX packet.
/// Packet: pwrx
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Pwrx (pt_packet_pwrx);
impl Pwrx {
#[inline]
Expand Down Expand Up @@ -76,4 +76,4 @@ impl Pwrx {
}

wrap2raw!(Pwrx, pt_packet_type_ppt_pwrx, pwrx);
raw2wrap!(Pwrx, Pwrx, pt_packet_pwrx);
raw2wrap!(Pwrx, Pwrx, pt_packet_pwrx);
4 changes: 2 additions & 2 deletions src/packet/stop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::mem;
use libipt_sys::{pt_packet, pt_packet_type_ppt_stop};

#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Stop {}

impl Stop {
Expand All @@ -20,4 +20,4 @@ impl From<Stop> for pt_packet {

impl Into<Stop> for pt_packet {
fn into(self) -> Stop { Stop{} }
}
}
4 changes: 2 additions & 2 deletions src/packet/tma.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_tma, pt_packet_type_ppt_tma};

/// A TMA packet.
/// Packet: tma
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Tma (pt_packet_tma);
impl Tma {
#[inline]
Expand All @@ -26,4 +26,4 @@ impl Tma {
}

wrap2raw!(Tma, pt_packet_type_ppt_tma, tma);
raw2wrap!(Tma, Tma, pt_packet_tma);
raw2wrap!(Tma, Tma, pt_packet_tma);
6 changes: 3 additions & 3 deletions src/packet/tnt.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use libipt_sys::{

/// A TNT-8 packet.
/// Packet: tnt-8
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Tnt8 (pt_packet_tnt);
impl Tnt8 {
#[inline]
Expand All @@ -32,7 +32,7 @@ impl Tnt8 {

/// A TNT-64 packet.
/// Packet: tnt-64
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Tnt64 (pt_packet_tnt);
impl Tnt64 {
#[inline]
Expand Down Expand Up @@ -60,4 +60,4 @@ wrap2raw!(Tnt8, pt_packet_type_ppt_tnt_8, tnt);
raw2wrap!(Tnt8, Tnt8, pt_packet_tnt);

wrap2raw!(Tnt64, pt_packet_type_ppt_tnt_64, tnt);
raw2wrap!(Tnt64, Tnt64, pt_packet_tnt);
raw2wrap!(Tnt64, Tnt64, pt_packet_tnt);
4 changes: 2 additions & 2 deletions src/packet/tsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use libipt_sys::{pt_packet_tsc, pt_packet_type_ppt_tsc};

/// A TSC packet.
/// Packet: tsc
#[derive(Clone, Copy)]
#[derive(Clone, Copy, Debug)]
pub struct Tsc (pt_packet_tsc);
impl Tsc {
#[inline]
Expand All @@ -18,4 +18,4 @@ impl Tsc {
}

wrap2raw!(Tsc, pt_packet_type_ppt_tsc, tsc);
raw2wrap!(Tsc, Tsc, pt_packet_tsc);
raw2wrap!(Tsc, Tsc, pt_packet_tsc);