5个版本

0.1.4 2020年1月10日
0.1.3 2019年9月27日
0.1.2 2019年9月13日
0.1.1 2019年9月6日
0.1.0 2019年8月30日

#2256 in 编码

每月 44 次下载
用于 velocystream

Apache-2.0

110KB
2K SLoC

rust-velocypack

Build Status Docs status codecov

Rust实现的VelocyPack协议,ArangoDB使用它进行序列化和反序列化。

状态

目前处于非常早期的工作状态,部分实现了序列化和反序列化,几乎没有文档。

目前实现了以下类型的(✓ = 已实现,空白 = 尚未实现,✗ = 未计划实现)

Serialize  Deserialize  Value type
✗          ✗            0x00 : none
✓          ✓            0x01 : empty array
✓          ✓            0x02 : array without index table, 1-byte byte length
✓          ✓            0x03 : array without index table, 2-byte byte length
✓          ✓            0x04 : array without index table, 4-byte byte length
✓          ✓            0x05 : array without index table, 8-byte byte length
✓          ✓            0x06 : array with 1-byte index table offsets, bytelen and # subvals
✓          ✓            0x07 : array with 2-byte index table offsets, bytelen and # subvals
✓          ✓            0x08 : array with 4-byte index table offsets, bytelen and # subvals
✓          ✓            0x09 : array with 8-byte index table offsets, bytelen and # subvals
✓          ✓            0x0a : empty object
✓          ✓            0x0b : object with 1-byte index table offsets, sorted by attribute name, 1-byte bytelen and # subvals
✓          ✓            0x0c : object with 2-byte index table offsets, sorted by attribute name, 2-byte bytelen and # subvals
✓          ✓            0x0d : object with 4-byte index table offsets, sorted by attribute name, 4-byte bytelen and # subvals
✓          ✓            0x0e : object with 8-byte index table offsets, sorted by attribute name, 8-byte bytelen and # subvals
✗          ✓            0x0f : object with 1-byte index table offsets, not sorted by attribute name, 1-byte bytelen and # subvals
✗          ✓            0x10 : object with 2-byte index table offsets, not sorted by attribute name, 2-byte bytelen and # subvals
✗          ✓            0x11 : object with 4-byte index table offsets, not sorted by attribute name, 4-byte bytelen and # subvals
✗          ✓            0x12 : object with 8-byte index table offsets, not sorted by attribute name, 8-byte bytelen and # subvals
✗          ✓            0x13 : compact array, no index table
✗          ✓            0x14 : compact object, no index table
✗          ✗            0x15-0x16 : reserved
✗          ✗            0x17 : illegal
✓          ✓            0x18 : null
✓          ✓            0x19 : false
✓          ✓            0x1a : true
✓          ✓            0x1b : double IEEE-754
                        0x1c : UTC-date
✗          ✗            0x1d : external (only in memory)
✗          ✗            0x1e : minKey
✗          ✗            0x1f : maxKey
✓          ✓            0x20-0x27 : signed int
✓          ✓            0x28-0x2f : uint
✓          ✓            0x30-0x39 : small integers
✓          ✓            0x3a-0x3f : small negative integers
✓          ✓            0x40-0xbe : UTF-8-string
✓          ✓            0xbf : long UTF-8-string
✓                       0xc0-0xc7 : binary blob
✗          ✗            0xc8-0xcf : positive long packed BCD-encoded float
✗          ✗            0xd0-0xd7 : negative long packed BCD-encoded float
✗          ✗            0xd8-0xef : reserved
✗          ✗            0xf0-0xff : custom types

示例

Cargo.toml:

[dependencies]
velocypack = "0.1.0"
serde = { version = "1.0", features = ["derive"] }

src/main.rs:

use serde::Serialize;

#[derive(Serialize)]
struct Person {
    name: String,
    age: u8,
    friends: Vec<Person>,
}

fn main() {
    let p = Person {
        name: "Bob".to_owned(),
        age: 23,
        friends: vec![
            Person {
                name: "Alice".to_owned(),
                age: 42,
                friends: Vec::new()
            }
        ]
    };
    println!("{:#04x?}", velocypack::to_bytes(&p).unwrap());
}

可以使用VelocyPack工具检查输出,例如。

$ cargo run > /tmp/bob.vpack && vpack-to-json --hex /tmp/bob.vpack /tmp/bob.json && cat /tmp/bob.json
Successfully converted JSON infile '/tmp/bob.vpack'
VPack Infile size: 63
JSON Outfile size: 137
{
  "age" : 23,
  "name" : "Bob",
  "friends" : [
    {
      "age" : 42,
      "name" : "Alice",
      "friends" : [
      ]
    }
  ]
}

依赖项

~1.5MB
~32K SLoC