writeString method

  1. @override
void writeString(
  1. String s
)
override

Writes a String s into the buffer

  • s: the value to write

Implementation

@override
void writeString(String s) {
  final encoded = encodeString(s);
  final length = encoded.length;
  if (length <= 31) {
    writeUint8(0xA0 | length);
  } else if (length <= 0xFF) {
    writeUint8(0xd9);
    writeUint8(length);
  } else if (length <= 0xFFFF) {
    writeUint8(0xda);
    writeUint16(length);
  } else if (length <= 0xFFFFFFFF) {
    writeUint8(0xdb);
    writeUint32(length);
  } else {
    throw MsgPackOverflowError(
        'String is too long to be serialized with msgpack.');
  }
  writeBytes(encoded);
}