childCount

Number of top-level children: fields for an object, elements for an array, 0 for a scalar.

The one counter that answers for every shape. elementCount and fieldCount stay, and stay throwing, because their job is to assert the shape; this one's job is to let a caller who does not know the shape ask anyway, which is what summarising a value needs. It is one branch over those two answers rather than a third definition of either.

The branch is on basicType rather than kind, deliberately: a primitive whose type id this build does not know still has no children, and that answer never depended on the byte this build cannot read — so it is not a default invented for unknown data, it is an answer that never needed it. Ask kind if you want the failure.

O(1) for every shape.

Throws

if the bytes do not decode.