writeString method

int writeString(
  1. String s
)

Implementation

int writeString(String s) {
  int written = 0;
  int sLength = s.length;
  while (sLength >= 0x80) {
    // the extra & 0xff is to strip off all bits higher than 0xff
    data.addByte((sLength | 0x80) & 0xff);
    sLength >>= 7;
    written++;
  }
  data.addByte(sLength);
  written++;

  var b = Utf8Encoder().convert(s);
  written += b.lengthInBytes;
  data.add(b);

  return written;
}