private string ReadName(int position, int nameLength)
{
Debug.Assert(position > 0);
Debug.Assert(nameLength >= 0 && (position + nameLength) <= _buffer.Length);
int lengthWithoutNullTerm = nameLength;
for (int i = 0; i < nameLength; i++)
{
if (_buffer[position + i] == '\0')
{
lengthWithoutNullTerm = i;
break;
}
}
Debug.Assert(lengthWithoutNullTerm <= nameLength); // should be null terminated or empty
return lengthWithoutNullTerm > 0 ?
Encoding.UTF8.GetString(_buffer, position, lengthWithoutNullTerm) :
string.Empty;
}