.chg file format of MONOMAKH-SAPR: Java parsing library

CHG is a container format file used by MONOMAKH-SAPR, a software package for analysis & design of reinforced concrete multi-storey buildings with arbitrary configuration in plan.

CHG is a simple container, which bundles several project files together.

Written and tested by Vladimir Shulzhitskiy, 2017

Application

MONOMAKH-SAPR

File extension

chg

KS implementation details

License: CC0-1.0
Minimal Kaitai Struct required: 0.7

This page hosts a formal specification of .chg file format of MONOMAKH-SAPR using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Usage

Runtime library

All parsing code for Java generated by Kaitai Struct depends on the Java runtime library. You have to install it before you can parse data.

The Java runtime library is published in the Maven Central Repository. Refer to the artifact page for instructions how to add it into your project with the build tool that you use.

Code

Parse a local file and get structure in memory:

MonomakhSaprChg data = MonomakhSaprChg.fromFile("path/to/local/file.chg");

Or parse structure from a byte array:

byte[] someArray = new byte[] { ... };
MonomakhSaprChg data = new MonomakhSaprChg(new ByteBufferKaitaiStream(someArray));

After that, one can get various attributes from the structure by invoking getter methods like:

data.title() // => get title

Java source code to parse .chg file format of MONOMAKH-SAPR

MonomakhSaprChg.java

// This is a generated file! Please edit source .ksy file and use kaitai-struct-compiler to rebuild

import io.kaitai.struct.ByteBufferKaitaiStream;
import io.kaitai.struct.KaitaiStruct;
import io.kaitai.struct.KaitaiStream;
import java.io.IOException;
import java.nio.charset.Charset;
import java.util.ArrayList;


/**
 * CHG is a container format file used by
 * [MONOMAKH-SAPR](https://www.liraland.com/mono/), a software
 * package for analysis & design of reinforced concrete multi-storey
 * buildings with arbitrary configuration in plan.
 * 
 * CHG is a simple container, which bundles several project files
 * together.
 * 
 * Written and tested by Vladimir Shulzhitskiy, 2017
 */
public class MonomakhSaprChg extends KaitaiStruct {
    public static MonomakhSaprChg fromFile(String fileName) throws IOException {
        return new MonomakhSaprChg(new ByteBufferKaitaiStream(fileName));
    }

    public MonomakhSaprChg(KaitaiStream _io) {
        this(_io, null, null);
    }

    public MonomakhSaprChg(KaitaiStream _io, KaitaiStruct _parent) {
        this(_io, _parent, null);
    }

    public MonomakhSaprChg(KaitaiStream _io, KaitaiStruct _parent, MonomakhSaprChg _root) {
        super(_io);
        this._parent = _parent;
        this._root = _root == null ? this : _root;
        _read();
    }
    private void _read() {
        this.title = new String(this._io.readBytes(10), Charset.forName("ascii"));
        this.ent = new ArrayList<Block>();
        {
            int i = 0;
            while (!this._io.isEof()) {
                this.ent.add(new Block(this._io, this, _root));
                i++;
            }
        }
    }
    public static class Block extends KaitaiStruct {
        public static Block fromFile(String fileName) throws IOException {
            return new Block(new ByteBufferKaitaiStream(fileName));
        }

        public Block(KaitaiStream _io) {
            this(_io, null, null);
        }

        public Block(KaitaiStream _io, MonomakhSaprChg _parent) {
            this(_io, _parent, null);
        }

        public Block(KaitaiStream _io, MonomakhSaprChg _parent, MonomakhSaprChg _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.header = new String(this._io.readBytes(13), Charset.forName("ascii"));
            this.fileSize = this._io.readU8le();
            this.file = this._io.readBytes(fileSize());
        }
        private String header;
        private long fileSize;
        private byte[] file;
        private MonomakhSaprChg _root;
        private MonomakhSaprChg _parent;
        public String header() { return header; }
        public long fileSize() { return fileSize; }
        public byte[] file() { return file; }
        public MonomakhSaprChg _root() { return _root; }
        public MonomakhSaprChg _parent() { return _parent; }
    }
    private String title;
    private ArrayList<Block> ent;
    private MonomakhSaprChg _root;
    private KaitaiStruct _parent;
    public String title() { return title; }
    public ArrayList<Block> ent() { return ent; }
    public MonomakhSaprChg _root() { return _root; }
    public KaitaiStruct _parent() { return _parent; }
}