writeExt method

void writeExt(
  1. int type,
  2. Uint8List bytes
)

Writes the type extension to the buffer

  • type: The type code
  • bytes: The byte buffer to write

Implementation

void writeExt(int type, Uint8List bytes) {
  final length = bytes.length;
  if (length == 1) {
    writeUint8(types.fixext1);
  } else if (length == 2) {
    writeUint8(types.fixext2);
  } else if (length == 4) {
    writeUint8(types.fixext4);
  } else if (length == 8) {
    writeUint8(types.fixext8);
  } else if (length == 16) {
    writeUint8(types.fixext16);
  } else if (length <= 0xFF) {
    writeUint8(types.ext8);
    writeUint8(length);
  } else if (length <= 0xFFFF) {
    writeUint8(types.ext16);
    writeUint16(length);
  } else if (length <= 0xFFFFFFFF) {
    writeUint8(types.ext32);
    writeUint32(length);
  } else {
    throw MsgPackOverflowError('Size must be at most 0xFFFFFFFF');
  }

  writeUint8(type);
  writeBytes(bytes);
}