Ejemplo n.º 1
0
            public unsafe static void WriteBytes2(BufferSegment buf, ref int offset, byte[] value)
            {
                ushort len = (ushort)value.Length;

                WriteUShort(buf, ref offset, len);
                //Marshal.Copy(value, 0, (IntPtr)(void*)(buf + offset), len);
                buf.CopyStartFromBytes(offset, value, 0, value.Length);
                offset += len;
            }
Ejemplo n.º 2
0
 public unsafe static void WriteBytes(BufferSegment buf, ref int offset, byte[] value, int dataoffset, int size)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     //Marshal.Copy(value, dataoffset, (IntPtr)(void*)(buf + offset), size);
     buf.CopyStartFromBytes(offset, value, dataoffset, size);
     offset += size;
 }
Ejemplo n.º 3
0
            public unsafe static void WriteBytes4(BufferSegment buf, ref int offset, byte[] value)
            {
                int len = value.Length;

                WriteInt32(buf, ref offset, len);
                //for (int i = 0; i < value.Length; i++) {
                //    WriteByte(buf, ref offset, value[i]);
                //}
                //Marshal.Copy(value, 0, (IntPtr)(void*)(buf + offset), len);
                buf.CopyStartFromBytes(offset, value, 0, value.Length);
                offset += len;
            }
Ejemplo n.º 4
0
            public unsafe static void WriteString(BufferSegment buf, ref int offset, string value, Encoding encoding)
            {
                if (string.IsNullOrEmpty(value))
                {
                    throw new ArgumentNullException("value");

                    return;
                }
                //byte len = 0;
                byte[] buf2 = encoding.GetBytes(value);
                buf.CopyStartFromBytes(offset, buf2, 0, buf2.Length);
                offset += buf2.Length;
            }
Ejemplo n.º 5
0
 public unsafe static void WriteBytes(BufferSegment buf, ref int offset, byte[] value, int size)
 {
     if (value == null)
     {
         throw new ArgumentNullException("value");
     }
     if (buf.Offset + size > buf.Length)
     {
         throw new ArgumentOutOfRangeException("value is out len");
     }
     //Marshal.Copy(value, 0, (IntPtr)(void*)(buf + offset), size);
     buf.CopyStartFromBytes(offset, value, 0, size);
     offset += size;
 }
Ejemplo n.º 6
0
            /// <summary>
            ///  把长度1 字节写进了,字符串长度不能超255
            /// </summary>
            /// <param name="buf"></param>
            /// <param name="offset"></param>
            /// <param name="value"></param>
            /// <param name="encoding"></param>
            public unsafe static void WriteString1(BufferSegment buf, ref int offset, string value, Encoding encoding)
            {
                if (string.IsNullOrEmpty(value))
                {
                    //throw new ArgumentNullException("value");
                    WriteByte(buf, ref offset, (byte)0);
                    return;
                }
                byte len   = 0;
                int  start = offset;

                offset += 1;
                //fixed (char* str = value) {
                //    len = (byte)encoding.GetBytes(str, value.Length, buf + offset, 256);
                //}
                byte[] buf2 = encoding.GetBytes(value);
                len = (byte)buf2.Length;
                buf.CopyStartFromBytes(offset, buf2, 0, buf2.Length);
                //ushort len = (ushort)strBuf.Length;
                WriteByte(buf, ref start, len);
                //Marshal.Copy(strBuf, 0, (IntPtr)(void*)(buf + offset), len);
                offset += len;
            }
Ejemplo n.º 7
0
 public static unsafe void WriteBytes4(BufferSegment buf, ref int offset, byte[] value)
 {
     int len = value.Length;
     WriteInt32(buf, ref offset, len);
     //for (int i = 0; i < value.Length; i++) {
     //    WriteByte(buf, ref offset, value[i]);
     //}
     //Marshal.Copy(value, 0, (IntPtr)(void*)(buf + offset), len);
     buf.CopyStartFromBytes(offset, value, 0, value.Length);
     offset += len;
 }
Ejemplo n.º 8
0
 public static unsafe void WriteBytes2(BufferSegment buf, ref int offset, byte[] value)
 {
     ushort len = (ushort)value.Length;
     WriteUShort(buf, ref offset, len);
     //Marshal.Copy(value, 0, (IntPtr)(void*)(buf + offset), len);
     buf.CopyStartFromBytes(offset, value, 0, value.Length);
     offset += len;
 }
Ejemplo n.º 9
0
 public static unsafe void WriteBytes2(BufferSegment buf, ref int offset, byte[] value, int dataoffset, int size)
 {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     WriteUShort(buf, ref offset, (ushort)size);
     //Marshal.Copy(value, dataoffset, (IntPtr)(void*)(buf + offset), size);
     buf.CopyStartFromBytes(offset, value, dataoffset, size);
     offset += size;
 }
Ejemplo n.º 10
0
 public static unsafe void WriteBytes(BufferSegment buf, ref int offset, byte[] value, int size)
 {
     if (value == null) {
         throw new ArgumentNullException("value");
     }
     if (buf.Offset + size > buf.Length) {
         throw new ArgumentOutOfRangeException("value is out len");
     }
     //Marshal.Copy(value, 0, (IntPtr)(void*)(buf + offset), size);
     buf.CopyStartFromBytes(offset, value, 0, size);
     offset += size;
 }
Ejemplo n.º 11
0
            public static unsafe void WriteString2(BufferSegment buf, ref int offset, string value, Encoding encoding)
            {
                if (string.IsNullOrEmpty(value)) {
                    //throw new ArgumentNullException("value");
                    WriteUShort(buf, ref offset, (ushort)0);
                    return;
                }

                ushort len = 0;
                int start = offset;
                offset += 2;
                //fixed (char* str = value) {
                //    len = (ushort)encoding.GetBytes(str, value.Length, buf + offset, 65535);
                //}
                byte[] buf2 = encoding.GetBytes(value);
                len = (ushort)buf2.Length;
                buf.CopyStartFromBytes(offset, buf2, 0, buf2.Length);
                //ushort len = (ushort)strBuf.Length;
                WriteUShort(buf, ref start, len);
                //Marshal.Copy(strBuf, 0, (IntPtr)(void*)(buf + offset), len);
                offset += len;
            }
Ejemplo n.º 12
0
            public static unsafe void WriteString(BufferSegment buf, ref int offset, string value, Encoding encoding)
            {
                if (string.IsNullOrEmpty(value)) {
                    throw new ArgumentNullException("value");

                    return;
                }
                //byte len = 0;
                byte[] buf2 = encoding.GetBytes(value);
                buf.CopyStartFromBytes(offset, buf2, 0, buf2.Length);
                offset += buf2.Length;
            }