sublist<T> method

CborListValue<T> sublist<T>(
  1. int start, [
  2. int? end
])

Returns a new CborListValue containing elements from this list from start inclusive to end exclusive.

If start or end are out of bounds, throws a MessageException

Implementation

CborListValue<T> sublist<T>(int start, [int? end]) {
  if (start >= value.length || (end != null && end >= value.length)) {
    throw MessageException("Index out of bounds.",
        details: {"length": value.length, "Start": start, "End": end});
  }
  return CborListValue.fixedLength((value as List<CborObject>)
      .sublist(start, end)
      .map((e) => e.cast<T>())
      .toList());
}