Hi, I'm new to gleam and I'm doing the codecrafters kafka challenge with it.
One of the stages requires being able to parse variable-width ints from within a bit array. In the protobuf docs, it mentions how to do it:
https://protobuf.dev/programming-guides/encoding/#varints
I'm new to bit manipulation and was confused on a couple things:
- How would you do a logical shift in gleam? I only saw an arithmetic shift in stdlib, thus the only thing i thought of was pattern matching & discarding the first bit.
- Any way to reverse the sections in a bit array (little endian to big endian)? Or is it only possible to just do list.reverse() on a list of bitarrays?
- After all that, whats a way to concatenate all the sections to be interpreted as one int? is it appending all of them and then pattern matching it as
// given that we discard the msb for each section, each section is 7 bits
<<result:unit(7)-size(num_sections)>> = combined
thanks in advance!
Explains how Protocol Buffers encodes data to files or to the wire.