requireAvailable method

void requireAvailable(
  1. int offset,
  2. int length
)

Throws LayoutException unless length bytes starting at offset are available. Fixed-span decodes call this first so short reads fail as LayoutException instead of leaking raw range errors from the byte utilities underneath.

Implementation

void requireAvailable(int offset, int length) {
  if (offset < 0 || length < 0 || offset + length > _bytes.length) {
    throw BuError(
      DefaultErrorType.invalidLength,
      "Truncated layout bytes.",
      details: {
        "offset": offset.toString(),
        "length": length.toString(),
        "available": _bytes.length.toString(),
      },
    );
  }
}