Re: Help reading structured binary files
- From: "Bruce Roberts" <ber@xxxxxxxxxxxxxxxxxxxxxx>
- Date: Mon, 18 Jul 2005 10:16:25 -0400
"Robert Kilroy" <kilroy@xxxxxxxxx> wrote in message
news:1121662250.936302.327560@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> Greetings,
>
> I was given a task to read some binary files that we will be dumping
> into our database. The files are in key/value pairs in the format of:
>
> Field ID = 2 bytes ( (Byte2 * 256) + Byte1 )
> Field Length = 1 byte (0-255)
> Field Data = 1 to 255 bytes
> Files terminated by 2 bytes of 255
>
> I'm not entirely what these files are, I was told "Put these in the
> database".
> I was wondering if I could use some sort of Record structure, but
> either way it seems I need to read the third byte to get the length of
> the data. Maybe a BlockRead? But is there a faster way to convert each
> byte into its CHR value for a string?
Type
pLoadRec = ^ tLoadRec;
tLoadRec = packed record
id : ShortInt;
data : string [255];
terminator : array [0 .. 1] of byte;
end;
The simplest way to load the records with this type would be a file of
tLoadRec. A (file) stream would also work and might prove more flexible.
Instead of using a string list you could use a tList or dynamic array and
New & Dispose. Converting the id from a numeric to a string, unless its
necessary, is a relatively costly operation.
.
- Follow-Ups:
- Re: Help reading structured binary files
- From: Robert Kilroy
- Re: Help reading structured binary files
- From: Rob Kennedy
- Re: Help reading structured binary files
- References:
- Help reading structured binary files
- From: Robert Kilroy
- Help reading structured binary files
- Prev by Date: Re: Help reading structured binary files
- Next by Date: Re: Rotate bitmap
- Previous by thread: Re: Help reading structured binary files
- Next by thread: Re: Help reading structured binary files
- Index(es):
Relevant Pages
|