unpackMapLength method

int unpackMapLength()

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

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

Implementation

int unpackMapLength() {
  final b = _d.getUint8(_offset);
  int len;
  if (b & 0xF0 == 0x80) {
    /// fixmap 1000XXXX stores a map whose length is upto 15 elements
    len = b & 0xF;
    _offset += 1;
  } else if (b == 0xc0) {
    len = 0;
    _offset += 1;
  } else if (b == 0xde) {
    len = _d.getUint16(++_offset);
    _offset += 2;
  } else if (b == 0xdf) {
    len = _d.getUint32(++_offset);
    _offset += 4;
  } else {
    throw _formatException('Map length', b);
  }
  return len;
}