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

package org.josast.AX25.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;


/**
 * :field dest_callsign: ax25_frame.ax25_header.dest_callsign_raw.callsign_ror.callsign
 * :field src_callsign: ax25_frame.ax25_header.src_callsign_raw.callsign_ror.callsign
 * :field src_ssid: ax25_frame.ax25_header.src_ssid_raw.ssid
 * :field dest_ssid: ax25_frame.ax25_header.dest_ssid_raw.ssid
 * :field ctl: ax25_frame.ax25_header.ctl
 * :field pid: ax25_frame.pid
 * :field pid: ax25_frame.ax25_info
 */
public class Ax25frames extends KaitaiStruct {
    public static Ax25frames fromFile(String fileName) throws IOException {
        return new Ax25frames(new ByteBufferKaitaiStream(fileName));
    }

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

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

    public Ax25frames(KaitaiStream _io, KaitaiStruct _parent, Ax25frames _root) {
        super(_io);
        this._parent = _parent;
        this._root = _root == null ? this : _root;
        _read();
    }
    private void _read() {
        this.ax25Frame = new Ax25Frame(this._io, this, _root);
    }
    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, Ax25frames _parent) {
            this(_io, _parent, null);
        }

        public Ax25Frame(KaitaiStream _io, Ax25frames _parent, Ax25frames _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.ax25Header = new Ax25Header(this._io, this, _root);
            this.pid = this._io.readU1();
            this.ax25Info = this._io.readBytesFull();
        }
        private Ax25Header ax25Header;
        private int pid;
        private byte[] ax25Info;
        private Ax25frames _root;
        private Ax25frames _parent;
        public Ax25Header ax25Header() { return ax25Header; }
        public int pid() { return pid; }
        public byte[] ax25Info() { return ax25Info; }
        public Ax25frames _root() { return _root; }
        public Ax25frames _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, Ax25frames.Ax25Frame _parent) {
            this(_io, _parent, null);
        }

        public Ax25Header(KaitaiStream _io, Ax25frames.Ax25Frame _parent, Ax25frames _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.destCallsignRaw = new CallsignRaw(this._io, this, _root);
            this.destSsidRaw = new SsidMask(this._io, this, _root);
            this.srcCallsignRaw = new CallsignRaw(this._io, this, _root);
            this.srcSsidRaw = new SsidMask(this._io, this, _root);
            this.ctl = this._io.readU1();
        }
        private CallsignRaw destCallsignRaw;
        private SsidMask destSsidRaw;
        private CallsignRaw srcCallsignRaw;
        private SsidMask srcSsidRaw;
        private int ctl;
        private Ax25frames _root;
        private Ax25frames.Ax25Frame _parent;
        public CallsignRaw destCallsignRaw() { return destCallsignRaw; }
        public SsidMask destSsidRaw() { return destSsidRaw; }
        public CallsignRaw srcCallsignRaw() { return srcCallsignRaw; }
        public SsidMask srcSsidRaw() { return srcSsidRaw; }
        public int ctl() { return ctl; }
        public Ax25frames _root() { return _root; }
        public Ax25frames.Ax25Frame _parent() { return _parent; }
    }
    public static class Callsign extends KaitaiStruct {
        public static Callsign fromFile(String fileName) throws IOException {
            return new Callsign(new ByteBufferKaitaiStream(fileName));
        }

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

        public Callsign(KaitaiStream _io, Ax25frames.CallsignRaw _parent) {
            this(_io, _parent, null);
        }

        public Callsign(KaitaiStream _io, Ax25frames.CallsignRaw _parent, Ax25frames _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.callsign = new String(this._io.readBytes(6), Charset.forName("ASCII"));
        }
        private String callsign;
        private Ax25frames _root;
        private Ax25frames.CallsignRaw _parent;
        public String callsign() { return callsign; }
        public Ax25frames _root() { return _root; }
        public Ax25frames.CallsignRaw _parent() { return _parent; }
    }
    public static class SsidMask extends KaitaiStruct {
        public static SsidMask fromFile(String fileName) throws IOException {
            return new SsidMask(new ByteBufferKaitaiStream(fileName));
        }

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

        public SsidMask(KaitaiStream _io, Ax25frames.Ax25Header _parent) {
            this(_io, _parent, null);
        }

        public SsidMask(KaitaiStream _io, Ax25frames.Ax25Header _parent, Ax25frames _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this.ssidMask = this._io.readU1();
        }
        private Integer ssid;
        public Integer ssid() {
            if (this.ssid != null)
                return this.ssid;
            int _tmp = (int) (((ssidMask() & 15) >> 1));
            this.ssid = _tmp;
            return this.ssid;
        }
        private int ssidMask;
        private Ax25frames _root;
        private Ax25frames.Ax25Header _parent;
        public int ssidMask() { return ssidMask; }
        public Ax25frames _root() { return _root; }
        public Ax25frames.Ax25Header _parent() { return _parent; }
    }
    public static class CallsignRaw extends KaitaiStruct {
        public static CallsignRaw fromFile(String fileName) throws IOException {
            return new CallsignRaw(new ByteBufferKaitaiStream(fileName));
        }

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

        public CallsignRaw(KaitaiStream _io, Ax25frames.Ax25Header _parent) {
            this(_io, _parent, null);
        }

        public CallsignRaw(KaitaiStream _io, Ax25frames.Ax25Header _parent, Ax25frames _root) {
            super(_io);
            this._parent = _parent;
            this._root = _root;
            _read();
        }
        private void _read() {
            this._raw__raw_callsignRor = this._io.readBytes(6);
            this._raw_callsignRor = KaitaiStream.processRotateLeft(this._raw__raw_callsignRor, 8 - (1), 1);
            KaitaiStream _io__raw_callsignRor = new ByteBufferKaitaiStream(_raw_callsignRor);
            this.callsignRor = new Callsign(_io__raw_callsignRor, this, _root);
        }
        private Callsign callsignRor;
        private Ax25frames _root;
        private Ax25frames.Ax25Header _parent;
        private byte[] _raw__raw_callsignRor;
        private byte[] _raw_callsignRor;
        public Callsign callsignRor() { return callsignRor; }
        public Ax25frames _root() { return _root; }
        public Ax25frames.Ax25Header _parent() { return _parent; }
        public byte[] _raw__raw_callsignRor() { return _raw__raw_callsignRor; }
        public byte[] _raw_callsignRor() { return _raw_callsignRor; }
    }
    private Ax25Frame ax25Frame;
    private Ax25frames _root;
    private KaitaiStruct _parent;

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