Hi, Michal,

Good question. Assignment is of type struct and the generated serialization
code is the following.

if (assignment == null) {
    _writable.writeByte((byte) -1);
} else {
    _writable.writeByte((byte) 1);
    assignment.write(_writable, _cache, _version);
}


So, for a nullable struct field, the first byte indicates whether it is
null. I agree that it would be useful to document this. I filed
https://issues.apache.org/jira/browse/KAFKA-19634 to track it.

Thanks,

Jun

On Tue, Aug 12, 2025 at 7:50 AM Michał Kalinowski <kalin8...@gmail.com>
wrote:

> Hello!
>
> When implementing the ConsumerGroupHeartbeat API for the TchKafka project,
> I faced problems deserializing the Assignment property of the Response. The
> documentation states that it should be "null if not provided; the
> assignment otherwise." However, in protocol primitive types, there is no
> such thing as Null itself, so I assumed that's part of CompactArray, as for
> the topic_partitions property of the Request or any other property in the
> protocol. Unfortunately, it was not the case, and Null for the assignment
> property is encoded as one byte smaller than 0. If it's not null, it's
> still a CompactArray (which is capable of encoding nulls by itself, by the
> way). Is this Null encoding an established protocol primitive type? If so,
> can we add this to the docs? What's the purpose of encoding the null
> outside of CompactArray?
>
> BR,
> Michał Kalinowski
>

Reply via email to