-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from savannstm/0.3.0
0.3.0
- Loading branch information
Showing
9 changed files
with
763 additions
and
731 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,13 @@ | ||
[package] | ||
name = "marshal-rs" | ||
version = "0.2.4" | ||
version = "0.3.0" | ||
authors = ["savannstm <[email protected]>"] | ||
edition = "2021" | ||
rust-version = "1.63.0" | ||
description = "Blazingly fast Ruby-lang's Marshal implementation in Rust." | ||
readme = "README.md" | ||
repository = "https://github.com/savannstm/marshal-rs" | ||
documentation = "https://docs.rs/marshal-rs/" | ||
license-file = "LICENSE.md" | ||
keywords = ["marshal", "ruby", "serialize", "deserialize"] | ||
|
||
|
@@ -15,11 +16,10 @@ sonic = ["dep:sonic-rs"] | |
default = ["dep:serde_json"] | ||
|
||
[dependencies] | ||
cfg-if = "1.0.0" | ||
encoding_rs = "0.8.34" | ||
num-bigint = "0.4.6" | ||
serde_json = { version = "1.0.125", optional = true, features = ["preserve_order"] } | ||
sonic-rs = { version = "0.3.11", optional = true } | ||
serde_json = { version = "1.0.128", optional = true, features = ["preserve_order"] } | ||
sonic-rs = { version = "0.3.13", optional = true } | ||
|
||
[dev-dependencies] | ||
rayon = "1.10.0" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,28 +1,24 @@ | ||
use cfg_if::cfg_if; | ||
use marshal_rs::{dump::dump, load::load}; | ||
cfg_if! { | ||
if #[cfg(feature = "sonic")] { | ||
use sonic_rs::json; | ||
} else { | ||
use serde_json::json; | ||
} | ||
} | ||
use marshal_rs::{dump, load}; | ||
#[cfg(not(feature = "sonic"))] | ||
use serde_json::json; | ||
#[cfg(feature = "sonic")] | ||
use sonic_rs::json; | ||
|
||
fn main() { | ||
// Bytes slice of Ruby Marshal data | ||
// Files with Marshal data can be read with std::fs::read() | ||
let bytes: [u8; 3] = [0x04, 0x08, 0x30]; // null | ||
let null_bytes: [u8; 3] = [0x04, 0x08, 0x30]; // null | ||
|
||
// Serialize bytes to a Value | ||
// If "sonic" feature is enabled, returns sonic_rs::Value, otherwise serde_json::Value | ||
let json = load(&bytes, None, None); | ||
let json = load(&null_bytes, None, None).unwrap(); | ||
assert_eq!(json, json!(null)); | ||
|
||
// Here you may write the json object to file using std::fs::write() | ||
|
||
// Deserialize object back to bytes | ||
let marshal: Vec<u8> = dump(json, None); | ||
assert_eq!(&marshal, &bytes); | ||
let marshal_bytes: Vec<u8> = dump(json, None); | ||
assert_eq!(&marshal_bytes, &null_bytes); | ||
|
||
// Here you may write bytes back to the Marshal file | ||
} |
Oops, something went wrong.