hex

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: May 25, 2023 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	MissingStartCodeErr  = RecordError("the passed record does not start with the correct start code")
	WrongRecordFormatErr = RecordError("the passed record is not a correct hex record")
	DataOutOfBounds      = RecordError("the passed byte slice cannot be held by this record")
	InvalidHexDigit      = RecordError("the passed byte represents a character that is not an hex digit")
	NoMoreRecordsErr     = RecordError("no more records")
)
View Source
const (
	MultipleEofErr    = FileError("the passed hex file contains more than one EOF records")
	NoEofRecordErr    = FileError("the passed hex file does not contain an EOF record")
	AccessOutOfBounds = FileError("cannot access the hex file out of the length of the encoded program")
	RecordErr         = FileError("faulty record")
	RecordOutOfBounds = FileError("attempting to request a record out of the bounds of the file")
)

Variables

This section is empty.

Functions

func CustomError

func CustomError(original FileError, msg string, args ...any) error

CustomError returns FileError that can use the classic fmt message/varargs.

Types

type File

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

File implements an Intel Hex-encoded file

func ReadAll

func ReadAll(in io.ByteScanner) (*File, error)

ReadAll initializes a hex file by reading every byte from its source, parsing the records and validating them

func (*File) BinarySize

func (hf *File) BinarySize() int

BinarySize returns the size of the hex-encoded actual data. This is equivalent to the size of the generated .bin.

func (*File) Iterator

func (hf *File) Iterator() <-chan *Record

func (*File) ReadAt

func (hf *File) ReadAt(pos uint32, size int) ([]byte, error)

ReadAt reads size bytes starting from pos position in the hex-encoded file. This implements a sort of random access to the data mapped in hex-format.

func (*File) Record

func (hf *File) Record(idx int) (*Record, error)

Record returns the idx-th record

func (*File) Size

func (hf *File) Size() int

Size returns the number of records in the file

func (*File) WriteAt

func (hf *File) WriteAt(pos uint32, data []byte) error

WriteAt writes len(data) bytes starting from pos position onto the hex-encoded file. The written bytes are passed through the data parameter.

type FileError

type FileError string

FileError identifies an error related to a hex file

func (FileError) Error

func (r FileError) Error() string

Error returns a string representation of a FileError

type Record

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

Record is an HEX Record that has been validated. Instantiate only via ParseRecord

func ParseRecord

func ParseRecord(input io.ByteScanner) (*Record, error)

ParseRecord initializes a new Record reading from a ByteReader. This function returns an error if the byte stream that is read does not represent a valid Record.

func (*Record) Address

func (r *Record) Address() uint16

Address is the record address value

func (*Record) AddressBytes

func (r *Record) AddressBytes() []byte

AddressBytes is the hex representation of the record address value

func (*Record) AsBytes

func (r *Record) AsBytes() []byte

AsBytes returns a bytes representation of the record

func (*Record) AsString

func (r *Record) AsString() string

AsString returns a string representation of the record

func (*Record) ByteCount

func (r *Record) ByteCount() int

ByteCount returned as an integer

func (*Record) Checksum

func (r *Record) Checksum() []byte

Checksum of the current record

func (*Record) ReadData

func (r *Record) ReadData() []byte

ReadData returns the data section of the record

func (*Record) Type

func (r *Record) Type() RecordType

Type is the record type

func (*Record) WriteData

func (r *Record) WriteData(start int, data []byte) error

WriteData is used to rewrite the data section of the record. This method re-computes the record checksum automatically.

type RecordError

type RecordError string

RecordError identifies an error related to a hex record

func (RecordError) Error

func (r RecordError) Error() string

Error returns a string representation of a RecordError

type RecordType

type RecordType uint

RecordType identifies the type of hex record (Data, EOF, etc.)

const (
	DataRecord RecordType = iota // A DataRecord contains data in hex format
	EOFRecord                    // An EOFRecord identifies the end of a hex file
	ExtendedSegmentAddrRecord
	StartSegmentAddrRecord
	ExtendedLinearAddrRecord
	StartLinearAddrRecord
	InvalidRecord
)

type Unsigned

type Unsigned interface {
	uint8 | uint16 | uint32 | uint64
}

Unsigned is a constraint for unsigned integers with explicit bit-width.

Jump to

Keyboard shortcuts

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