.bmp file format of Heroes of Might and Magic: Go parsing library

Application

Heroes of Might and Magic

File extension

bmp

KS implementation details

License: CC0-1.0

This page hosts a formal specification of .bmp file format of Heroes of Might and Magic using Kaitai Struct. This specification can be automatically translated into a variety of programming languages to get a parsing library.

Go source code to parse .bmp file format of Heroes of Might and Magic

heroes_of_might_and_magic_bmp.go

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

import "github.com/kaitai-io/kaitai_struct_go_runtime/kaitai"

type HeroesOfMightAndMagicBmp struct {
	Magic uint16
	Width uint16
	Height uint16
	Data []byte
	_io *kaitai.Stream
	_root *HeroesOfMightAndMagicBmp
	_parent interface{}
}
func NewHeroesOfMightAndMagicBmp() *HeroesOfMightAndMagicBmp {
	return &HeroesOfMightAndMagicBmp{
	}
}

func (this *HeroesOfMightAndMagicBmp) Read(io *kaitai.Stream, parent interface{}, root *HeroesOfMightAndMagicBmp) (err error) {
	this._io = io
	this._parent = parent
	this._root = root

	tmp1, err := this._io.ReadU2le()
	if err != nil {
		return err
	}
	this.Magic = uint16(tmp1)
	tmp2, err := this._io.ReadU2le()
	if err != nil {
		return err
	}
	this.Width = uint16(tmp2)
	tmp3, err := this._io.ReadU2le()
	if err != nil {
		return err
	}
	this.Height = uint16(tmp3)
	tmp4, err := this._io.ReadBytes(int((this.Width * this.Height)))
	if err != nil {
		return err
	}
	tmp4 = tmp4
	this.Data = tmp4
	return err
}