Hello, I'm trying to parse a binary file from the Jet Propulsion Laboratory (JPL). They provide binary files known as Double Precision Array Files (DAF) which contain data for planets' ephemeris. This file is created as contiguous address of mixed integers, doubles and strings (with different byte counts). The structure for it is detailed here: DAF Reference
I'm using swift-system
with their FileDescriptor
struct to go little by little on the data without loading it entirely into memory since it's several MB heavy.
var buffer = ...
let _ = try descriptor.read(fromAbsoluteOffset: Int64(0), into: buffer)
The read
method requires as parameter an UnsafeMutableRawBufferPointer
with count of 1024
.
The only way I found to instantiate the buffer is through:
UnsafeMutableRawBufferPointer.allocate(byteCount: 1024, alignment: ???)
But I don't what to put on alignment, neither what its role is. Is there a way to determine what is the best alignment for a set of heterogeneous data in a binary file?
The first part of the DAF file, determines its properties located at:
-
LOCIDW (8 characters, 8 bytes): An identification word.
-
ND ( 1 integer, 4 bytes) [Address 8]
-
NI ( 1 integer, 4 bytes) [Address 12]
-
LOCIFN (60 characters, 60 bytes) [Address 16]
-
FWARD ( 1 integer, 4 bytes) [Address 76]
-
BWARD ( 1 integer, 4 bytes) [Address 80]
-
FREE ( 1 integer, 4 bytes) [Address 84]
-
LOCFMT ( 8 characters, 8 bytes) [Address 88]
-
PRENUL ( 603 characters, 603 bytes) [Address 96]
-
FTPSTR ( 28 characters, 28 bytes) [Address 699]
-
PSTNUL ( 297 characters, 297 bytes) [Address 727]