clj-commons / clj-commons/gloss
repeated :encoding-delimiter
- Dominant language
- Clojure
- Stars
- 486
- Forks
- 53
- PR merge metrics
- No merged PRs in 30d
Description
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:
``` clojure
(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:
``` clojure
(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
Contributor guide
No contributing guide indexed for this repository
Research direction
Start by reading the repeated codec and the defcodec examples shown in the issue, focusing on how delimiters are used during encoding versus decoding. Done means a repeated section can accept an encoding-delimiter such as "\r\n" without emitting an extra section delimiter, while the existing decoding behavior remains intact.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- clojure
- Domain
- networking
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100