Beispiel #1
0
        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);
        }
Beispiel #2
0
        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);
        }
Beispiel #3
0
        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);
        }