static void EncodeString (byte[] buf, ref int index, short type, string value, bool unicode) { var encoding = unicode ? Encoding.Unicode : Encoding.UTF8; int length = value.Length; if (unicode) length *= 2; EncodeTypeAndLength (buf, ref index, type, (short) length); encoding.GetBytes (value, 0, value.Length, buf, index); index += length; }