fox-it / dissect.cstruct_legacy

A no-nonsense c-like structure parsing library for Python
MIT License
239 stars 25 forks source link

json support #9

Open Hadatko opened 4 years ago

Hadatko commented 4 years ago

Would be nice to have chance to get output in json type. result.toJSON() => {'type':'struct', 'name':'structName','members':[{...},{...}]} or {'type':'struct', 'name':'structName','members':{'paam1':{...},'paam2':{...},...}}

Hadatko commented 4 years ago

struct definition

struct B
{
    uint16_t a;
};
struct A
{
    struct B b[2];
};

B.a = 5
A.b=[5,5] //A.b[0].a=5;A.b[1].a=5;

json example for B:

{
    "B": {
        "a": {
            "type": "uint16",
            "value": 5
        }
    }
}

json example for A:

{
    "A": {
        "b": {
            "type": "B",
            "value": [{
                "a": {
                    "type": "uint16",
                    "value": 5
                }
            }, {
                "a": {
                    "type": "uint16",
                    "value": 5
                }
            }]
        }
    }
}