public string ReadString()
{
int length = ReadLength();
// No need to read any data for an empty string.
if (length == 0)
{
return "";
}
if (length <= bufferSize - bufferPos)
{
// Fast path: We already have the bytes in a contiguous buffer, so
// just copy directly from it.
String result = CodedOutputStream.Utf8Encoding.GetString(buffer, bufferPos, length);
bufferPos += length;
return result;
}
// Slow path: Build a byte array first then copy it.
return CodedOutputStream.Utf8Encoding.GetString(ReadRawBytes(length), 0, length);
}