Commit 8ac62889 authored by RILLING Louis's avatar RILLING Louis
Browse files

tansiv-client: Implement Display for Buffer and MsgIn

parent a1086253
......@@ -119,6 +119,17 @@ pub struct Buffer {
inner: InnerBuffer,
}
impl fmt::Display for Buffer {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
let bytes = self.deref();
write!(f, "{:?} / \"", bytes)?;
for b in bytes {
write!(f, "{}", char::from(*b))?;
}
write!(f, "\"")
}
}
impl Drop for Buffer {
fn drop(&mut self) {
let pool = &self.pool;
......
......@@ -3,6 +3,7 @@ use binser_derive::{FromLe, IntoLe, ValidAsBytes, Validate};
use crate::buffer_pool::{Buffer, BufferPool};
use static_assertions::const_assert;
use std::convert::TryFrom;
use std::fmt;
use std::io::{Error, ErrorKind, Read, Result, Write};
use std::mem::size_of;
use std::time::Duration;
......@@ -195,6 +196,16 @@ pub enum MsgIn {
EndSimulation,
}
impl fmt::Display for MsgIn {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
use crate::vsg_address::to_ipv4addr;
match self {
MsgIn::DeliverPacket(src, dst, payload) => write!(f, "DeliverPacket(src = {}, dst = {}, payload = {})", to_ipv4addr(*src), to_ipv4addr(*dst), payload),
_ => fmt::Debug::fmt(self, f),
}
}
}
impl MsgIn {
// No const max macro...
fn max_header_size() -> usize {
......
......@@ -5,3 +5,7 @@ pub fn from_str(ip: &str) -> std::result::Result<libc::in_addr_t , std::net::Add
let ipv4 = Ipv4Addr::from_str(ip)?;
Ok(Into::<u32>::into(ipv4).to_be())
}
pub fn to_ipv4addr(address: libc::in_addr_t) -> Ipv4Addr {
Ipv4Addr::from(u32::from_be(address))
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment