Skip to content

CBOR: decodeCollectionSize ignores definite-length headers and always returns -1 #3154

@kozaxinan

Description

@kozaxinan

When parsing CBOR payloads, CompositeDecoder.decodeCollectionSize() currently always returns -1 (unknown size). However, the CBOR specification supports definite-length maps and arrays (Major Types 4 and 5), where the exact size is explicitly declared in the binary header.

Because the decoder ignores this header information, custom serializers cannot pre-allocate collection capacities, leading to expensive memory reallocations on large payloads (especially problematic on Android).

Proposed Solution
Update CborMapReader and CborListReader to parse and return the exact integer size from the binary header when a definite-length map or array is encountered.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions