I am developing MQTT server in Clojure. I use Gloss to parse binary data. However, I'm stuck with Variable Byte Integer, not sure how to create codec for this. My gut feeling it should use header
frame somehow, but I'm not sure how to put it together. So my questions are: 1. Is it possible to represent this as Gloss codec, or I should use some other approach? 2. Can you please provide codec for this? Thanks!
Asked
Active
Viewed 204 times
0

Vladimir Kadalashvili
- 747
- 2
- 5
- 17
-
I want to be contributer. Can you share your code with me ? – SefaUn Jun 27 '21 at 09:39
-
I just started working on it, didn't publish yet – Vladimir Kadalashvili Jun 27 '21 at 09:53
-
Here's the repo https://github.com/selentium/clj-mqtt – Vladimir Kadalashvili Jul 04 '21 at 15:28
-
Why did you choose Clojure language to code the mqtt ? @VladimirKadalashvili – SefaUn Jul 06 '21 at 18:38
-
Just want to practice with Clojure @SefaUn – Vladimir Kadalashvili Jul 08 '21 at 09:11
-
could you code mqtt protocol ? @VladimirKadalashvili – SefaUn Jul 08 '21 at 17:33
2 Answers
1
Reading the docs, it looks like you'll need to define something new to process the VBI encoding.
Since Gloss appears to expect only fixed-length representations, your algorithm will probably need to accept a block of bytes with a VBI at the beginning, then decode the VBI and return
- the decoded value
- the remaining bytes
The bytes from (2) can then be input to Gloss as normal. If the VBI is not the first item in the overall input, you can strip off any leading bytes using Gloss or any other means.

Alan Thompson
- 29,276
- 6
- 41
- 48
0
Ended up creating custom codec for Gloss https://github.com/selentium/clj-mqtt/blob/master/src/clj_mqtt/varint.clj

Vladimir Kadalashvili
- 747
- 2
- 5
- 17