public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); messageNum = reader.ReadUInt64(); force = reader.ReadBoolean(); int numOfItems = reader.ReadInt32(); for (int i = 0; i < numOfItems; ++i) { ulong key = reader.ReadUInt64(); int valueLen = reader.ReadInt32(); byte[] objData = new byte[valueLen]; reader.Read(objData, 0, valueLen); networkData.Data.Add(key, objData); } }
public static T Deserialize <T>(byte[] data, int len) where T : IMessage, new() { if (readStream == null) { readStream = new ReusableStream(); } readStream.ReplaceData(data, 0, len, false); if (MessageTypes.TryGetValue(typeof(T), out ISerialized sBase)) { return(sBase.Deserialize <T>(readStream)); } else if (typeof(T).GetInterfaces().Contains(typeof(ISerialized))) { sBase = (ISerialized) new T(); MessageTypes[typeof(T)] = sBase; return(sBase.Deserialize <T>(readStream)); } ushort channel = readStream.ReadUInt16(); ushort part = readStream.ReadUInt16(); ushort totalParts = readStream.ReadUInt16(); int length = readStream.ReadInt32(); ushort id = readStream.ReadUInt16(); bool isAsync = readStream.ReadBoolean(); T Mes; try { Mes = JsonUtility.FromJson <T>(readStream.ReadString()); Mes.Channel = channel; Mes.Part = part; Mes.TotalParts = totalParts; Mes.Length = length; Mes.ID = id; Mes.IsAsync = isAsync; } catch { Mes = new T { Channel = channel, Part = part, TotalParts = totalParts, Length = length, ID = id, IsAsync = isAsync }; } return(Mes); }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); owner = reader.ReadInt32(); }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); Accepted = reader.ReadBoolean(); PlayerID = reader.ReadInt32(); playerName = reader.ReadString(); }
public void SetLength() { var s = new ReusableStream(16); Assert.AreEqual(0, s.Length); Assert.AreEqual(0, s.UnreadByteCount); Assert.AreEqual(16, s.Capacity); s.SetLength(4); Assert.AreEqual(4, s.Length); Assert.AreEqual(4, s.UnreadByteCount); Assert.AreEqual(16, s.Capacity); s.ReadInt32(); Assert.AreEqual(4, s.Length); Assert.AreEqual(0, s.UnreadByteCount); Assert.AreEqual(16, s.Capacity); s.SetLength(16); Assert.AreEqual(16, s.Length); Assert.AreEqual(12, s.UnreadByteCount); Assert.AreEqual(16, s.Capacity); s.SetLength(17); Assert.AreEqual(17, s.Length); Assert.AreEqual(13, s.UnreadByteCount); Assert.IsTrue(s.Capacity >= 17); s.SetLength(0); Assert.AreEqual(0, s.Length); Assert.AreEqual(0, s.UnreadByteCount); Assert.IsTrue(s.Capacity >= 17); Assert.Throws <ArgumentOutOfRangeException>(() => s.SetLength(-1)); }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); playerRequested = reader.ReadInt32(); playerToOwn = reader.ReadInt32(); prefabName = reader.ReadString(); spawnType = (SpawnType)reader.ReadInt32(); perminant = reader.ReadBoolean(); }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); step = (Step)reader.ReadByte(); int l = reader.ReadInt32(); Data = new byte[l]; reader.Read(Data, 0, l); }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); int num = reader.ReadInt32(); networkIDs = new List <ulong>(num); for (int i = 0; i < num; ++i) { networkIDs.Add(reader.ReadUInt64()); } }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); owner = reader.ReadInt32(); int networkedObjectDataLen = reader.ReadInt32(); networkedObjectData = new byte[networkedObjectDataLen]; reader.Read(networkedObjectData, 0, networkedObjectDataLen); prefabName = reader.ReadString(); spawnType = (SpawnType)reader.ReadInt32(); }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); int mappingLen = reader.ReadInt32(); playerInfo = new Dictionary <int, PlayerInformation>(mappingLen); for (int i = 0; i < mappingLen; ++i) { playerInfo.Add(reader.ReadInt32(), new PlayerInformation() { PlayerID = reader.ReadInt32(), PlayerName = reader.ReadString(), PlayerPing = reader.ReadSingle(), }); } }
public void Deserialize(byte[] data, int len) { ReusableStream reader = new ReusableStream(data, 0, len, false); Channel = reader.ReadUInt16(); Part = reader.ReadUInt16(); TotalParts = reader.ReadUInt16(); Length = reader.ReadInt32(); ID = reader.ReadUInt16(); IsAsync = reader.ReadBoolean(); sceneName = reader.ReadString(); int mappingLen = reader.ReadInt32(); sceneMapping = new Dictionary <ulong, byte[]>(mappingLen); for (int i = 0; i < mappingLen; ++i) { ulong key = reader.ReadUInt64(); int l = reader.ReadInt32(); byte[] buffer = new byte[l]; reader.Read(buffer, 0, l); sceneMapping.Add(key, buffer); } }
public unsafe void ReadPastEnd() { var s = new ReusableStream(16); s.Write((ulong)3); var buffer = new byte[16]; fixed(byte *p = buffer) { var bufferPtr = p; Assert.AreEqual(-1, s.ReadByte()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadBoolean()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt8()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt8()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt16()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt16()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt32()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt32()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadInt64()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadUInt64()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadSingle()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadDouble()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadDateTime()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadGuid()); Assert.Throws <IndexOutOfRangeException>(() => s.ReadString(true)); Assert.AreEqual(0, s.Read(buffer, 0, 1)); Assert.AreEqual(0, s.Read(bufferPtr, 1)); s.ResetForReading(); Assert.AreEqual(8, s.Read(buffer, 0, 9)); s.ResetForReading(); Assert.AreEqual(8, s.Read(bufferPtr, 9)); } }
public void ReadWritePrimitives() { var s = new ReusableStream(100); var rng = new Random(); var b = (byte)rng.Next(255); var sb = (sbyte)rng.Next(255); var sh = (short)rng.Next(short.MinValue, short.MaxValue); var ush = (ushort)rng.Next(ushort.MaxValue); var i = rng.Next(int.MinValue, int.MaxValue); var ui = (uint)rng.Next(int.MinValue, int.MaxValue); var l = (long)RandomULong(rng); var ul = RandomULong(rng); var f = (float)rng.NextDouble(); var d = rng.NextDouble(); var c = (char)rng.Next(char.MinValue, char.MaxValue); var t = DateTime.UtcNow; var g = Guid.NewGuid(); var expectedLength = 0; s.Write(b); expectedLength += 1; Assert.AreEqual(expectedLength, s.Length); s.Write(sb); expectedLength += 1; Assert.AreEqual(expectedLength, s.Length); s.Write(sh); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.Write(ush); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.Write(i); expectedLength += 4; Assert.AreEqual(expectedLength, s.Length); s.Write(ui); expectedLength += 4; Assert.AreEqual(expectedLength, s.Length); s.Write(l); expectedLength += 8; Assert.AreEqual(expectedLength, s.Length); s.Write(ul); expectedLength += 8; Assert.AreEqual(expectedLength, s.Length); s.Write(f); expectedLength += 4; Assert.AreEqual(expectedLength, s.Length); s.Write(d); expectedLength += 8; Assert.AreEqual(expectedLength, s.Length); s.Write(c); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.Write(false); expectedLength += 1; Assert.AreEqual(expectedLength, s.Length); s.Write(true); expectedLength += 1; Assert.AreEqual(expectedLength, s.Length); s.Write(t); expectedLength += 8; Assert.AreEqual(expectedLength, s.Length); s.Write(g); expectedLength += 16; Assert.AreEqual(expectedLength, s.Length); s.ResetForReading(); Assert.AreEqual(b, s.ReadUInt8()); Assert.AreEqual(sb, s.ReadInt8()); Assert.AreEqual(sh, s.ReadInt16()); Assert.AreEqual(ush, s.ReadUInt16()); Assert.AreEqual(i, s.ReadInt32()); Assert.AreEqual(ui, s.ReadUInt32()); Assert.AreEqual(l, s.ReadInt64()); Assert.AreEqual(ul, s.ReadUInt64()); Assert.AreEqual(f, s.ReadSingle()); Assert.AreEqual(d, s.ReadDouble()); Assert.AreEqual(c, s.ReadChar()); Assert.AreEqual(false, s.ReadBoolean()); Assert.AreEqual(true, s.ReadBoolean()); Assert.AreEqual(t, s.ReadDateTime()); Assert.AreEqual(g, s.ReadGuid()); // verify that we read to the end Assert.AreEqual(s.Length, s.Position); s.ResetForReading(); Assert.AreEqual((int)b, s.ReadByte()); }