6个版本 (3个稳定版)

2.0.0 2023年2月1日
1.0.1 2022年4月10日
1.0.0 2022年2月4日
0.1.0-dev.12021年11月30日
0.0.0-reserve.02021年11月29日

#1020编码

Download history 197/week @ 2024-03-11 137/week @ 2024-03-18 163/week @ 2024-03-25 259/week @ 2024-04-01 178/week @ 2024-04-08 179/week @ 2024-04-15 221/week @ 2024-04-22 171/week @ 2024-04-29 84/week @ 2024-05-06 94/week @ 2024-05-13 165/week @ 2024-05-20 172/week @ 2024-05-27 100/week @ 2024-06-03 106/week @ 2024-06-10 105/week @ 2024-06-17 104/week @ 2024-06-24

每月下载量436
12 个crate中使用 (直接使用3个)

MIT/Apache

29KB
615

ordered-varint

提供字节序可排序的可变长度有符号和无符号整数编码。

crate version Live Build Status HTML Coverage Report for main branch Documentation for main branch

该crate提供Variable trait,它将整数编码和解码为1到16字节的长度的缩写格式。所有有符号整数类型(i8、i16、i32、i64和i128)之间可以相互比较,所有无符号整数类型(u8、u16、u32、u64和u128)之间也可以相互比较。 但是,编码的有符号和无符号值不能有意义地相互比较。

示例

要运行包含的示例,请执行 cargo run --example demo。输出将类似于以下内容

Original bytes: 1968
Encoded bytes: 1068
1 encodes as [01]
3 encodes as [03]
7 encodes as [07]
15 encodes as [0f]
31 encodes as [10, 1f]
63 encodes as [10, 3f]
127 encodes as [10, 7f]
255 encodes as [10, ff]
511 encodes as [11, ff]
[...]
1329227995784915872903807060280344575 encodes as [f0, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
2658455991569831745807614120560689151 encodes as [f1, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
5316911983139663491615228241121378303 encodes as [f3, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
10633823966279326983230456482242756607 encodes as [f7, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]

运行以下命令可以获得显示有符号编码的另一个示例: cargo run --example demo-signed。输出将类似于以下内容

Original bytes: 3920
Encoded bytes: 2165
-5316911983139663491615228241121378305 encodes as [03, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
-2658455991569831745807614120560689153 encodes as [05, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
-1329227995784915872903807060280344577 encodes as [06, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
-664613997892457936451903530140172289 encodes as [07, 7f, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
[...]
-65 encodes as [77, bf]
-33 encodes as [77, df]
-17 encodes as [77, ef]
-9 encodes as [77, f7]
-5 encodes as [7b]
-3 encodes as [7d]
1 encodes as [81]
3 encodes as [83]
7 encodes as [87]
15 encodes as [88, 0f]
31 encodes as [88, 1f]
63 encodes as [88, 3f]
[...]
1329227995784915872903807060280344575 encodes as [f8, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
2658455991569831745807614120560689151 encodes as [f9, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
5316911983139663491615228241121378303 encodes as [fb, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]
10633823966279326983230456482242756607 encodes as [ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff, ff]

开源许可证

该项目,如所有来自Khonsu Labs的项目一样,是开源的。此仓库可在MIT许可证Apache许可证2.0下获得。

有关贡献的更多信息,请参阅CONTRIBUTING.md

无运行时依赖