public static unsafe IntPtr ToCStringUtf8(string str, ByteBuffer byteBuffer) { var utf8 = System.Text.Encoding.UTF8; var byteCount = utf8.GetByteCount(str); var byteArray = byteBuffer.Allocate(byteCount + 1); fixed(char *chars = str) { utf8.GetBytes(chars, str.Length, (byte *)byteArray.Pointer, byteCount); } return(byteArray.Pointer); }
private static unsafe IntPtr ToCString(string str, ByteBuffer byteBuffer) { var ascii = System.Text.Encoding.ASCII; var byteCount = ascii.GetByteCount(str); var byteArray = byteBuffer.Allocate(byteCount + 1); fixed(char *chars = str) { ascii.GetBytes(chars, str.Length, (byte *)byteArray.Pointer, byteCount); } return(byteArray.Pointer); }
private static unsafe ByteArray FromString(string str, ByteBuffer byteBuffer) { var utf8 = System.Text.Encoding.UTF8; var byteCount = utf8.GetByteCount(str); var byteArray = byteBuffer.Allocate(byteCount); fixed(char *chars = str) { utf8.GetBytes(chars, str.Length, (byte *)byteArray.Pointer, byteCount); } return(byteArray); }