There is an appended `0x00` after the correlation ID if the response header version is v1 because of the tag buffer. While this is valid, the client does not seem to honor this response. With the response header version set to v0, the payload is honored correctly by the client. By that, I mean, the client sends the subsequent metadata request and other messages. Therefore, what is the guidance w.r.t. setting the response header version?
On Sat, Nov 2, 2024 at 8:44 PM Chain Head <mrchainh...@gmail.com> wrote: > 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. >