Add GVariant with the same (very low) hope to trully make it work as DBus
This commit is contained in:
parent
ceb10fabd9
commit
f5b2a25eaf
49
src/lib.rs
49
src/lib.rs
@ -15,9 +15,9 @@ pub struct Opt {
|
|||||||
#[clap(value_enum, ignore_case = true)]
|
#[clap(value_enum, ignore_case = true)]
|
||||||
pub output: Output,
|
pub output: Output,
|
||||||
|
|
||||||
#[clap(long, short = 'F')]
|
#[clap(long, short = 'F', required_if_eq_any(&[("input", "d-bus"), ("input", "g-variant")]))]
|
||||||
pub format_in: Option<String>,
|
pub format_in: Option<String>,
|
||||||
#[clap(long, short = 'f', required_if_eq_any(&[("output", "d-bus")]))]
|
#[clap(long, short = 'f', required_if_eq_any(&[("output", "d-bus"), ("output", "g-variant")]))]
|
||||||
pub format_out: Option<String>,
|
pub format_out: Option<String>,
|
||||||
|
|
||||||
/// For data format compatible, a default pretty format is output instead of a minified one
|
/// For data format compatible, a default pretty format is output instead of a minified one
|
||||||
@ -34,6 +34,7 @@ pub enum Input {
|
|||||||
//Bson,
|
//Bson,
|
||||||
//Cbor,
|
//Cbor,
|
||||||
DBus,
|
DBus,
|
||||||
|
GVariant,
|
||||||
Json,
|
Json,
|
||||||
Json5,
|
Json5,
|
||||||
//SExpression,
|
//SExpression,
|
||||||
@ -49,8 +50,8 @@ pub enum Input {
|
|||||||
pub enum Output {
|
pub enum Output {
|
||||||
//Bson,
|
//Bson,
|
||||||
//Cbor,
|
//Cbor,
|
||||||
//#[clap(requires("format_out"))]
|
|
||||||
DBus,
|
DBus,
|
||||||
|
GVariant,
|
||||||
Json,
|
Json,
|
||||||
//Json5, // NOTE: The crate is not noted "(deserialization only)" on the [serde listing](https://serde.rs/#data-formats) but it does not expose a `Serializer`
|
//Json5, // NOTE: The crate is not noted "(deserialization only)" on the [serde listing](https://serde.rs/#data-formats) but it does not expose a `Serializer`
|
||||||
//SExpression,
|
//SExpression,
|
||||||
@ -107,6 +108,24 @@ fn de(opt: &Opt, input: &mut dyn Read, output: &mut dyn Write) {
|
|||||||
);
|
);
|
||||||
ser(opt, &mut deserializer, output);
|
ser(opt, &mut deserializer, output);
|
||||||
}
|
}
|
||||||
|
Input::GVariant => {
|
||||||
|
use zvariant::gvariant::Deserializer;
|
||||||
|
use zvariant::EncodingContext;
|
||||||
|
use zvariant::Signature;
|
||||||
|
|
||||||
|
use byteorder::LE;
|
||||||
|
|
||||||
|
let sig = opt.format_in.clone().unwrap();
|
||||||
|
let mut buf = String::new();
|
||||||
|
let _buf_size = input.read_to_string(&mut buf).unwrap();
|
||||||
|
let mut deserializer = Deserializer::new(
|
||||||
|
buf.as_bytes(),
|
||||||
|
None,
|
||||||
|
&Signature::try_from(sig).unwrap(),
|
||||||
|
EncodingContext::<LE>::new_dbus(0),
|
||||||
|
);
|
||||||
|
ser(opt, &mut deserializer, output);
|
||||||
|
}
|
||||||
Input::Json => {
|
Input::Json => {
|
||||||
use serde_json::Deserializer;
|
use serde_json::Deserializer;
|
||||||
|
|
||||||
@ -189,7 +208,7 @@ where
|
|||||||
let mut out = std::io::Cursor::new(vec![]);
|
let mut out = std::io::Cursor::new(vec![]);
|
||||||
let mut fs = vec![];
|
let mut fs = vec![];
|
||||||
let serializer = &mut Serializer::new(
|
let serializer = &mut Serializer::new(
|
||||||
&Signature::try_from(dbg!(sig)).unwrap(),
|
&Signature::try_from(sig).unwrap(),
|
||||||
&mut out,
|
&mut out,
|
||||||
&mut fs, //None,
|
&mut fs, //None,
|
||||||
EncodingContext::<LE>::new_dbus(0),
|
EncodingContext::<LE>::new_dbus(0),
|
||||||
@ -200,6 +219,28 @@ where
|
|||||||
// let mut deserializer = Deserializer::new();
|
// let mut deserializer = Deserializer::new();
|
||||||
serde_transcode::transcode(deserializer, serializer).unwrap();
|
serde_transcode::transcode(deserializer, serializer).unwrap();
|
||||||
}
|
}
|
||||||
|
Output::GVariant => {
|
||||||
|
use zvariant::gvariant::Serializer;
|
||||||
|
use zvariant::EncodingContext;
|
||||||
|
use zvariant::Signature;
|
||||||
|
|
||||||
|
use byteorder::LE;
|
||||||
|
|
||||||
|
let sig = opt.format_out.clone().unwrap();
|
||||||
|
let mut out = std::io::Cursor::new(vec![]);
|
||||||
|
let mut fs = vec![];
|
||||||
|
let serializer = &mut Serializer::new(
|
||||||
|
&Signature::try_from(sig).unwrap(),
|
||||||
|
&mut out,
|
||||||
|
&mut fs, //None,
|
||||||
|
EncodingContext::<LE>::new_dbus(0),
|
||||||
|
);
|
||||||
|
|
||||||
|
//let mut buf = String::new();
|
||||||
|
// let _buf_size = output.read_to_string(&mut buf).unwrap();
|
||||||
|
// let mut deserializer = Deserializer::new();
|
||||||
|
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