Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search

[REBOL] Re: Unusual file format

From: tim:johnsons-web at: 14-Nov-2000 14:17

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: