# Stuck trying to parse api version

**URL:** https://forum.codecrafters.io/t/stuck-trying-to-parse-api-version/8923
**Category:** Challenges
**Tags:** challenge:kafka
**Created:** [April 18, 2025, 2:06am UTC](https://forum.codecrafters.io/t/stuck-trying-to-parse-api-version/8923 "2025-04-18T02:06:21Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![malawarecreator](https://yyz1.discourse-cdn.com/flex003/user_avatar/forum.codecrafters.io/malawarecreator/32/9390_2.png) [@malawarecreator](https://forum.codecrafters.io/u/malawarecreator)
#### Post date: [April 18, 2025, 2:06am UTC](https://forum.codecrafters.io/t/stuck-trying-to-parse-api-version/8923/1 "2025-04-18T02:06:21Z")

</div>

```rs
#![allow(unused_imports)]
use std::{io::{Cursor, Read, Write}, net::TcpListener};
use tokio::io::AsyncReadExt;
#[tokio::main(flavor = "current_thread")]
async fn main() {
    
    println!("Logs from your program will appear here!");

    
    
    let listener = TcpListener::bind("127.0.0.1:9092").unwrap();
    
    for stream in listener.incoming() {
        match stream {
            Ok(mut _stream) => {

                
                println!("accepted new connection");

                let mut buf = [0_u8; 4];

                _stream.read_exact(&mut buf).unwrap();
                let mut rdr = Cursor::new(buf);
                let len = rdr.read_u32().await.unwrap();
                let mut msg = vec![0u8; len.try_into().unwrap()];
                _stream.read_exact(&mut msg.as_mut_slice()).unwrap();

                let mut rdr = Cursor::new(msg);

                rdr.read_u16().await.unwrap();
                let version = rdr.read_u16().await.unwrap();
                

                let cid = rdr.read_u32().await.unwrap();
                let acceptable_range = 0..4;
                if acceptable_range.contains(&version) {
                    _stream.write_all([0, 0, 0, 4].as_slice()).unwrap();
                    _stream.write_all(&cid.to_be_bytes()).unwrap();
                } else {

                    let errorcode: i32 = 35;
                    _stream.write_all([0, 0, 0, 4].as_slice()).unwrap();
                    _stream.write_all(&cid.to_be_bytes()).unwrap();
                    _stream.write_all(&errorcode.to_be_bytes()).unwrap();
                }
                
            }
            Err(e) => {
                println!("error: {}", e);
            }
        }
    }
}

```

this is my code  
it says expected error 35 got 0

---

<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: [April 18, 2025, 2:07am UTC](https://forum.codecrafters.io/t/stuck-trying-to-parse-api-version/8923/3 "2025-04-18T02:07:29Z")

</div>

Hey @malawarecreator, could you [upload your code to GitHub](https://docs.codecrafters.io/features/publish-to-github) and share the link? It will be much easier to debug if I can run it directly.

---

<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: [April 28, 2025, 12:46pm UTC](https://forum.codecrafters.io/t/stuck-trying-to-parse-api-version/8923/4 "2025-04-28T12:46:42Z")

</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: ![system](https://canada1.discourse-cdn.com/flex003/uploads/codecrafters/original/3X/7/0/700657133935c15703e22c7c8870394f6e6dc27d.svg) [@system](https://forum.codecrafters.io/u/system)
#### Post date: [May 3, 2025, 12:46pm UTC](https://forum.codecrafters.io/t/stuck-trying-to-parse-api-version/8923/5 "2025-05-03T12:46:57Z")

</div>

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