Newtonsoft.Json.Bson.BsonBinaryWriter.WriteString C# (CSharp) Method

WriteString() private method

private WriteString ( string s, int byteCount, int calculatedlengthPrefix ) : void
s string
byteCount int
calculatedlengthPrefix int
return void
    private void WriteString(string s, int byteCount, int? calculatedlengthPrefix)
    {
      if (calculatedlengthPrefix != null)
        _writer.Write(calculatedlengthPrefix.Value);

      if (s != null)
      {
        if (_largeByteBuffer == null)
        {
          _largeByteBuffer = new byte[256];
          _maxChars = 256/Encoding.GetMaxByteCount(1);
        }
        if (byteCount <= 256)
        {
          Encoding.GetBytes(s, 0, s.Length, _largeByteBuffer, 0);
          _writer.Write(_largeByteBuffer, 0, byteCount);
        }
        else
        {
          int charCount;
          int totalCharsWritten = 0;
          for (int i = s.Length; i > 0; i -= charCount)
          {
            charCount = (i > _maxChars) ? _maxChars : i;
            int count = Encoding.GetBytes(s, totalCharsWritten, charCount, _largeByteBuffer, 0);
            _writer.Write(_largeByteBuffer, 0, count);
            totalCharsWritten += charCount;
          }
        }
      }

      _writer.Write((byte)0);
    }