0

I need to parse binary data using Swift. Can anybody tell me how to implement something like the Java Preon library in Swift?

QByte, here is more information....

I am developing an application to program radios. The program must read and write data from a variety of radios and, of course, each radio manufacturer encodes the data in a different way. The program must be able to 1. Read the data over a serial port using the protocol used by the radio, 2. Parse the data. There needs to be a language to specify the data format for a particular radio , 3. Decode the data and populate objects with the parsed and decoded data, 4. Allow the user to edit the data, 5. Encode the modified data back to the data format needed by the radio, 6. Write the changed configuration data back to the radio. The parsing code needs to perform items 2, 3, and 5. I know how to do the other items.

At first I thought Preon could perform items 2, 3, and 5. I have just found that Preon is unable to encode the data. Since Preon is unsupported, I now doubt Preon will be usable.

Because the data format is different for each manufacturer, the data is represented in a variety of ways. One radio simply encodes the data as ASCII characters. So a frequency of 144MHz might be transmitted as ASCII characters '144000000'. A Boolean value would be expressed as an ASCII 0 or 1. Other radios encode the data in bits. Numbers are expressed as 16 bit unsigned shorts, 32 bit unsigned integers, or BCD numbers. Boolean values use 1 bit.

I could hard code the routines to parse, decode, and encode, however this is difficult to document and modify and it makes it difficult to add new radios.

So, does this explanation help you understand what I am trying to do?

Does anyone know of any libraries that can be used with Swift to accomplish these tasks?

ClarkS
  • 100
  • 1
  • 9
  • What do you want to accomplish exactly? The Preon library isn't small... – Qbyte Jul 28 '15 at 18:17
  • @Qbyte I have modified my question to better explain what I need to accomplish. Preon can handle many more data types than I need, plus it has many features I don't need such as limbo expressions, lazy evaluation, and a documentation generator. However I still need to do other things that Preon does, or should do, such as parse, decode, and encode. As I mentioned above my tests now show that Preons encoder is broken except for very simple data structures. – ClarkS Jul 30 '15 at 00:42
  • I have solved my problem. I found this link which adds structured data to Swift. After that I heavily modified it to meet my needs. https://github.com/MagerValp/MVPCStruct The end result is that I am able to encode and decode binary data, I also have a library that is a tiny fraction of the size of Preon, a library that is understandable, and, best of all, one that works. – ClarkS Nov 01 '15 at 12:53

0 Answers0