0

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!

2 Answers2

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

  1. the decoded value
  2. 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