Skip to content

zoryamba/serde_zipson

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

62 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

serde_zipson

serde_zipson is serde-compatible Rust implementation of zipson compression format.

serde_zipson playground is available on Github Pages

Usage

Serialize

use indexmap::IndexMap;
use serde_zipson::ser::to_string;
use serde_zipson::value::{Number, Value};

fn main() {
    let string = to_string(
        &Value::Object(
            IndexMap::from([
                ("x".to_string(), Value::Number(Number::Int(1))),
                ("y".to_string(), Value::Number(Number::Int(2)))
            ])
        ),
        true, // full_precision_floats
        true, // detect_utc_timestamps
    ).unwrap();

    assert_eq!(string, "{´x´Ê´y´Ë}");
}

Deserialize

use indexmap::IndexMap;
use serde_zipson::de::from_str;
use serde_zipson::value::{Number, Value};

fn main() {
    let value = from_str::<Value>("{´x´Ê´y´Ë}").unwrap();

    assert_eq!(
        value,
        Value::Object(
            IndexMap::from([
                ("x".to_string(), Value::Number(Number::Int(1))),
                ("y".to_string(), Value::Number(Number::Int(2)))
            ])
        )
    );
}

Convert to JSON

use serde_zipson::de::from_str;
use serde_zipson::value::Value;

fn main() {
    let zipson_value = from_str::<Value>("{´x´Ê´y´Ë}").unwrap();

    let json_value = serde_json::to_value(zipson_value).unwrap();

    let json_string = json_value.to_string();

    assert_eq!(json_string, "{\"x\":1,\"y\":2}");
}

Convert from JSON

use serde_json::from_str;
use serde_zipson::value::Value;
use serde_zipson::ser::to_string;

fn main() {
    let json_value = from_str::<serde_json::Value>("{\"x\":1,\"y\":2}").unwrap();

    let zipson_value = serde_json::from_value::<Value>(json_value).unwrap();

    let zipson_string = to_string(&zipson_value, true, true).unwrap();

    assert_eq!(zipson_string, "{´x´Ê´y´Ë}");
}

Known issues

  • serialize_struct/deserialize_struct are not implemented yet, so serde derive doesn't work for structs
  • serialize_enum/deserialize_enum are not implemented yet, so serde derive doesn't work for enums
  • serde_zipson panics on integer overflow
  • serde_zipson object template feature not working yet, so [{"key":"value1"},{"key":"value2"}] ends up in |{¨key¨¨value1¨}{ß0¨value2¨}÷ instead of |¦¨key¨‡¨value1¨¨value2¨—÷

License

Licensed under either of Apache License, Version 2.0 or MIT license at your option.
Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in this crate by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

About

No description, website, or topics provided.

Resources

License

Apache-2.0, MIT licenses found

Licenses found

Apache-2.0
LICENSE-APACHE
MIT
LICENSE-MIT

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages