kampu

Crates.iokampu
lib.rskampu
version0.1.11
sourcesrc
created_at2024-08-05 09:44:34.486799
updated_at2024-08-13 06:25:55.493249
descriptionGeneric byte array parser function where you can define the structure/tree of the bytes in JSON, send it a byte array and get the parsed output in JSON.
homepage
repositoryhttps://github.com/ykasidit/kampu
max_upload_size
id1325761
size51,613
(ykasidit)

documentation

README

Kampu

Generic byte array parser function where you can define the structure/tree of the bytes in JSON, send it a byte array and get the parsed output in JSON.

'Kampu' is the name a large tree common in Thailand, it has very large branches that could be allegorical to the complex bit/byte/loops/matches that this parser aims to handle.

Usage

See the tests folder for examples, a simple example below:

fn test_simple_packet() {
    const tree_id:u64 = 1;
    let data = hex_to_bin("01 00 E8 03");
    plant_tree(
        tree_id,
        json!({
                "branches": [
                    { "name": "fix_status", "type": "u8" },
                    { "name": "rcr", "type": "u8" },
                    { "name": "millisecond", "type": "u16_le" }
                ]
            })
    );
    let parsed_json = parse_tree(tree_id, &data);
    assert_eq!(parsed_json, json!({
            "fix_status": 1,
            "rcr": 0,
            "millisecond": 1000
        }));
}

History

Inspired by the 'data' folder of libqmi and its python scripts to gen C code to match. Some GNSS device manufactureres sent new GNSS devices where they had their own packet structures to be added for the bluetooth_gnss app. Manually coding of these parsers and more complex protocols seem to call for a generic parser tool that could offer a simple way to define structures in JSON and have the safety, portability and performance of rust in which GPT helped draft most of the initial code in this repo and would hopefully be benefical to other common protocol dissector works too.

Commit count: 0

cargo fmt