def create_msg(id,api_key: int, error_code: int = 0):
response_header = id.to_bytes(4, byteorder="big")
err = error_code.to_bytes(2, byteorder="big")
api_key_bytes = api_key.to_bytes(2, byteorder="big")
min_version, max_version = 0,4
tag_buffer = b"\x00"
num_api_keys = int(2).to_bytes(1, byteorder="big")
throttle_time_ms = 0
response_body = (
err+
num_api_keys+
api_key_bytes+
min_version.to_bytes(2)+
max_version.to_bytes(2)+
tag_buffer+
throttle_time_ms.to_bytes(4, byteorder="big")+
tag_buffer
)
total_len = len(response_header) + len(response_body)
return int(total_len).to_bytes(4, byteorder="big") + response_header + response_body
here in this code if we take num_api_keys = 1 decoder takes it value as 0 while if we take num_api_keys = 2 decoder takes it value as 2 and i don’t seem to understand this why this happening?