Hi,
I'm trying to parse a "binary" file with the help of gloss. My problem
is, the data is in a format that gloss seeminglydoesn't deal with at all.

The file start with a plaintext header, followed by some binary data,
which may be compressed in various formats. What I'm trying to
do is parse the header, and then store the binary blobs away to be 
decompressed later.

A typical header looks like this:
SPKCycrow;4.20;1;727\r\n
<binary prefix>[<binary data>...]

That's in order: FileType magic string, FileType version, enum for
compression format, length of compressed data, linebreak, :int32-be
length of decompressed data and then the data (in my case zlib).

Here's how far I got:
-----------------------------------------------------------------------
(defcodec compression (enum :byte {:none \0, :zlib \1, :7zip \2,
                                   :lzma \3, :best \4}))

(defcodec file-header
  (ordered-map :filetype    (string :utf-8 :delimiters [";"])
               :spkversion  (string :utf-8 :delimiters [";"])
               :compression compression
               :junk        :byte
               ))

(defcodec blocksize (string-integer :utf-8 :delimiters ["\n"]))

(defcodec value
  (ordered-map :size       blocksize
               :decompsize :int32-be
               :data       (finite-frame ??? (repeated :byte :prefix 
:none))))

(defcodec payload (repeated :byte :prefix :none))

(defcodec spkfile [file-header value payload])
-----------------------------------------------------------------------

My 2 problems:
- note the :junk in file-header, this I had to do since enum only accepts 
  primitives. (This also means enum switches on the ASCII-value of the
  number instead of the actual number.) Is there a better way to coerce
  "1;", "2;", etc. into an enum?
- the ??? in the finite-frame of value, what do I put there? how do I get
  blocksize into the size definition of the frame? Gloss seems to assume
  that any such definitions *directly* precede the following data.

Any pointers are greatly appreciated.

-- 
-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to clojure+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to