Giter VIP home page Giter VIP logo

Comments (6)

Frostie314159 avatar Frostie314159 commented on June 9, 2024 1

Thanks a lot!

from deku.

wcampbell0x2a avatar wcampbell0x2a commented on June 9, 2024

I'm not at my computer to give an example, but Endian is just a Ctx. You should be able to store it in a struct and use it with #[deku(ctx)]

On another topic, I have a squashfs library that uses deku: https://github.com/wcampbell0x2a/backhand. Although I only support 4.0 so I didn't run into this issue.

from deku.

Frostie314159 avatar Frostie314159 commented on June 9, 2024

Actually this is about backhand. I'm trying to parse/modify a big endian squashfs, with qshs magic. While writing the patch I stumbled upon the default endianness being little.

from deku.

wcampbell0x2a avatar wcampbell0x2a commented on June 9, 2024

😆 of course! And yes, you would need to translate the magic to a Ctx::Endian before sending it to all the children. I haven't don't it, so if you run into deku related problems lmk

from deku.

Frostie314159 avatar Frostie314159 commented on June 9, 2024

The need for this arises from the fact, that many routers/APs from the 200x Era use BE Mips with squashfs. Coincidentally, I am working on such devices and squashfs-tools was just like: Deprecating: Meh; Deleting BE support: YESSS!.

from deku.

sharksforarms avatar sharksforarms commented on June 9, 2024

here's an example of a conditional endian-ness

use deku::ctx::Endian;
use deku::prelude::*;
use std::convert::{TryFrom, TryInto};

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
#[deku(ctx = "endian: deku::ctx::Endian")]
struct Child {
    #[deku(endian = "endian")]
    data: u16,
}

#[derive(Debug, PartialEq, DekuRead, DekuWrite)]
struct DekuTest {
    criteria: u8,
    #[deku(ctx = "if *criteria == 1 { Endian::Big } else { Endian::Little }")]
    child: Child,
}

fn main() {
    let test_data: &[u8] = [0x01, 0xAB, 0xCD].as_ref();

    let test_deku = DekuTest::try_from(test_data).unwrap();
    assert_eq!(
        DekuTest {
            criteria: 0x01,
            child: Child { data: 0xABCD },
        },
        test_deku,
    );

    let test_deku: Vec<u8> = test_deku.try_into().unwrap();
    assert_eq!(test_data.to_vec(), test_deku);
}

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.