diff --git a/Cargo.lock b/Cargo.lock index 14c7909..6ded61d 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -31,6 +31,12 @@ version = "1.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a" +[[package]] +name = "byteorder" +version = "1.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "14c189c53d098945499cdfa7ecc63567cf3886b3332b312a5b4585d8d3a6a610" + [[package]] name = "clap" version = "3.2.20" @@ -101,6 +107,12 @@ dependencies = [ "hashbrown", ] +[[package]] +name = "iter-read" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c397ca3ea05ad509c4ec451fea28b4771236a376ca1c69fd5143aae0cf8f93c4" + [[package]] name = "itoa" version = "1.0.3" @@ -113,6 +125,36 @@ version = "0.2.132" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "8371e4e5341c3a96db127eb2465ac681ced4c433e01dd0e938adbef26ba93ba5" +[[package]] +name = "num-bigint" +version = "0.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "f93ab6289c7b344a8a9f60f88d80aa20032336fe78da341afc91c8a2341fc75f" +dependencies = [ + "autocfg", + "num-integer", + "num-traits", +] + +[[package]] +name = "num-integer" +version = "0.1.45" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "225d3389fb3509a24c93f5c29eb6bde2586b98d9f016636dff58d7c6f7569cd9" +dependencies = [ + "autocfg", + "num-traits", +] + +[[package]] +name = "num-traits" +version = "0.2.15" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "578ede34cf02f8924ab9447f50c28075b4d3e5b269972345e7e0372b38c6cdcd" +dependencies = [ + "autocfg", +] + [[package]] name = "once_cell" version = "1.14.0" @@ -193,6 +235,19 @@ dependencies = [ "serde_derive", ] +[[package]] +name = "serde-pickle" +version = "1.1.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "c762ad136a26407c6a80825813600ceeab5e613660d93d79a41f0ec877171e71" +dependencies = [ + "byteorder", + "iter-read", + "num-bigint", + "num-traits", + "serde", +] + [[package]] name = "serde-transcode" version = "1.1.1" @@ -276,6 +331,7 @@ dependencies = [ "clap", "ron", "serde", + "serde-pickle", "serde-transcode", "serde_json", "serde_yaml", diff --git a/Cargo.toml b/Cargo.toml index 6c189f0..b8ba452 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -24,6 +24,9 @@ serde-transcode = "1.1.1" # Data types we support # Should tend to be equal to the official list of data formats supported by serde: https://serde.rs/#data-formats -ron = "0.8" +#ciborium = "0.2" serde_json = "1.0" +serde-pickle = "1.0" +ron = "0.8" +#toml = "0.5" serde_yaml = "0.9" diff --git a/src/lib.rs b/src/lib.rs index 92d913c..4c6a776 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -24,6 +24,7 @@ pub struct Opt { #[derive(Copy, Clone, Debug, ValueEnum)] pub enum Input { Json, + Pickle, Ron, Yaml, } @@ -31,6 +32,7 @@ pub enum Input { #[derive(Copy, Clone, Debug, ValueEnum)] pub enum Output { Json, + Pickle, Ron, Yaml, } @@ -61,6 +63,12 @@ fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) { let mut deserializer = Deserializer::from_reader(input); ser(opt, &mut deserializer, output); } + Input::Pickle => { + use serde_pickle::Deserializer; + + let mut deserializer = Deserializer::new(input, serde_pickle::DeOptions::new()); + ser(opt, &mut deserializer, output); + } Input::Ron => { use ron::Deserializer; @@ -102,6 +110,13 @@ where // NOTE: serde_json’s PrettyFormatter and CompactFormatter are incompatibles… // serde_transcode::transcode(deserializer, serializer).unwrap(); } + Output::Pickle => { + use serde_pickle::Serializer; + + let serializer = &mut Serializer::new(output, serde_pickle::SerOptions::new()); + + serde_transcode::transcode(deserializer, serializer).unwrap(); + } Output::Ron => { use ron::Serializer;