private static void CheckUtf8Bytes(string charSequence) { var buf = Unpooled.Buffer(ByteBufferUtil.Utf8MaxBytes(charSequence)); try { int writtenBytes = ByteBufferUtil.WriteUtf8(buf, charSequence); int utf8Bytes = ByteBufferUtil.Utf8Bytes(charSequence); Assert.Equal(writtenBytes, utf8Bytes); } finally { buf.Release(); } }
public void WriteUtf8InvalidEndOnTrailingSurrogate() { string surrogateString = new StringBuilder(2) .Append('\uDC00') .ToString(); var buf = Unpooled.Buffer(16); buf.WriteBytes(TextEncodings.UTF8NoBOM.GetBytes(surrogateString)); var buf2 = Unpooled.Buffer(16); ByteBufferUtil.WriteUtf8(buf2, surrogateString); Assert.Equal(buf, buf2); Assert.Equal(buf.ReadableBytes, ByteBufferUtil.Utf8Bytes(surrogateString)); buf.Release(); buf2.Release(); }