#![feature(new_zeroed_alloc)]
#![feature(const_trait_impl)]
#![feature(generic_const_exprs)]
#![feature(specialization)]
use std::{
fmt,
fs::File,
hint::black_box,
io::{Read, Write},
mem::forget,
str::FromStr,
};
use fastbuf::{Buf, Buffer, ReadBuf, WriteBuf};
use serialization::binary_format::SerialDescriptor;
use serialization_minecraft::{PacketDecoder, PacketEncoder};
#[derive(Debug, serialization::Serializable, PartialEq, PartialOrd, Ord, Eq, Clone)]
pub struct Log {
pub address: Address,
pub identity: String,
pub userid: String,
pub date: String,
pub request: String,
pub code: u16,
pub size: u64,
}
#[derive(Debug, serialization::Serializable, PartialEq, PartialOrd, Ord, Eq, Clone)]
pub struct Logs {
pub logs: Vec<Log>,
}
#[derive(Debug, serialization::Serializable, PartialEq, PartialOrd, Ord, Eq, Clone, Copy)]
pub struct Address {
pub x0: u8,
pub x1: u8,
pub x2: u8,
pub x3: u8,
}
#[test]
fn testing() {
type D = PacketDecoder<&'static mut Buffer<100>>;
println!("logs {:?}", Logs::fields::<D>());
println!("log {:?}", Log::fields::<D>());
println!("address {:?}", Address::fields::<D>());
for i in 0..10 {
test_log();
}
}
fn test_log() {
const BUFFER_LEN: usize = 1024 * 1024 * 5000;
let mut buf = unsafe { Box::<Buffer<BUFFER_LEN>>::new_zeroed().assume_init() };
let value = Logs {
logs: vec![
Log {
address: Address {
x0: 11,
x1: 22,
x2: 33,
x3: 44,
},
identity: String::from_str("ABCD").unwrap(),
userid: String::from_str("ABCD").unwrap(),
date: String::from_str("ABCD").unwrap(),
request: String::from_str("ABCD").unwrap(),
code: 55,
size: 66,
};
10
],
};
let mut enc = PacketEncoder::new(&mut buf);
serialization::Encode::encode(&value, &mut enc).unwrap();
let buf_clone = buf.get_continuous(buf.remaining()).clone();
for i in 0..10 {
let mut buf = unsafe { Box::<Buffer<BUFFER_LEN>>::new_zeroed().assume_init() };
WriteBuf::write(&mut buf, &buf_clone);
let mut dec = serialization_minecraft::PacketDecoder::new(&mut buf);
let decoded = <Logs as serialization::Decode>::decode_placed(&mut dec);
let decoded = decoded.unwrap();
unsafe { buf.set_pos(0) };
black_box(&decoded);
}
drop(buf);
std::mem::forget(value);
}