# How to parse variable sized integer from metadata log

**URL:** <https://forum.codecrafters.io/t/how-to-parse-variable-sized-integer-from-metadata-log/4254>\
**Category:** Challenges\
**Tags:** challenge:kafka\
**Created:** [January 17, 2025, 3:12pm UTC](https://forum.codecrafters.io/t/how-to-parse-variable-sized-integer-from-metadata-log/4254 "2025-01-17T15:12:29Z")\
**Posts on this page:** 1\
**Showing post:** 5

<div class="post-metadata">

**Author:** ![andy1li](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/andy1li/32/10_2.png) [@andy1li](https://forum.codecrafters.io/u/andy1li)\
**Post date:** [January 21, 2025, 2:48pm UTC](https://forum.codecrafters.io/t/how-to-parse-variable-sized-integer-from-metadata-log/4254/5 "2025-01-21T14:48:12Z")

</div>

It’s the Calculator app on mac in programmer mode:

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/7/76fbd0e5f88d40b60888f3a24421853a60aec703.jpeg)

* * *

You’re absolutely right! It’s 257. I was a bit confused as well, because the length of `Value (Partition Record)` is apparently 65 (= 1 + 16 x 4):

 ![image](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/2X/a/a6fd2f4fa8656609cd1056fd3de97946d3b4d24a.png)

Turns out that VARINT in Kafka involves two additional considerations:

1. [Small/Big-endian order](https://protobuf.dev/programming-guides/encoding/#varints)
2. [Zig-zag encoding](https://protobuf.dev/programming-guides/encoding/#signed-ints)

```auto
000 0010 + 000 0001 reverses order due to endianness:

000 0001 + 000 0010

= 1 000 0010 = 130

```

130 becomes 130 / 2 = 65 due to zig-zag encoding.

---

_[View the full topic](https://forum.codecrafters.io/t/how-to-parse-variable-sized-integer-from-metadata-log/4254)._
