Attempt to add support for BSON
This commit is contained in:
		@@ -24,6 +24,7 @@ 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
 | 
			
		||||
#bson = "2.3"
 | 
			
		||||
#ciborium = "0.2"
 | 
			
		||||
serde_json = "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)]
 | 
			
		||||
pub enum Input {
 | 
			
		||||
    //Bson,
 | 
			
		||||
    //Cbor,
 | 
			
		||||
    Json,
 | 
			
		||||
    Pickle,
 | 
			
		||||
    Ron,
 | 
			
		||||
    //Toml
 | 
			
		||||
    Yaml,
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#[derive(Copy, Clone, Debug, ValueEnum)]
 | 
			
		||||
pub enum Output {
 | 
			
		||||
    //Bson,
 | 
			
		||||
    //Cbor,
 | 
			
		||||
    Json,
 | 
			
		||||
    Pickle,
 | 
			
		||||
    Ron,
 | 
			
		||||
    //Toml,
 | 
			
		||||
    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) {
 | 
			
		||||
    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 => {
 | 
			
		||||
            use serde_json::Deserializer;
 | 
			
		||||
 | 
			
		||||
@@ -66,6 +80,7 @@ fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) {
 | 
			
		||||
        Input::Pickle => {
 | 
			
		||||
            use serde_pickle::Deserializer;
 | 
			
		||||
 | 
			
		||||
            // NOTE: Apparently serde_pickle do not implement `Deserializer` on const?
 | 
			
		||||
            let mut deserializer = Deserializer::new(input, serde_pickle::DeOptions::new());
 | 
			
		||||
            ser(opt, &mut deserializer, output);
 | 
			
		||||
        }
 | 
			
		||||
@@ -93,6 +108,21 @@ where
 | 
			
		||||
    D: Deserializer<'de>,
 | 
			
		||||
{
 | 
			
		||||
    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 => {
 | 
			
		||||
            use serde_json::Serializer;
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user