2023-08-02 23:29:56 +08:00
|
|
|
|
# nbt-rust
|
|
|
|
|
|
2024-03-10 12:03:50 +08:00
|
|
|
|
一个 "全功能" 的 "快速" NBT 解析器
|
|
|
|
|
|
|
|
|
|
支持
|
|
|
|
|
|
|
|
|
|
- `Java`
|
|
|
|
|
- 也就是除了 1.20.2+ (协议号 >= 764) 之后的 网络传输用 NBT 格式
|
|
|
|
|
- 数据都是大端序
|
|
|
|
|
- 根节点必须有名称
|
|
|
|
|
- 根节点必须是一个 `NbtCompound(10)` 类型
|
|
|
|
|
- `JavaNetAfter1_20_2`
|
|
|
|
|
- Java 版在 1.20.2 之后的网络传输用 NBT 格式
|
|
|
|
|
- 数据都是大端序
|
|
|
|
|
- 根节点没有名称
|
|
|
|
|
- 根节点必须是一个 `NbtCompound(10)` 类型
|
|
|
|
|
- `BedrockDisk`
|
|
|
|
|
- 基岩版存在硬盘里的 NBT 格式
|
|
|
|
|
- 数据都是小端序
|
|
|
|
|
- 根节点必须有名称
|
|
|
|
|
- 根节点是 `NbtCompound(10)` 或者 `NbtList(9)` 类型
|
|
|
|
|
- `BedrockNetVarInt`
|
|
|
|
|
- 基岩版用于网络传输的 NBT 格式
|
|
|
|
|
|
|
|
|
|
- ```text
|
|
|
|
|
这种格式比其他格式稍微复杂一些。与Java版本的big-endian格式的区别如下:
|
|
|
|
|
|
|
|
|
|
TAG_Short、TAG_Float和TAG_Double值被编码为其小端对应值
|
|
|
|
|
TAG_Int值以及TAG_List、TAG_Byte_Array、TAG_Int_Array和TAG_Long_Array的长度前缀均编码为使用ZigZag编码的VarInt
|
|
|
|
|
TAG_Long值使用ZigZag编码被编码为VarLong
|
|
|
|
|
所有字符串(标记名称和TAG_String值)都以普通的VarInt作为长度前缀
|
|
|
|
|
|
|
|
|
|
---- https://wiki.vg/NBT
|
|
|
|
|
```
|
|
|
|
|
|
2023-08-04 00:01:19 +08:00
|
|
|
|
|
|
|
|
|
writen in rust!
|
2023-08-04 00:21:50 +08:00
|
|
|
|
|
2024-03-10 12:03:50 +08:00
|
|
|
|
## 感谢
|
2023-08-04 00:21:50 +08:00
|
|
|
|
|
2024-03-10 12:03:50 +08:00
|
|
|
|
感谢 @langyo 和 @InfyniteHeap
|
2023-08-04 00:21:50 +08:00
|
|
|
|
在编写过程中的帮助(
|
2024-03-06 23:31:51 +08:00
|
|
|
|
|
2024-03-10 12:03:50 +08:00
|
|
|
|
感谢 [wiki.vg](https://wiki.vg/NBT) 存储的 NBT 格式的详细信息
|
|
|
|
|
|
2024-03-06 23:31:51 +08:00
|
|
|
|
## 概况
|
|
|
|
|
|
|
|
|
|
- `shen-nbt1`
|
|
|
|
|
- 几周的技术积累
|
|
|
|
|
- 100 mb/s
|
|
|
|
|
|
|
|
|
|
- `shen-nbt2`
|
|
|
|
|
- 2个月的技术积累
|
|
|
|
|
- 500 mb/s
|
|
|
|
|
|
|
|
|
|
- `shen-nbt3/4`
|
|
|
|
|
- 半年的技术积累
|
|
|
|
|
- v3 有单一依赖库
|
|
|
|
|
- v4 无依赖库
|
|
|
|
|
- 2000 mb/s
|
|
|
|
|
|
|
|
|
|
- `shen-nbt5` (编写中)
|
|
|
|
|
- 一年左右的技术积累
|
|
|
|
|
- 4000 mb/s ?
|
|
|
|
|
- 支持 `serde` 序列化/反序列化
|
2024-03-09 18:50:17 +08:00
|
|
|
|
|
|
|
|
|
## 测试数据
|
|
|
|
|
|
|
|
|
|
解压 `test-data.zip` 到 `test-data` 文件夹
|
|
|
|
|
|
|
|
|
|
```text
|
|
|
|
|
❯ cargo run --release -- .\test-data\test-zip
|
|
|
|
|
|
2024-03-09 19:04:11 +08:00
|
|
|
|
Hello, nbt!
|
2024-03-09 18:50:17 +08:00
|
|
|
|
============ small test ============
|
|
|
|
|
=== nbt v1 ===
|
2024-03-09 20:04:37 +08:00
|
|
|
|
time: 871.9694ms
|
|
|
|
|
speed: 1770.7043389366645 (bytes/s)
|
|
|
|
|
1.7292034559928364 (KB/s)
|
2024-03-09 18:50:17 +08:00
|
|
|
|
=== nbt v2 ===
|
2024-03-09 20:04:37 +08:00
|
|
|
|
time: 36.4µs
|
|
|
|
|
speed: 42417582.41758242 (bytes/s)
|
|
|
|
|
41423.420329670334 (KB/s)
|
|
|
|
|
40.452558915693686 (MB/s)
|
2024-03-09 18:50:17 +08:00
|
|
|
|
=== nbt v3 ===
|
2024-03-09 20:04:37 +08:00
|
|
|
|
time: 25.8µs
|
|
|
|
|
speed: 59844961.24031008 (bytes/s)
|
|
|
|
|
58442.34496124031 (KB/s)
|
|
|
|
|
57.07260250121124 (MB/s)
|
2024-03-09 18:50:17 +08:00
|
|
|
|
=== nbt v4 ===
|
2024-03-09 20:04:37 +08:00
|
|
|
|
time: 26.4µs
|
|
|
|
|
speed: 58484848.484848484 (bytes/s)
|
|
|
|
|
57114.10984848485 (KB/s)
|
|
|
|
|
55.775497898910984 (MB/s)
|
2024-03-09 18:50:17 +08:00
|
|
|
|
=== nbt v5 ===
|
2024-03-09 20:04:37 +08:00
|
|
|
|
time: 24.7µs
|
|
|
|
|
speed: 62510121.45748988 (bytes/s)
|
|
|
|
|
61045.04048582996 (KB/s)
|
|
|
|
|
59.61429734944332 (MB/s)
|
2024-03-09 18:50:17 +08:00
|
|
|
|
=== fastnbt ===
|
2024-03-09 20:04:37 +08:00
|
|
|
|
time: 38.9µs
|
|
|
|
|
speed: 39691516.70951157 (bytes/s)
|
|
|
|
|
38761.24678663239 (KB/s)
|
|
|
|
|
37.8527800650707 (MB/s)
|
2024-03-09 18:50:17 +08:00
|
|
|
|
============ cli test ============
|
|
|
|
|
=== shen nbt 5 ===
|
2024-03-09 20:04:37 +08:00
|
|
|
|
time: 2.3202808s
|
|
|
|
|
speed: 2483288579.985664 (bytes/s)
|
|
|
|
|
2425086.50389225 (KB/s)
|
|
|
|
|
2368.2485389572753 (MB/s)
|
|
|
|
|
2.312742713825464 (GB/s)
|
2024-03-09 18:50:17 +08:00
|
|
|
|
```
|