Git Product home page Git Product logo

Comments (4)

sharksforarms avatar sharksforarms commented on August 20, 2024 1

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.

wcampbell0x2a avatar wcampbell0x2a commented on August 20, 2024 1

Perfect, works as expected

from deku.

sharksforarms avatar sharksforarms commented on August 20, 2024

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.

wcampbell0x2a avatar wcampbell0x2a commented on August 20, 2024

I shall

from deku.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.