重构目录结构

This commit is contained in:
shenjack 2024-02-26 21:45:04 +08:00
parent 618dd911c5
commit f0632bb09a
Signed by: shenjack
GPG Key ID: 7B1134A979775551
21 changed files with 119 additions and 41 deletions

52
.vscode/settings.json vendored
View File

@ -1,9 +1,47 @@
{ {
"rust-analyzer.linkedProjects": [ "files.associations": {
"crates/shen-nbt1/Cargo.toml", "*.html": "html",
"crates/shen-nbt2/Cargo.toml", "__bit_reference": "cpp",
"crates/shen-nbt3/Cargo.toml", "__config": "cpp",
"crates/shen-nbt4/Cargo.toml", "__hash_table": "cpp",
"crates/nbt-test/Cargo.toml", "__locale": "cpp",
] "__node_handle": "cpp",
"__split_buffer": "cpp",
"__threading_support": "cpp",
"__verbose_abort": "cpp",
"array": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdint": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"execution": "cpp",
"initializer_list": "cpp",
"ios": "cpp",
"iosfwd": "cpp",
"limits": "cpp",
"locale": "cpp",
"mutex": "cpp",
"new": "cpp",
"optional": "cpp",
"ratio": "cpp",
"span": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"string": "cpp",
"string_view": "cpp",
"tuple": "cpp",
"typeinfo": "cpp",
"unordered_map": "cpp",
"variant": "cpp",
"vector": "cpp",
"algorithm": "cpp"
}
} }

10
Cargo.toml Normal file
View File

@ -0,0 +1,10 @@
[workspace]
members = [
"nbt-test",
# "shen-nbt1", # EOL!
"shen-nbt2",
"shen-nbt3",
"shen-nbt4",
"shen-nbt5",
]
resolver = "2"

View File

@ -192,7 +192,6 @@ fn test_fastnbt(data: Vec<u8>) {
} }
fn read_test(in_data: Vec<u8>) { fn read_test(in_data: Vec<u8>) {
let len = in_data.len();
#[cfg(feature = "debug")] #[cfg(feature = "debug")]
println!("data: {:?}", data); println!("data: {:?}", data);
@ -219,44 +218,65 @@ fn cli_read_test() {
let mut args = std::env::args(); let mut args = std::env::args();
// 如果有, 取出 // 如果有, 取出
if let Some(arg) = args.nth(1) { if let Some(arg) = args.nth(1) {
let data = std::fs::read(&arg).unwrap(); let read_data = std::fs::read(&arg).unwrap();
// read_test(data); // read_test(data);
let len = data.len(); let len = read_data.len();
test_lib!( let data = read_data;
{
let cursor: shen_nbt1::data::Reader = std::io::Cursor::new(data.as_slice());
let nbt_data = shen_nbt1::data::NbtItem::try_from(cursor).unwrap();
}, "nbt v1", len std::thread::sleep(std::time::Duration::from_secs(1));
let start_time = std::time::Instant::now();
let nbt_data = shen_nbt4::Value::from_vec(data);
let end_time = std::time::Instant::now();
println!("=== shen nbt 4 ===");
print!("time: {:?}", end_time - start_time);
println!(" speed: {:?} (bytes/sec)", len as f64 / (end_time - start_time).as_secs_f64());
println!("{:?} (kb/sec)", len as f64 / (end_time - start_time).as_secs_f64() / 1024.0);
println!(
"{:?} (mb/sec)",
len as f64 / (end_time - start_time).as_secs_f64() / 1024.0 / 1024.0
); );
println!(
"{:?} (gb/sec)",
len as f64 / (end_time - start_time).as_secs_f64() / 1024.0 / 1024.0 / 1024.0
);
#[cfg(feature = "core_debug")]
println!("nbt_data: {:#?}", nbt_data);
println!("nbt len {}", nbt_data.as_byte().is_some());
// test_lib!(
// {
// let cursor: shen_nbt1::data::Reader = std::io::Cursor::new(data.as_slice());
// let nbt_data = shen_nbt1::data::NbtItem::try_from(cursor).unwrap();
let data2 = std::fs::read(&arg).unwrap(); // }, "nbt v1", len
test_lib!( // );
{
let nbt_data = shen_nbt2::Value::from_vec(data2);
}, "nbt v2", len
);
let data3 = std::fs::read(&arg).unwrap(); // let data2 = std::fs::read(&arg).unwrap();
test_lib!( // test_lib!(
{ // {
let nbt_data = shen_nbt3::Value::from_vec(data3); // let nbt_data = shen_nbt2::Value::from_vec(data2);
}, "nbt v3", len // }, "nbt v2", len
); // );
let data4 = std::fs::read(&arg).unwrap(); // let data3 = std::fs::read(&arg).unwrap();
test_lib!( // test_lib!(
{ // {
let nbt_data = shen_nbt4::Value::from_vec(data4); // let nbt_data = shen_nbt3::Value::from_vec(data3);
}, "nbt v4", len // }, "nbt v3", len
); // );
let data5 = std::fs::read(&arg).unwrap(); // let data4 = std::fs::read(&arg).unwrap();
test_lib!( // test_lib!(
{ // {
let nbt_data: fastnbt::Value = fastnbt::from_bytes(data5.as_slice()).unwrap(); // let nbt_data = shen_nbt4::Value::from_vec(data);
}, "fastnbt", len // }, "nbt v4", len
); // );
// let data5 = std::fs::read(&arg).unwrap();
// test_lib!(
// {
// let nbt_data: fastnbt::Value = fastnbt::from_bytes(data5.as_slice()).unwrap();
// }, "fastnbt", len
// );
} else { } else {
println!("Usage: cargo run --release -- <file>"); println!("Usage: cargo run --release -- <file>");
} }

View File

@ -1,5 +1,4 @@
use crate::data::{NbtItem, NbtList, NbtValue, Reader}; use crate::data::{NbtItem, NbtList, NbtValue, Reader};
use std::convert::From;
use std::io::{BufRead, Cursor, Read}; use std::io::{BufRead, Cursor, Read};
/// 输出类型标识符 /// 输出类型标识符

8
shen-nbt5/Cargo.toml Normal file
View File

@ -0,0 +1,8 @@
[package]
name = "shen-nbt5"
version = "0.1.0"
edition = "2021"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

3
shen-nbt5/src/main.rs Normal file
View File

@ -0,0 +1,3 @@
fn main() {
println!("Hello, world!");
}