public void WriteString16(String text)
{
if(text != null)
{
if(text.Length > ushort.MaxValue)
{
throw new IOException(
String.Format(
"Cannot marshall string longer than: {0} characters, supplied string was: " +
"{1} characters", ushort.MaxValue, text.Length));
}
char[] charr = text.ToCharArray();
uint utfLength = CountUtf8Bytes(charr);
if(utfLength > ushort.MaxValue)
{
throw new IOException(
String.Format(
"Cannot marshall an encoded string longer than: {0} bytes, supplied" +
"string requires: {1} characters to encode", ushort.MaxValue, utfLength));
}
byte[] bytearr = new byte[utfLength];
encodeUTF8toBuffer(charr, bytearr);
Write((ushort) utfLength);
Write(bytearr);
}
}