代码拉取完成,页面将自动刷新
use std::str::FromStr;
use jppe::{ByteDecode, ByteEncode};
use jppe_derive::{ByteEncode, ByteDecode};
use jppe::prelude::MacAddress;
#[derive(Debug, PartialEq, Eq, ByteEncode, ByteDecode)]
pub struct Ethernet {
pub smac: MacAddress,
pub dmac: MacAddress,
pub r#type: u16,
}
fn main() {
let input = b"\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00\x45\x00";
// decode
let (input_remain, value) = Ethernet::decode(input, None, None).unwrap();
println!("{value:?} {input_remain:?}");
assert_eq!(value, Ethernet {
smac: MacAddress::from_str("ff:ff:ff:ff:ff:ff").unwrap(),
dmac: MacAddress::from_str("00:00:00:00:00:00").unwrap(),
r#type: 0x0800,
});
// encode
let mut buf = vec![];
value.encode(&mut buf, None, None);
assert_eq!(buf, b"\xff\xff\xff\xff\xff\xff\x00\x00\x00\x00\x00\x00\x08\x00");
assert_eq!(input_remain, b"\x45\x00");
}
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。