Hello Mike:
I'll show you how to get started, and I'll bet that you will
get even better tips from others in the list. But first, I
observe a discrepancy in your example, the hex dump seems
to off by 1.
;First, run the following code so that you have a test setup:
variable: #{01 00 05 41 42 43 44 45 02 00 10 41 42 43 44 45
           46 47 48 49 4A 4B 4C 4D 4E 4F 50 FF FF}
write/binary %bin.tst variable
;Now you have the binary data written to a file, next step
; is to test the binary read, and give you an idea of how to
;map out the binary data into the data-types that you request;
; run the following script now:
;  read data into buffer
print variable: read/binary %bin.tst
; parse out field-number
print field-num: copy/part variable 2
; and convert it to an integer, correcting for byte order
print field-num: to-integer head reverse field-num
; skip the read data
variable: skip variable 2
; demonstrate where variable points to
print variable
; get the field length
field-len: copy/part variable 1
; and convert it to an integer so that copy/part has an integer argument
print field-len: to-integer field-len
; skip the read data
variable: skip variable 1
; get text
text-field: copy/part variable field-len
; convert to string
print to-string text-field
; hopefully, this will get you started in the conceptualization....
; next step is to make this elegant! :)
I hope this helps (I wrote an entire dbms in "C" using this method).
Trust me, it's much easier in rebol
-Tim
Mike Duncan wrote:

> I need to create a file in Windows with the following format (not one I
> designed):
>   Field number - 2 bytes in MS Lo-Hi order
>   Field length - 1 byte
>   String data  - as many characters as specified in field length
>
> Using a hex editor the file would look like this:
>   01 00 05 41 42 43 44 45   02 00 10 41 42 43 44 45    ...ABCDEF...ABCDE
>   46 47 48 49 4A 4B 4C 4D   4E 4F 50 FF FF             FGHIJKLMNOP..
>
> with field number 1, 5 characters "ABCDE"
>      field number 2, 16 characters "ABCDEFGHIJKLMNOP"
> FF FF marks the end of the file.
>
> Any help would be appreciated. I'm new to Rebol and am having trouble with
> this one.
>
> TIA
>
> Mike
>
> --
> To unsubscribe from this list, please send an email to
> [EMAIL PROTECTED] with "unsubscribe" in the
> subject, without the quotes.

-- 
To unsubscribe from this list, please send an email to
[EMAIL PROTECTED] with "unsubscribe" in the 
subject, without the quotes.

Reply via email to