public int Unmarshal(byte[] b, int n) { this.Byte = (byte)b[n++]; this.Int = Gobuf.ReadVarint(b, ref n); this.Uint = Gobuf.ReadUvarint(b, ref n); this.Int8 = (sbyte)b[n++]; this.Uint8 = (byte)b[n++]; this.Int16 = (short)Gobuf.ReadUint16(b, ref n); this.Uint16 = (ushort)Gobuf.ReadUint16(b, ref n); this.Int32 = (int)Gobuf.ReadUint32(b, ref n); this.Uint32 = (uint)Gobuf.ReadUint32(b, ref n); this.Int64 = (long)Gobuf.ReadUint64(b, ref n); this.Uint64 = (ulong)Gobuf.ReadUint64(b, ref n); this.Float32 = Gobuf.ReadFloat32(b, ref n); this.Float64 = Gobuf.ReadFloat64(b, ref n); this.String = Gobuf.ReadString(b, ref n); this.Bytes = Gobuf.ReadBytes(b, ref n); this.Bool = b[n++] == 1; return(n); }
public int Unmarshal(byte[] b, int n) { { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.IntMap = new Dictionary <long, long>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; long val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = Gobuf.ReadVarint(b, ref n); this.IntMap.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.UintMap = new Dictionary <long, ulong>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; ulong val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = Gobuf.ReadUvarint(b, ref n); this.UintMap.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Int8Map = new Dictionary <long, sbyte>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; sbyte val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (sbyte)b[n++]; this.Int8Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Uint8Map = new Dictionary <long, byte>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; byte val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (byte)b[n++]; this.Uint8Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Int16Map = new Dictionary <long, short>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; short val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (short)Gobuf.ReadUint16(b, ref n); this.Int16Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Uint16Map = new Dictionary <long, ushort>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; ushort val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (ushort)Gobuf.ReadUint16(b, ref n); this.Uint16Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Int32Map = new Dictionary <long, int>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; int val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (int)Gobuf.ReadUint32(b, ref n); this.Int32Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Uint32Map = new Dictionary <long, uint>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; uint val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (uint)Gobuf.ReadUint32(b, ref n); this.Uint32Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Int64Map = new Dictionary <long, long>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; long val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (long)Gobuf.ReadUint64(b, ref n); this.Int64Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Uint64Map = new Dictionary <long, ulong>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; ulong val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = (ulong)Gobuf.ReadUint64(b, ref n); this.Uint64Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Float32Map = new Dictionary <long, float>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; float val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = Gobuf.ReadFloat32(b, ref n); this.Float32Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.Float64Map = new Dictionary <long, double>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; double val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = Gobuf.ReadFloat64(b, ref n); this.Float64Map.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.StringMap = new Dictionary <long, string>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; string val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = Gobuf.ReadString(b, ref n); this.StringMap.Add(key1, val1); } } { var cap1 = (int)Gobuf.ReadUvarint(b, ref n); this.BoolMap = new Dictionary <long, bool>(cap1); for (var i1 = 0; i1 < cap1; i1++) { long key1; bool val1; key1 = Gobuf.ReadVarint(b, ref n); val1 = b[n++] == 1; this.BoolMap.Add(key1, val1); } } return(n); }
public int Unmarshal(byte[] b, int n) { this.IntArray = new long[1]; for (var i1 = 0; i1 < 1; i1++) { this.IntArray[i1] = Gobuf.ReadVarint(b, ref n); } this.UintArray = new ulong[1]; for (var i1 = 0; i1 < 1; i1++) { this.UintArray[i1] = Gobuf.ReadUvarint(b, ref n); } this.Int8Array = new sbyte[1]; for (var i1 = 0; i1 < 1; i1++) { this.Int8Array[i1] = (sbyte)b[n++]; } this.Uint8Array = Gobuf.ReadBytes(b, ref n); this.Int16Array = new short[1]; for (var i1 = 0; i1 < 1; i1++) { this.Int16Array[i1] = (short)Gobuf.ReadUint16(b, ref n); } this.Uint16Array = new ushort[1]; for (var i1 = 0; i1 < 1; i1++) { this.Uint16Array[i1] = (ushort)Gobuf.ReadUint16(b, ref n); } this.Int32Array = new int[1]; for (var i1 = 0; i1 < 1; i1++) { this.Int32Array[i1] = (int)Gobuf.ReadUint32(b, ref n); } this.Uint32Array = new uint[1]; for (var i1 = 0; i1 < 1; i1++) { this.Uint32Array[i1] = (uint)Gobuf.ReadUint32(b, ref n); } this.Int64Array = new long[1]; for (var i1 = 0; i1 < 1; i1++) { this.Int64Array[i1] = (long)Gobuf.ReadUint64(b, ref n); } this.Uint64Array = new ulong[1]; for (var i1 = 0; i1 < 1; i1++) { this.Uint64Array[i1] = (ulong)Gobuf.ReadUint64(b, ref n); } this.Float32Array = new float[1]; for (var i1 = 0; i1 < 1; i1++) { this.Float32Array[i1] = Gobuf.ReadFloat32(b, ref n); } this.Float64Array = new double[1]; for (var i1 = 0; i1 < 1; i1++) { this.Float64Array[i1] = Gobuf.ReadFloat64(b, ref n); } this.StringArray = new string[1]; for (var i1 = 0; i1 < 1; i1++) { this.StringArray[i1] = Gobuf.ReadString(b, ref n); } this.BoolArray = new bool[1]; for (var i1 = 0; i1 < 1; i1++) { this.BoolArray[i1] = b[n++] == 1; } return(n); }
public int Unmarshal(byte[] b, int n) { { this.IntArray = new List <long>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.IntArray.Capacity; i1++) { long v1; v1 = Gobuf.ReadVarint(b, ref n); this.IntArray.Add(v1); } } { this.UintArray = new List <ulong>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.UintArray.Capacity; i1++) { ulong v1; v1 = Gobuf.ReadUvarint(b, ref n); this.UintArray.Add(v1); } } { this.Int8Array = new List <sbyte>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Int8Array.Capacity; i1++) { sbyte v1; v1 = (sbyte)b[n++]; this.Int8Array.Add(v1); } } this.Uint8Array = Gobuf.ReadBytes(b, ref n); { this.Int16Array = new List <short>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Int16Array.Capacity; i1++) { short v1; v1 = (short)Gobuf.ReadUint16(b, ref n); this.Int16Array.Add(v1); } } { this.Uint16Array = new List <ushort>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Uint16Array.Capacity; i1++) { ushort v1; v1 = (ushort)Gobuf.ReadUint16(b, ref n); this.Uint16Array.Add(v1); } } { this.Int32Array = new List <int>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Int32Array.Capacity; i1++) { int v1; v1 = (int)Gobuf.ReadUint32(b, ref n); this.Int32Array.Add(v1); } } { this.Uint32Array = new List <uint>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Uint32Array.Capacity; i1++) { uint v1; v1 = (uint)Gobuf.ReadUint32(b, ref n); this.Uint32Array.Add(v1); } } { this.Int64Array = new List <long>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Int64Array.Capacity; i1++) { long v1; v1 = (long)Gobuf.ReadUint64(b, ref n); this.Int64Array.Add(v1); } } { this.Uint64Array = new List <ulong>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Uint64Array.Capacity; i1++) { ulong v1; v1 = (ulong)Gobuf.ReadUint64(b, ref n); this.Uint64Array.Add(v1); } } { this.Float32Array = new List <float>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Float32Array.Capacity; i1++) { float v1; v1 = Gobuf.ReadFloat32(b, ref n); this.Float32Array.Add(v1); } } { this.Float64Array = new List <double>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.Float64Array.Capacity; i1++) { double v1; v1 = Gobuf.ReadFloat64(b, ref n); this.Float64Array.Add(v1); } } { this.StringArray = new List <string>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.StringArray.Capacity; i1++) { string v1; v1 = Gobuf.ReadString(b, ref n); this.StringArray.Add(v1); } } { this.BoolArray = new List <bool>((int)Gobuf.ReadUvarint(b, ref n)); for (var i1 = 0; i1 < this.BoolArray.Capacity; i1++) { bool v1; v1 = b[n++] == 1; this.BoolArray.Add(v1); } } return(n); }
public int Unmarshal(byte[] b, int n) { if (b[n++] != 0) { this.IntPtr = Gobuf.ReadVarint(b, ref n); } else { this.IntPtr = null; } if (b[n++] != 0) { this.UintPtr = Gobuf.ReadUvarint(b, ref n); } else { this.UintPtr = null; } if (b[n++] != 0) { this.Int8Ptr = (sbyte)b[n++]; } else { this.Int8Ptr = null; } if (b[n++] != 0) { this.Uint8Ptr = (byte)b[n++]; } else { this.Uint8Ptr = null; } if (b[n++] != 0) { this.Int16Ptr = (short)Gobuf.ReadUint16(b, ref n); } else { this.Int16Ptr = null; } if (b[n++] != 0) { this.Uint16Ptr = (ushort)Gobuf.ReadUint16(b, ref n); } else { this.Uint16Ptr = null; } if (b[n++] != 0) { this.Int32Ptr = (int)Gobuf.ReadUint32(b, ref n); } else { this.Int32Ptr = null; } if (b[n++] != 0) { this.Uint32Ptr = (uint)Gobuf.ReadUint32(b, ref n); } else { this.Uint32Ptr = null; } if (b[n++] != 0) { this.Int64Ptr = (long)Gobuf.ReadUint64(b, ref n); } else { this.Int64Ptr = null; } if (b[n++] != 0) { this.Uint64Ptr = (ulong)Gobuf.ReadUint64(b, ref n); } else { this.Uint64Ptr = null; } if (b[n++] != 0) { this.Float32Ptr = Gobuf.ReadFloat32(b, ref n); } else { this.Float32Ptr = null; } if (b[n++] != 0) { this.Float64Ptr = Gobuf.ReadFloat64(b, ref n); } else { this.Float64Ptr = null; } if (b[n++] != 0) { this.StringPtr = Gobuf.ReadString(b, ref n); } else { this.StringPtr = null; } if (b[n++] != 0) { this.BoolPtr = b[n++] == 1; } else { this.BoolPtr = null; } return(n); }
public void TestCommunication() { var scalar = new Scalar(); scalar.Byte = System.Byte.MaxValue; scalar.Int = System.Int64.MaxValue; scalar.Uint = System.UInt64.MaxValue; scalar.Int8 = System.SByte.MaxValue; scalar.Uint8 = System.Byte.MaxValue; scalar.Int16 = System.Int16.MaxValue; scalar.Uint16 = System.UInt16.MaxValue; scalar.Int32 = System.Int32.MaxValue; scalar.Uint32 = System.UInt32.MaxValue; scalar.Int64 = System.Int64.MaxValue; scalar.Uint64 = System.UInt64.MaxValue; scalar.Float32 = System.Single.MaxValue; scalar.Float64 = System.Double.MaxValue; scalar.String = "test string content"; scalar.Bytes = new byte[] { 1, 2, 3, 4 }; scalar.Bool = true; var msg1 = new Message(); msg1.Scalar = scalar; msg1.ScalarPtr = scalar; msg1.ScalarArray.Add(scalar); msg1.ScalarMap.Add(1, scalar); var body = new byte[msg1.Size()]; var size = msg1.Marshal(body, 0); Assert.Equal(size, body.Length); var head = new byte[4]; int offset = 0; Gobuf.WriteUint32((uint)size, head, ref offset); var conn = new TcpClient(); var task = conn.ConnectAsync("127.0.0.1", 12345); task.Wait(); Assert.True(conn.Connected); var stream = conn.GetStream(); stream.Write(head, 0, 4); stream.Write(body, 0, body.Length); offset = 0; while (offset != 4) { offset += stream.Read(head, offset, 4 - offset); } offset = 0; size = (int)Gobuf.ReadUint32(head, ref offset); Assert.Equal(size, body.Length); offset = 0; while (offset != body.Length) { offset += stream.Read(body, offset, body.Length - offset); } var msg2 = new Message(); size = msg2.Unmarshal(body, 0); Assert.Equal(size, body.Length); check(msg1.Scalar, msg2.Scalar); check(msg1.ScalarPtr, msg2.ScalarPtr); check(msg1.ScalarArray[0], msg2.ScalarArray[0]); check(msg1.ScalarMap[1], msg2.ScalarMap[1]); }