private void WriteStringValue(string value) { bool twoByteString = this.StringRequires16BitSupport(value); if (twoByteString) { this.Stream.WriteByte(1); // Write 16 bit flag ProperBitConverter.GetBytes(this.buffer, 0, value.Length); this.Stream.Write(this.buffer, 0, 4); using (var tempBuffer = Buffer <byte> .Claim(value.Length * 2)) { var array = tempBuffer.Array; UnsafeUtilities.StringToBytes(array, value, true); this.Stream.Write(array, 0, value.Length * 2); } } else { this.Stream.WriteByte(0); // Write 8 bit flag ProperBitConverter.GetBytes(this.buffer, 0, value.Length); this.Stream.Write(this.buffer, 0, 4); using (var tempBuffer = Buffer <byte> .Claim(value.Length)) { var array = tempBuffer.Array; for (int i = 0; i < value.Length; i++) { array[i] = (byte)value[i]; } this.Stream.Write(array, 0, value.Length); } } }