Binary parsing in Swift like Preon in Java

293 Views Asked by At

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?

0

There are 0 best solutions below