Okteta: how do create struct with dynamic length?

Hi. I try to check a binary file that I created myself with my own structure. Okteta can validate the binary file against a defined structure. I can already create a simple structure file and use it. But my data format have a map that can contain a variable count of key-values pairs. First is a int32 for the count, then (int32-int32) pairs x the count red before.

I tried something like this without success:

function init() {
    var chunksIndex = struct({
        size: uint32()
    });
    chunksIndex.updateFunc = updateChunksIndex;
    var map = {
        "chunksIndex": chunksIndex
    };
    var obj = struct(map);
    obj.byteOrder = "big-endian";
    return obj;
}

function updateChunksIndex(root) {
    var sizeValue = this.size.value;
    var map = {
        size: uint32()
    };
    for (var i = 0; i < sizeValue; i++) {
        map.set(struct({
            pos: uint32(),
            size: uint32()
        }));
    }
    this = struct(map);
}

It’s actually simple. I came with this solutions.

function init() {
    var chunksIndex = struct({
        count: int32(),
        values: array(
            struct({
                pos: int32(),
                size: int32()
            }), chunksCount)
    });
    var map = {
        chunksIndex: chunksIndex
    };
    var obj = struct(map);
    obj.byteOrder = "big-endian";
    return obj;
}

function chunksCount(mainStruct) {
    return mainStruct.chunksIndex.count.value;
}

function init() {
    var chunkPosMap = { sx: int32(), sy: int32(), sz: int32(), ex: int32(), ey: int32(), ez: int32() };
    var centerExtentMap = { centerx: float(), centery: float(), centerz: float(), extentx: float(), extenty: float(), extentz: float() };
    var chunksMap = {
        id: int32(),
        pos: struct(chunkPosMap)
    };
    var map = {
        id: int32(),
        parent: int32(),
        chunkSize: int32(),
        pos: struct(chunkPosMap),
        chunksCount: int32(),
        chunks: array(struct(chunksMap), 8)
    };
    var obj = struct(map);
    obj.byteOrder = "big-endian";
    return obj;
}

function chunksCount(mainStruct) {
    return mainStruct.chunksCount.value;
}

We mark this as solved.