gohex

package
v1.0.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 24, 2026 License: Apache-2.0, MIT Imports: 8 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

README

Build Status

gohex

A Go library for parsing Intel HEX files

Documentation:

https://godoc.org/github.com/marcinbor85/gohex

Features:

  • robust intelhex parsing (full test coverage)
  • support i32hex format
  • two-way converting hex<->bin
  • trivial but powerful api (only the most commonly used functions)
  • interface-based IO functions

Examples:

Loading IntelHex file:
package main

import (
	"fmt"
	"github.com/marcinbor85/gohex"
	"os"
)

func main() {
	file, err := os.Open("example.hex")
	if err != nil {
		panic(err)
	}
	defer file.Close()
	
	mem := gohex.NewMemory()
	err = mem.ParseIntelHex(file)
	if err != nil {
		panic(err)
	}
	for _, segment := range mem.GetDataSegments() {
		fmt.Printf("%+v\n", segment)
	}
	bytes := mem.ToBinary(0xFFF0, 128, 0x00)
	fmt.Printf("%v\n", bytes)
}
Dumping IntelHex file:
package main

import (
	"github.com/marcinbor85/gohex"
	"os"
)

func main() {
	file, err := os.Create("output.hex")
	if err != nil {
		panic(err)
	}
	defer file.Close()
	
	mem := gohex.NewMemory()
	mem.SetStartAddress(0x80008000)
	mem.AddBinary(0x10008000, []byte{0x01,0x02,0x03,0x04})
	mem.AddBinary(0x20000000, make([]byte, 256))
	
	mem.DumpIntelHex(file, 16)
}

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type DataSegment

type DataSegment struct {
	Address uint32 // Starting address of data segment
	Data    []byte // Data segment bytes
}

Structure with binary data segment fields

type Memory

type Memory struct {
	// contains filtered or unexported fields
}

Main structure with private fields of IntelHex parser

func NewMemory

func NewMemory() *Memory

Constructor of Memory structure

func (*Memory) AddBinary

func (m *Memory) AddBinary(adr uint32, bytes []byte) error

Method to add binary data to memory (auto segmented and sorted)

func (*Memory) Clear

func (m *Memory) Clear()

Method to clear memory structure

func (*Memory) DumpIntelHex

func (m *Memory) DumpIntelHex(writer io.Writer, lineLength byte) error

Method to dumping IntelHex data previously loaded into memory

func (*Memory) GetDataSegments

func (m *Memory) GetDataSegments() []DataSegment

Method to getting data segments address from IntelHex data

func (*Memory) GetStartAddress

func (m *Memory) GetStartAddress() (adr uint32, ok bool)

Method to getting start address from IntelHex data

func (*Memory) ParseIntelHex

func (m *Memory) ParseIntelHex(reader io.Reader) error

Method to parsing IntelHex data and add into memory

func (*Memory) RemoveBinary

func (m *Memory) RemoveBinary(adr uint32, size uint32)

Method to remove binary data from memory (auto segmented and sorted)

func (*Memory) SetBinary

func (m *Memory) SetBinary(adr uint32, bytes []byte)

Method to set binary data to memory (data overlapped will change, auto segmented and sorted)

func (*Memory) SetStartAddress

func (m *Memory) SetStartAddress(adr uint32)

Method to setting start address to IntelHex data

func (*Memory) ToBinary

func (m *Memory) ToBinary(address uint32, size uint32, padding byte) []byte

Method to load binary data previously loaded into memory

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL