parent
9e05a03cf2
commit
c2ea3bb1a5
2 changed files with 24 additions and 3 deletions
|
@ -12,6 +12,11 @@ the `serde::Deserialize` and `std::fmt::Debug` traits.
|
|||
|
||||
[typed]: https://docs.rs/framed/*/framed/typed/index.html
|
||||
|
||||
Note: you must install [`jq`][jq] and have it on your path.
|
||||
[jq]: https://stedolan.github.io/jq/
|
||||
|
||||
On Ubuntu you can install it with: `sudo apt install jq`.
|
||||
|
||||
Here's an example. The main binary in crate `framed_test_type` writes
|
||||
a serialized and encoded `framed_test_type::Test` struct to stdout;
|
||||
first save that to a file:
|
||||
|
@ -79,8 +84,13 @@ OPTIONS:
|
|||
Csv, Debug, Json]
|
||||
```
|
||||
|
||||
Note: you must install [`jq`][jq] and have it on your path.
|
||||
To customize the output for your type, try creating a tuple struct
|
||||
with a custom Debug implementation. See `CustomDebug` in test_type for
|
||||
an example:
|
||||
|
||||
On Ubuntu you can install it with: `sudo apt install jq`.
|
||||
```text
|
||||
~/framed-rs % export DECODE_TYPE_NAME=framed_test_type::CustomDebug;
|
||||
~/framed-rs % < test_data bin/decode_typed
|
||||
|
||||
[jq]: https://stedolan.github.io/jq/
|
||||
CustomDebug a=0x000000ff, b=0x2
|
||||
```
|
||||
|
|
|
@ -4,8 +4,19 @@ extern crate serde;
|
|||
#[macro_use]
|
||||
extern crate serde_derive;
|
||||
|
||||
use std::fmt::{self, Debug, Formatter};
|
||||
|
||||
#[derive(Debug, Deserialize, Serialize)]
|
||||
pub struct Test {
|
||||
pub a: u32,
|
||||
pub b: u16,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Serialize)]
|
||||
pub struct CustomDebug(Test);
|
||||
|
||||
impl Debug for CustomDebug {
|
||||
fn fmt(&self, f: &mut Formatter) -> Result<(), fmt::Error> {
|
||||
write!(f, "CustomDebug a=0x{:08x}, b=0x{:X}", self.0.a, self.0.b)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue