writeUnsignedArrayInRange method

void writeUnsignedArrayInRange(
  1. int id,
  2. List<int> values,
  3. int count,
  4. int lo,
  5. int hi,
)

Writes an array of unsigned integers like writeUnsignedArray — the first count of values — and refuses an element outside the declared width lo..hi with SofabError.invalidArgument (CORELIB_PLAN §6.3).

The width is the caller's argument, the same pair the decoder applies to an InlineInt64Array destination; the codec holds none of its own (§6.2.1). Each element is compared as the varint loop loads it, so the check costs one compare pair per element and no pass of its own. The refusal ends the message: the bytes already written for it are not a success and must be discarded. For an unsigned width lo is 0, so an element Dart shows as negative (one at or past 2^63) is refused too.

A writer of its own rather than an optional argument of writeUnsignedArray: plain int bounds and a required count keep the call free of a nullable argument, its test and the field loads of a range object — measured about 1.6 % of a whole encode on the generator's vehicle-telemetry benchmark.

Implementation

void writeUnsignedArrayInRange(
  int id,
  List<int> values,
  int count,
  int lo,
  int hi,
) {
  _checkCount(count, values);
  _writeHeader(id, WireType.arrayUnsigned);
  _writeVarint(count);
  _writeUnsignedInRange(id, values, count, lo, hi);
}