5个版本 (1个稳定版)
新 1.0.0 | 2024年8月23日 |
---|---|
0.3.0 | 2024年8月12日 |
0.2.1 | 2024年8月7日 |
0.2.0 | 2024年8月6日 |
0.1.0 | 2024年8月6日 |
在解析器实现中排名第661
每月下载量476
1.5MB
516 行
mca
一个简单但有效且快速的Minecraft区域文件(mca)读写器。
读取示例
use std::{fs::File, io::Read};
use mca::RegionReader;
let mut data = Vec::new();
File::open("r.0.0.mca")?.read_to_end(&mut data)?;
// Initialize the region
// This mostly just validates the header
let region = RegionReader::new(&data)?;
// Get a specific chunk based of it's chunk coordinates
let chunk = region.get_chunk(0, 0)?.unwrap();
// Decompress the chunk data
// This will most commonly be either ZLib or LZ4 compressed
let decompressed = chunk.decompress()?;
// You can now bring your own NBT parser to parse the actual chunk data here
// I recommend either `simdnbt` or `fastnbt` for this.
写入示例
use std::{fs::File};
use mca::RegionWriter;
let data = vec![]; // some chunk data to write
// Initialize the region writer
let mut writer = RegionWriter::new();
// Push a chunk to the writer
writer.push_chunk(&data, 0, 0)?;
// Write the writer to a buffer
let mut buf = vec![];
writer.write(&mut buf)?;
// Write the buffer to a file
File::create("r.0.0.mca")?.write_all(&buf)?;
不安全功能
启用unsafe
功能将向代码中添加不安全的get_unchecked
调用。
这提高了性能约50% - 100%(我们谈论的是2-3纳秒更快)。
我认为我已经添加了足够的手动边界检查以使它安全,但我无法保证。
我已经在几百MB的区域文件上进行了测试,并且没有出现任何问题。
请注意,启用unsafe
将改变RegionReader::get_timestamp
函数的签名,使其返回一个结果
读取器基准测试
包含一个基准测试,与唯一找到的另一个
mca解析器(mca-parser
)进行比较,这个crate只是比(启用unsafe
)快了1-3ns
。
一个非常愚蠢、微小的误差差异,但嗯,这似乎“更快”。
您可以使用cargo bench
或cargo bench --features unsafe
来运行不安全的版本。