I am semi-new to clojure and I’m sitting with an funcool/octet problem, would this be the right forum to ask questions?
well assuming this is the right forum, I’ll ask and we’ll see what I receive : )
I’m trying to parse parts of the zip file specification using octet and a fair amount of the spec uses variable length strings. octet supports variable length strings, but if I’m reading things correctly, only if the length is a four byte int32 and immediately preceding the string data. The zip spec has plenty of instances where the you have a record and the stringlength is either an int16 or is not immediately before the data. I would like to solve this with a custom special-string*
spec which would take a keyword as an argument and the keyword would point to the spec containing the length of the string.
example from zip specification:
central file header signature 4 bytes (0x02014b50)
...
file name length 2 bytes
extra field length 2 bytes
file comment length 2 bytes
disk number start 2 bytes
internal file attributes 2 bytes
external file attributes 4 bytes
relative offset of local header 4 bytes
file name (variable size)
extra field (variable size)
file comment (variable size)
in this case I would like to have:
(spec
:file-name-length int16
:extra-field-length int16
:file-comment-length int16
...
:file-name (special-string* :file-name-length)
...
)
or something similar, fair chance I’m missing something as I don’t have all that much mileage with clojure
I haven’t been able to figure out how to write this custom spec and any help or pointers would be much appreciated