Comments (4)
I like the idea! Shouldn't be too hard to implement. I can get to it next week most likely, also reminds me of a cond
attribute for a conditional parsing, which may cover your use case
from deku.
Perfect, works as expected
from deku.
If you don't mind taking a look to see if it meets your use-case, I plan on making a release tomorrow morning.
In the case of your original ticket:
use deku::prelude::*;
use std::convert::TryFrom;
#[derive(PartialEq, Debug, DekuRead, DekuWrite)]
pub struct DekuTest {
pub field_a: u8,
#[deku(skip, cond="*field_a == 1")] // skip if field_a == 1
pub field_b: Option<u8>,
#[deku(skip, cond="*field_b == Some(1)")] // skip if field_b == Some(1)
pub field_c: Option<u8>,
}
fn main() {
let data: Vec<u8> = vec![0x01, 0x02];
let value = DekuTest::from_bytes((data.as_ref(), 0)).unwrap();
println!("{:#?}", value)
}
DekuTest {
field_a: 1,
field_b: None,
field_c: Some(
2,
),
},
from deku.
I shall
from deku.
Related Issues (20)
- Cant "count" from Some(field) directly - need as_ref().unwrap() HOT 1
- Passing a struct in ctx creates opaque error HOT 7
- Doc request: update for structs
- How to access enum-struct members? HOT 4
- Assert for tuple enum HOT 1
- Working with elements of Vec<StructUsingDeku> to get sum of their byte-sizes HOT 4
- Weird parsing with `bool` and non-aligned data. HOT 4
- Is there a way to pad by a variable number of bytes? HOT 3
- Roll a release? HOT 12
- Performance of `read_all` and `count` HOT 2
- Ability to ignore excess bytes HOT 1
- endian attribute breaks enum HOT 2
- Comply to `cond` attribute while encoding HOT 6
- Support unit structure `struct S;` in derive-macro `DekuWrite` HOT 1
- Reading from a tokio stream
- Support for fallible use cases for mutating and serializing fields HOT 2
- Add `to_slice` for buffer reuse `DekuContainerWrite` trait HOT 3
- With no rest and input anymore: how to peek into the Reader? Or get total of whole input? HOT 1
- Is there a faster way to read large Vec<u8>? HOT 5
- Add support for error_in_core in a no_std environment HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from deku.