unpackListLength method

int unpackListLength()

Unpack List.length if packed value is an List or null.

Encoded in msgpack packet null or 0 length unpacks to 0 for convenience. Items of the List must be unpacked manually with respect to returned length Throws FormatException if value is not an List.

Implementation

int unpackListLength() {
  final b = _d.getUint8(_offset);
  int len;
  if (b & 0xF0 == 0x90) {
    /// fixarray 1001XXXX stores an array whose length is upto 15 elements:
    len = b & 0xF;
    _offset += 1;
  } else if (b == 0xc0) {
    len = 0;
    _offset += 1;
  } else if (b == 0xdc) {
    len = _d.getUint16(++_offset);
    _offset += 2;
  } else if (b == 0xdd) {
    len = _d.getUint32(++_offset);
    _offset += 4;
  } else {
    throw _formatException('List length', b);
  }
  return len;
}