# Question about nc5: Parse API Version

**URL:** <https://forum.codecrafters.io/t/question-about-nc5-parse-api-version/2410>\
**Category:** Challenges\
**Tags:** challenge:kafka\
**Created:** [October 16, 2024, 6:15am UTC](https://forum.codecrafters.io/t/question-about-nc5-parse-api-version/2410 "2024-10-16T06:15:55Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![codesbyayush](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/codesbyayush/32/36_2.png) [@codesbyayush](https://forum.codecrafters.io/u/codesbyayush)\
**Post date:** [October 16, 2024, 6:15am UTC](https://forum.codecrafters.io/t/question-about-nc5-parse-api-version/2410/1 "2024-10-16T06:15:55Z")

</div>

How will we parse the api\_version if it’s negative as u8 only represent the positive values.

---

<div class="post-metadata">

**Author:** ![FRIZFOREVER](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/frizforever/32/2382_2.png) [@FRIZFOREVER](https://forum.codecrafters.io/u/FRIZFOREVER)\
**Post date:** [October 16, 2024, 6:30am UTC](https://forum.codecrafters.io/t/question-about-nc5-parse-api-version/2410/2 "2024-10-16T06:30:54Z")

</div>

Depends on the language, but it doesn’t have to be u8, as, according to kafka documentation, api\_ver comes as an int16, which is stated here: [Apache Kafka](https://kafka.apache.org/protocol.html#protocol_messages)  
It doesn’t mean that we can’t receive some garbage in request. Then it comes to error handle’ing, which we are doing in the exercise. My solution i.e. implements a match statement for api\_ver, which creates correct response if api ver contains anything between 0 and 4 inclusively and for everything else we create an error response.  
In case we cannot even parse api\_ver, we would also send error response

---

<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:** [October 24, 2024, 3:22pm UTC](https://forum.codecrafters.io/t/question-about-nc5-parse-api-version/2410/3 "2024-10-24T15:22:48Z")

</div>

Closing this thread due to inactivity. If you still need assistance, feel free to reopen or start a new discussion!

---

<div class="post-metadata">

**Author:** ![LzzCongee](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/lzzcongee/32/1320_2.png) [@LzzCongee](https://forum.codecrafters.io/u/LzzCongee)\
**Post date:** [October 29, 2024, 5:04am UTC](https://forum.codecrafters.io/t/question-about-nc5-parse-api-version/2410/4 "2024-10-29T05:04:29Z")

</div>

take my code for example

```auto
messageSize := binary.BigEndian.Uint32( request[0:4] ) // request message size

binary.BigEndian.PutUint32(response[0:4], uint32(messageSize)) // 4 Byte

```

- in my code which cannot pass the test , here I falsely set the response message size as the request message size, which cause the tester `read the wrong number of bytes` from connection;
- so I later set the response size to a fixed value `19` correctly ;
- and you can also set the `response_header_size` according to your response structure

---

<div class="post-metadata">

**Author:** ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)\
**Post date:** [November 3, 2024, 5:05am UTC](https://forum.codecrafters.io/t/question-about-nc5-parse-api-version/2410/5 "2024-11-03T05:05:09Z")

</div>

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.
