Attempt to add support for BSON
This commit is contained in:
parent
2cdcea5391
commit
20c45f269c
@ -24,6 +24,7 @@ serde-transcode = "1.1.1"
|
|||||||
|
|
||||||
# Data types we support
|
# Data types we support
|
||||||
# Should tend to be equal to the official list of data formats supported by serde: https://serde.rs/#data-formats
|
# Should tend to be equal to the official list of data formats supported by serde: https://serde.rs/#data-formats
|
||||||
|
#bson = "2.3"
|
||||||
#ciborium = "0.2"
|
#ciborium = "0.2"
|
||||||
serde_json = "1.0"
|
serde_json = "1.0"
|
||||||
serde-pickle = "1.0"
|
serde-pickle = "1.0"
|
||||||
|
30
src/lib.rs
30
src/lib.rs
@ -23,17 +23,23 @@ pub struct Opt {
|
|||||||
|
|
||||||
#[derive(Copy, Clone, Debug, ValueEnum)]
|
#[derive(Copy, Clone, Debug, ValueEnum)]
|
||||||
pub enum Input {
|
pub enum Input {
|
||||||
|
//Bson,
|
||||||
|
//Cbor,
|
||||||
Json,
|
Json,
|
||||||
Pickle,
|
Pickle,
|
||||||
Ron,
|
Ron,
|
||||||
|
//Toml
|
||||||
Yaml,
|
Yaml,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, ValueEnum)]
|
#[derive(Copy, Clone, Debug, ValueEnum)]
|
||||||
pub enum Output {
|
pub enum Output {
|
||||||
|
//Bson,
|
||||||
|
//Cbor,
|
||||||
Json,
|
Json,
|
||||||
Pickle,
|
Pickle,
|
||||||
Ron,
|
Ron,
|
||||||
|
//Toml,
|
||||||
Yaml,
|
Yaml,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,6 +62,14 @@ pub fn transcode(opt: Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
|||||||
|
|
||||||
fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
||||||
match opt.input {
|
match opt.input {
|
||||||
|
/*
|
||||||
|
Input::Bson => {
|
||||||
|
use bson::Deserializer;
|
||||||
|
|
||||||
|
let mut deserializer = bson::from_reader(input).unwrap(); // FIXME: need which type annotation?
|
||||||
|
ser(opt, &mut deserializer, output);
|
||||||
|
}
|
||||||
|
*/
|
||||||
Input::Json => {
|
Input::Json => {
|
||||||
use serde_json::Deserializer;
|
use serde_json::Deserializer;
|
||||||
|
|
||||||
@ -66,6 +80,7 @@ fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
|||||||
Input::Pickle => {
|
Input::Pickle => {
|
||||||
use serde_pickle::Deserializer;
|
use serde_pickle::Deserializer;
|
||||||
|
|
||||||
|
// NOTE: Apparently serde_pickle do not implement `Deserializer` on const?
|
||||||
let mut deserializer = Deserializer::new(input, serde_pickle::DeOptions::new());
|
let mut deserializer = Deserializer::new(input, serde_pickle::DeOptions::new());
|
||||||
ser(opt, &mut deserializer, output);
|
ser(opt, &mut deserializer, output);
|
||||||
}
|
}
|
||||||
@ -93,6 +108,21 @@ where
|
|||||||
D: Deserializer<'de>,
|
D: Deserializer<'de>,
|
||||||
{
|
{
|
||||||
match opt.output {
|
match opt.output {
|
||||||
|
/*
|
||||||
|
Output::Bson => {
|
||||||
|
use bson::Serializer;
|
||||||
|
|
||||||
|
let options = bson::SerializerOptions::builder();
|
||||||
|
let options = if opt.pretty {
|
||||||
|
options.human_readable(true)
|
||||||
|
} else {
|
||||||
|
options.human_readable(false)
|
||||||
|
};
|
||||||
|
|
||||||
|
let serializer = Serializer::new_with_options(options.build()); // FIXME: why no way to tell the serializer were we want the output?
|
||||||
|
serde_transcode::transcode(deserializer, serializer).unwrap();
|
||||||
|
}
|
||||||
|
*/
|
||||||
Output::Json => {
|
Output::Json => {
|
||||||
use serde_json::Serializer;
|
use serde_json::Serializer;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user