wcampbell0x2a / bintex

Create bytefield latex digrams with the use of rust proc-macros and deku
Apache License 2.0
5 stars 0 forks source link

Add Table generation for Enums #1

Open wcampbell0x2a opened 3 years ago

wcampbell0x2a commented 3 years ago

Normal Enum

This is pretty trivial for normal Enums:

#[deku(type = "u8", bits = "4")]
enum DekuTest {
    #[deku(id = "0b1001")]
    VariantA,,
    #[deku(id = "0b0110")]
    VariantB,,
}

That would just emit the enum table.

Figure DekuTest

field id
VariantA 0b1001
VariantB 0b0110

Advanced Enum

This will be difficult for advanced enums:

#[deku(type = "u8", bits = "4")]
enum DekuTest {
    #[deku(id = "0b1001")]
    VariantA( #[deku(bits = "4")] u8, u8),
}

That latex_output would emit one enum table, and another bytefield for the VariantA.

Figure DekuTest

field id
VariantA 0b1001

Bytefield VariantA

wcampbell0x2a commented 3 years ago

See https://github.com/sharksforarms/deku/issues/223 for some blocking changes.

wcampbell0x2a commented 3 years ago

Normal Enum

I think actually just requiring a #[bintex(bits = "var")] will be easier. TWe can also have a EnumType attribute [bintex(enum_type = EnumType::Fixed)] for declaring that the size of this is fixed

enum EnumType {
    Fixed,
    Variable,
}
struct Testing {
    #[bintex(bits = "4", enum_type = EnumType::Fixed)]
    a: DekuTest,
}

#[deku(type = "u8", bits = "4")]
enum DekuTest {
    #[deku(id = "0b1001")]
    VariantA,
    #[deku(id = "0b0110")]
    VariantB,
}

Advanced Enum

For these, we can be certain the size of the enum in bits beforehand, since it will vary at runtime. The best we can do is emit a \skippedwords for bytefield LaTeX.

struct Testing {
    #[bintex(enum_type = EnumType::Variable)]
    a: DekuTest,
}

#[deku(type = "u8", bits = "4")]
enum DekuTest {
    #[deku(id = "0b1001")]
    VariantA(u8),
    #[deku(id = "0b0110")]
    VariantB,
}

We can worry about emitting the correct bytefield field for the struct for now. The actual latex_output for the advanced enum will need more thinking.