gloss
gloss copied to clipboard
repeated :encoding-delimiter
Hi Zach,
I'm using Gloss to decode different types of repeated headers, often following the Internet Message (RFC-5322) style.
Given the simple case of a repeated header in the style "key:value\r\n" where the total section is delimited by "\r\n\r\n", I can decode fine with a codec like:
(defcodec basic-header
[(string :utf-8 :delimiters [":"])
(string :utf-8 :delimiters ["\r\n" "\r\n\r\n"])])
(defcodec basic-headers
(repeated basic-header :delimiters ["\r\n\r\n"]
:strip-delimiters? false))
i.e. Leave the repeated section delimiter to be consumed by the inner codec.
Decoding is fine, the problem is when encoding Gloss will emit a delimiter for each inner header, "\r\n", then the delimiter for the repeated section "\r\n\r\n", leaving me with one too many "\r\n\r\n"
While I'm not actually encoding headers, I thought it might be a nice addition to be able to specify the encoding-delimiter for a repeated section:
(defcodec basic-headers
(repeated basic-header :delimiters ["\r\n\r\n"]
:encoding-delimiter "\r\n"
:strip-delimiters? false))
If this is agreeable I'd be happy to supply a pull-request for you.
More information here: http://derek.troywest.com/articles/by-example-gloss/#basic-limitations
Thanks, Derek