Hi,
I am implementing broker as a hobby project. Here is the high level flow.

1. Set up a response header with correlation ID and header version (1).
2. Create an `ApiVersionCollection` and add APIs. For now, I have added
only two - `PRODUCE` and `METADATA` with min, max versions and no tagged
fields.
3. Create `ApiVersionsResponseData` with error code as 0, throttle as 0 and
set API keys with the `ApiVersionCollection` created above.
4. Create `ApiVersionsResponse` with the `ApiVersionsResponseData` above.
5. Create a buffer of size `4 + responseHeader.size() +
response.data().size(cache, apiVersion);`
6. Populate buffer with payload size, response header and response.
7. Invoke `response.data().write(accessor, cache, apiVersion);` where
apiVersion is set to 3.

When I look into Wireshark, I can see the API keys array prepended with
number of keys + 1 _stored in 2 bytes_. This is the `write` method in
`ApiVersionsResponseData`.

```
    @Override
    public void write(Writable _writable, ObjectSerializationCache _cache,
short _version) {
        int _numTaggedFields = 0;
        _writable.writeShort(errorCode);
        if (_version >= 3) {
            _writable.writeUnsignedVarint(apiKeys.size() + 1);
            for (ApiVersion apiKeysElement : apiKeys) {
                apiKeysElement.write(_writable, _cache, _version);
            }
        } else {
            _writable.writeInt(apiKeys.size());
            for (ApiVersion apiKeysElement : apiKeys) {
                apiKeysElement.write(_writable, _cache, _version);
            }
        }
...
}
```

Why is `writeUnsignedVarint()` writing `0x0003` instead of `0x03`? Really
struggling with this - any guidance will be highly appreciated.

Thanks.

Reply via email to