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

package org.josast.spino.generated;

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

public class SpinoHeader extends KaitaiStruct {
    public static SpinoHeader fromFile(String fileName) throws IOException {
        return new SpinoHeader(new ByteBufferKaitaiStream(fileName));
    }

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

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

    public SpinoHeader(KaitaiStream _io, KaitaiStruct _parent, SpinoHeader _root) {
        super(_io);
        this._parent = _parent;
        this._root = _root == null ? this : _root;
        _read();
    }
    private void _read() {
        this.ax25Frame = new Ax25Frame(this._io, this, _root);
        this.payload = this._io.readBytesFull();
    }
    public static class Ax25Frame extends KaitaiStruct {
        public static Ax25Frame fromFile(String fileName) throws IOException {
            return new Ax25Frame(new ByteBufferKaitaiStream(fileName));
        }

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

        public Ax25Frame(KaitaiStream _io, SpinoHeader _parent) {
            this(_io, _parent, null);
        }

        public Ax25Frame(KaitaiStream _io, SpinoHeader _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.ax25Header = new Ax25Header(this._io, this, _root);
        }
        private Ax25Header ax25Header;
        private SpinoHeader _root;
        private SpinoHeader _parent;
        public Ax25Header ax25Header() { return ax25Header; }
        public SpinoHeader _root() { return _root; }
        public SpinoHeader _parent() { return _parent; }
    }
    public static class DestCallsign extends KaitaiStruct {
        public static DestCallsign fromFile(String fileName) throws IOException {
            return new DestCallsign(new ByteBufferKaitaiStream(fileName));
        }

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

        public DestCallsign(KaitaiStream _io, SpinoHeader.DestCallsignRaw _parent) {
            this(_io, _parent, null);
        }

        public DestCallsign(KaitaiStream _io, SpinoHeader.DestCallsignRaw _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.destCallsign = new String(this._io.readBytes(6), Charset.forName("ASCII"));
        }
        private String destCallsign;
        private SpinoHeader _root;
        private SpinoHeader.DestCallsignRaw _parent;
        public String destCallsign() { return destCallsign; }
        public SpinoHeader _root() { return _root; }
        public SpinoHeader.DestCallsignRaw _parent() { return _parent; }
    }
    public static class Ax25Header extends KaitaiStruct {
        public static Ax25Header fromFile(String fileName) throws IOException {
            return new Ax25Header(new ByteBufferKaitaiStream(fileName));
        }

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

        public Ax25Header(KaitaiStream _io, SpinoHeader.Ax25Frame _parent) {
            this(_io, _parent, null);
        }

        public Ax25Header(KaitaiStream _io, SpinoHeader.Ax25Frame _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.destCallsignRaw = new DestCallsignRaw(this._io, this, _root);
            this.destSsidRaw = this._io.readU1();
            this.srcCallsignRaw = new SrcCallsignRaw(this._io, this, _root);
            this.srcSsidRaw = this._io.readU1();
            this.ctl = this._io.readU1();
            this.pid = this._io.readU1();
        }
        private Integer srcSsid;
        public Integer srcSsid() {
            if (this.srcSsid != null)
                return this.srcSsid;
            int _tmp = (int) (((srcSsidRaw() & 15) >> 1));
            this.srcSsid = _tmp;
            return this.srcSsid;
        }
        private Integer destSsid;
        public Integer destSsid() {
            if (this.destSsid != null)
                return this.destSsid;
            int _tmp = (int) (((destSsidRaw() & 15) >> 1));
            this.destSsid = _tmp;
            return this.destSsid;
        }
        private DestCallsignRaw destCallsignRaw;
        private int destSsidRaw;
        private SrcCallsignRaw srcCallsignRaw;
        private int srcSsidRaw;
        private int ctl;
        private int pid;
        private SpinoHeader _root;
        private SpinoHeader.Ax25Frame _parent;
        public DestCallsignRaw destCallsignRaw() { return destCallsignRaw; }
        public int destSsidRaw() { return destSsidRaw; }
        public SrcCallsignRaw srcCallsignRaw() { return srcCallsignRaw; }
        public int srcSsidRaw() { return srcSsidRaw; }
        public int ctl() { return ctl; }
        public int pid() { return pid; }
        public SpinoHeader _root() { return _root; }
        public SpinoHeader.Ax25Frame _parent() { return _parent; }
    }
    public static class Payload extends KaitaiStruct {
        public static Payload fromFile(String fileName) throws IOException {
            return new Payload(new ByteBufferKaitaiStream(fileName));
        }

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

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

        public Payload(KaitaiStream _io, KaitaiStruct _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.sizeFrame = this._io.readU2le();
            this.cmdId = this._io.readU2le();
            this.responseType = this._io.readU1();
            this.errorCode = this._io.readU1();
            this.spare = this._io.readU2le();
            this.timestamps = this._io.readU8le();
            this.responsetype = new String(this._io.readBytes(sizeFrame()), Charset.forName("UTF-8"));
        }
        private int sizeFrame;
        private int cmdId;
        private int responseType;
        private int errorCode;
        private int spare;
        private long timestamps;
        private String responsetype;
        private SpinoHeader _root;
        private KaitaiStruct _parent;
        public int sizeFrame() { return sizeFrame; }
        public int cmdId() { return cmdId; }
        public int responseType() { return responseType; }
        public int errorCode() { return errorCode; }
        public int spare() { return spare; }
        public long timestamps() { return timestamps; }
        public String responsetype() { return responsetype; }
        public SpinoHeader _root() { return _root; }
        public KaitaiStruct _parent() { return _parent; }
    }
    public static class SrcCallsignRaw extends KaitaiStruct {
        public static SrcCallsignRaw fromFile(String fileName) throws IOException {
            return new SrcCallsignRaw(new ByteBufferKaitaiStream(fileName));
        }

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

        public SrcCallsignRaw(KaitaiStream _io, SpinoHeader.Ax25Header _parent) {
            this(_io, _parent, null);
        }

        public SrcCallsignRaw(KaitaiStream _io, SpinoHeader.Ax25Header _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this._raw__raw_srcCallsignRor = this._io.readBytes(6);
            this._raw_srcCallsignRor = KaitaiStream.processRotateLeft(_raw__raw_srcCallsignRor, 8 - (1), 1);
            KaitaiStream _io__raw_srcCallsignRor = new ByteBufferKaitaiStream(_raw_srcCallsignRor);
            this.srcCallsignRor = new SrcCallsign(_io__raw_srcCallsignRor, this, _root);
        }
        private SrcCallsign srcCallsignRor;
        private SpinoHeader _root;
        private SpinoHeader.Ax25Header _parent;
        private byte[] _raw_srcCallsignRor;
        private byte[] _raw__raw_srcCallsignRor;
        public SrcCallsign srcCallsignRor() { return srcCallsignRor; }
        public SpinoHeader _root() { return _root; }
        public SpinoHeader.Ax25Header _parent() { return _parent; }
        public byte[] _raw_srcCallsignRor() { return _raw_srcCallsignRor; }
        public byte[] _raw__raw_srcCallsignRor() { return _raw__raw_srcCallsignRor; }
    }
    public static class DestCallsignRaw extends KaitaiStruct {
        public static DestCallsignRaw fromFile(String fileName) throws IOException {
            return new DestCallsignRaw(new ByteBufferKaitaiStream(fileName));
        }

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

        public DestCallsignRaw(KaitaiStream _io, SpinoHeader.Ax25Header _parent) {
            this(_io, _parent, null);
        }

        public DestCallsignRaw(KaitaiStream _io, SpinoHeader.Ax25Header _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this._raw__raw_destCallsignRor = this._io.readBytes(6);
            this._raw_destCallsignRor = KaitaiStream.processRotateLeft(_raw__raw_destCallsignRor, 8 - (1), 1);
            KaitaiStream _io__raw_destCallsignRor = new ByteBufferKaitaiStream(_raw_destCallsignRor);
            this.destCallsignRor = new DestCallsign(_io__raw_destCallsignRor, this, _root);
        }
        private DestCallsign destCallsignRor;
        private SpinoHeader _root;
        private SpinoHeader.Ax25Header _parent;
        private byte[] _raw_destCallsignRor;
        private byte[] _raw__raw_destCallsignRor;
        public DestCallsign destCallsignRor() { return destCallsignRor; }
        public SpinoHeader _root() { return _root; }
        public SpinoHeader.Ax25Header _parent() { return _parent; }
        public byte[] _raw_destCallsignRor() { return _raw_destCallsignRor; }
        public byte[] _raw__raw_destCallsignRor() { return _raw__raw_destCallsignRor; }
    }
    public static class Digi extends KaitaiStruct {
        public static Digi fromFile(String fileName) throws IOException {
            return new Digi(new ByteBufferKaitaiStream(fileName));
        }

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

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

        public Digi(KaitaiStream _io, KaitaiStruct _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.size = this._io.readU2le();
            this.data = new String(this._io.readBytesFull(), Charset.forName("ASCII"));
        }
        private int size;
        private String data;
        private SpinoHeader _root;
        private KaitaiStruct _parent;
        public int size() { return size; }
        public String data() { return data; }
        public SpinoHeader _root() { return _root; }
        public KaitaiStruct _parent() { return _parent; }
    }
    public static class SrcCallsign extends KaitaiStruct {
        public static SrcCallsign fromFile(String fileName) throws IOException {
            return new SrcCallsign(new ByteBufferKaitaiStream(fileName));
        }

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

        public SrcCallsign(KaitaiStream _io, SpinoHeader.SrcCallsignRaw _parent) {
            this(_io, _parent, null);
        }

        public SrcCallsign(KaitaiStream _io, SpinoHeader.SrcCallsignRaw _parent, SpinoHeader _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.srcCallsign = new String(this._io.readBytes(6), Charset.forName("ASCII"));
        }
        private String srcCallsign;
        private SpinoHeader _root;
        private SpinoHeader.SrcCallsignRaw _parent;
        public String srcCallsign() { return srcCallsign; }
        public SpinoHeader _root() { return _root; }
        public SpinoHeader.SrcCallsignRaw _parent() { return _parent; }
    }
    private Ax25Frame ax25Frame;
    private byte[] payload;
    private SpinoHeader _root;
    private KaitaiStruct _parent;

    /**
     * @see <a href="https://www.tapr.org/pub_ax25.html">Source</a>
     */
    public Ax25Frame ax25Frame() { return ax25Frame; }
    public byte[] payload() { return payload; }
    public SpinoHeader _root() { return _root; }
    public KaitaiStruct _parent() { return _parent; }
}
