Byte array with an `_io` member: C# parsing library

Helper type to work around Kaitai Struct not providing an _io member for plain byte arrays.

KS implementation details

License: MIT

This page hosts a formal specification of Byte array with an `_io` member 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 C# generated by Kaitai Struct depends on the C# runtime library. You have to install it before you can parse data.

The C# runtime library is available in the NuGet Gallery. Installation instructions can also be found there.

Code

Parse a local file and get structure in memory:

var data = BytesWithIo.FromFile("path/to/local/file.bin");

Or parse structure from a byte array:

byte[] someArray = new byte[] { ... };
var data = new BytesWithIo(new KaitaiStream(someArray));

After that, one can get various attributes from the structure by accessing properties like:

data.Data // => The actual data.

C# source code to parse Byte array with an `_io` member

BytesWithIo.cs

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



namespace Kaitai
{

    /// <summary>
    /// Helper type to work around Kaitai Struct not providing an `_io` member for plain byte arrays.
    /// </summary>
    public partial class BytesWithIo : KaitaiStruct
    {
        public static BytesWithIo FromFile(string fileName)
        {
            return new BytesWithIo(new KaitaiStream(fileName));
        }

        public BytesWithIo(KaitaiStream p__io, KaitaiStruct p__parent = null, BytesWithIo p__root = null) : base(p__io)
        {
            m_parent = p__parent;
            m_root = p__root ?? this;
            _read();
        }
        private void _read()
        {
            _data = m_io.ReadBytesFull();
        }
        private byte[] _data;
        private BytesWithIo m_root;
        private KaitaiStruct m_parent;

        /// <summary>
        /// The actual data.
        /// </summary>
        public byte[] Data { get { return _data; } }
        public BytesWithIo M_Root { get { return m_root; } }
        public KaitaiStruct M_Parent { get { return m_parent; } }
    }
}