#nbt #minecraft #io #binary-format #binary-data #read-write

named-binary-tag

格式用于 Minecraft 保存数据的各种文件

9 个版本 (5 个重大更改)

0.6.0 2021 年 3 月 21 日
0.5.0 2020 年 11 月 30 日
0.4.0 2020 年 11 月 4 日
0.3.0 2020 年 10 月 3 日
0.1.0 2019 年 10 月 13 日

#757 in 游戏

Download history 97/week @ 2024-03-11 63/week @ 2024-03-18 35/week @ 2024-03-25 99/week @ 2024-04-01 37/week @ 2024-04-08 40/week @ 2024-04-15 71/week @ 2024-04-22 56/week @ 2024-04-29 46/week @ 2024-05-06 40/week @ 2024-05-13 67/week @ 2024-05-20 31/week @ 2024-05-27 35/week @ 2024-06-03 61/week @ 2024-06-10 43/week @ 2024-06-17 34/week @ 2024-06-24

每月 176 次下载
用于 5 crates

MIT 许可证

48KB
1K SLoC

named-binary-tag

crates.io Build Status codecov

NBT(命名二进制标签)是一种基于标签的二进制格式,旨在携带大量二进制数据,同时附加少量额外数据。

用法

将此添加到您的 Cargo.toml

[dependencies]
named-binary-tag = "0.6"

示例

读取

use nbt::decode::read_compound_tag;
use std::io::Cursor;

let mut cursor = Cursor::new(include_bytes!("../test/binary/servers.dat").to_vec());
let root_tag = read_compound_tag(&mut cursor).unwrap();

let servers = root_tag.get_compound_tag_vec("servers").unwrap();
assert_eq!(servers.len(), 1);

let server = servers[0];
let ip = server.get_str("ip").unwrap();
let name = server.get_str("name").unwrap();
let hide_address = server.get_bool("hideAddress").unwrap();

assert_eq!(ip, "localhost:25565");
assert_eq!(name, "Minecraft Server");
assert!(hide_address);

写入

use nbt::encode::write_compound_tag;
use nbt::CompoundTag;

let mut server = CompoundTag::new();

server.insert_str("ip", "localhost:25565");
server.insert_str("name", "Minecraft Server");
server.insert_bool("hideAddress", true);

let mut servers = Vec::new();
servers.push(server);

let mut root_tag = CompoundTag::new();
root_tag.insert_compound_tag_vec("servers", servers);

let mut vec = Vec::new();
write_compound_tag(&mut vec, &root_tag).unwrap();

依赖关系

~480KB