Swiftpack.co - ole/HexHexHex as Swift Package

Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
See all packages published by ole.
ole/HexHexHex 0.1.0
A parser for the Intel Hexadecimal Object File Format (.hex), written in Swift.
⭐️ 14
🕓 2 years ago
.package(url: "https://github.com/ole/HexHexHex.git", from: "0.1.0")

HexHexHex

A parser for the Intel Hexadecimal Object File Format (.hex), written in Swift.

Status

Very experimental and untested.

Usage

Add HexHexHex as a Swift Package Manager dependency

dependencies: [
  .package(url: "https://github.com/ole/HexHexHex.git", from: "0.1.0"),
],

Code

Creating a HEXFile value from the text of a .hex file:

import HexHexHex

let hexText = """
  :020000040000FA
  :1000000025001C0C0200080C06006306590AE306D2
  :0C00B000590A000C3000070C2600030069
  :00000001FF
  """
let hexFile = try HEXFile(text: hexText)

The HEXFile value contains an array of Record values that represent the records in the .hex file:

debugPrint(hexFile)
/*
HEXFile (4 records)
  04 extended linear address – 0000
  00 data – address: 0000, data: 25 00 1C 0C 02 00 08 0C 06 00 63 06 59 0A E3 06
  00 data – address: 00B0, data: 59 0A 00 0C 30 00 07 0C 26 00 03 00
  01 end of file
 */

// Get all data records in the file
let dataRecords = hexFile.records.filter { $0.kind == .data }
print(dataRecords)

// Print out the addresses of all data records in the file
for case .data(let address, _) in hexFile.records {
  print(address)
}

Author

Ole Begemann, oleb.net.

License

MIT. See LICENSE.txt.

GitHub

link
Stars: 14
Last commit: 2 years ago
Advertisement: IndiePitcher.com - Cold Email Software for Startups

Release Notes

Initial Release
4 years ago

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API | Analytics