readUTF8EncodedString2 method

String readUTF8EncodedString2(
  1. int stringLength
)

Decodes the given amount of bytes from the read buffer to a string.

@param stringLength the length of the string in bytes. @return the UTF-8 decoded string (may be null).

Implementation

String readUTF8EncodedString2(int stringLength) {
  assert(stringLength > 0);
  if (this._bufferPosition + stringLength <= this._bufferData.length) {
    this._bufferPosition += stringLength;
    //_log.info("Reading utf8 $stringLength bytes ending at $_bufferPosition");
    String result = utf8.decoder.convert(_bufferData, _bufferPosition - stringLength, _bufferPosition);
    //_log.info("String found $result");
    return result;
  }
  throw Exception("Cannot read utf8 string with $stringLength length at position $_bufferPosition of data with ${_bufferData.length} bytes");
}