Thanks, header seems very useful and relevant to what I was doing, but I 
ended up doing something slightly different because I needed to include the 
information retrieved using the chunk header codec in the final result 
(specifically, the type of the chunk). Here is some code:

https://gist.github.com/stathissideris/8801295

select-codec is almost identical to header (didn't bother with writing in 
this case), but it also merges the result of the "decision-codec" with the 
result of the selected codec. Of course it's less generic than header 
because it makes the assumption that we're dealing with maps. Also, note 
the use of core.match to decide on what codec to use.

Stathis


On Monday, 3 February 2014 16:50:12 UTC, Steffen Dienst wrote:
>
> I would use header for this:
>
>     (def chunk 
>       (header :int-be
>               #(ordered-map 
>                   :type (b/repeated :byte :length 4)
>                   :data (b/repeated :byte :length %)
>                   :crc (b/repeated :byte :length 4))
>               #(count (:data %))))
>
> The resulting data structure would not contain the field length in this 
> case. Length only gets used to configure the inner codec for the body (the 
> map with :type, :data and :crc). You can read this codec as: "Read a 
> big-endian integer, then use this value to construct a new codec to read 
> the body. When writing, count the :data field, write the length using :type 
> and then write the body".
>
> Steffen
>
>
> 2014-02-03 Stathis Sideris <sid...@gmail.com <javascript:>>:
>
>> Hello,
>>
>> Is it possible to use 'repeated with a dynamic size if the 
>> length-defining prefix does not directly precede the content? For example, 
>> see PNG chunks:
>>
>>
>> http://en.wikipedia.org/wiki/Portable_Network_Graphics#.22Chunks.22_within_the_file
>>
>> The codec would be:
>>
>> (def chunk
>>   (b/ordered-map
>>    :length :int-be
>>    :type (b/repeated :byte :length 4)
>>    :data (b/repeated :byte :length ???)
>>    :crc (b/repeated :byte :length 4)))
>>
>> What do I put in the place of "???"
>>
>> Thanks,
>>
>> Stathis
>>
>>
>> On Friday, 31 January 2014 08:12:23 UTC, Steffen Dienst wrote:
>>>
>>> Thanks, I fixed the documentation issues. Feel free to share your id3 
>>> tags parser, if you like :) You can see that mine is still stuck at the 
>>> very beginning..
>>>
>>>
>>>  -- 
>> You received this message because you are subscribed to the Google
>> Groups "Clojure" group.
>> To post to this group, send email to clo...@googlegroups.com<javascript:>
>> Note that posts from new members are moderated - please be patient with 
>> your first post.
>> To unsubscribe from this group, send email to
>> clojure+u...@googlegroups.com <javascript:>
>> For more options, visit this group at
>> http://groups.google.com/group/clojure?hl=en
>> --- 
>> You received this message because you are subscribed to a topic in the 
>> Google Groups "Clojure" group.
>> To unsubscribe from this topic, visit 
>> https://groups.google.com/d/topic/clojure/2c9-oXfKlp0/unsubscribe.
>> To unsubscribe from this group and all its topics, send an email to 
>> clojure+u...@googlegroups.com <javascript:>.
>> For more options, visit https://groups.google.com/groups/opt_out.
>>
>
>

-- 
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