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 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(); owner = reader.ReadInt32(); int networkedObjectDataLen = reader.ReadInt32(); networkedObjectData = new byte[networkedObjectDataLen]; reader.Read(networkedObjectData, 0, networkedObjectDataLen); prefabName = reader.ReadString(); spawnType = (SpawnType)reader.ReadInt32(); }
public unsafe void StringsNullable() { var s = new ReusableStream(40); var expectedLength = 0; const string emptyString = ""; s.WriteString(null, true); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.WriteString(null, 0, 0, true); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.WriteString(null, 0, true); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.WriteString(emptyString, true); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.WriteString(Array.Empty <char>(), 0, 0, true); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); fixed(char *ptr = emptyString) s.WriteString(ptr, 0, true); expectedLength += 2; Assert.AreEqual(expectedLength, s.Length); s.ResetForReading(); Assert.AreEqual(null, s.ReadString(true)); Assert.AreEqual(null, s.ReadString(true)); Assert.AreEqual(null, s.ReadString(true)); Assert.AreEqual(emptyString, s.ReadString(true)); Assert.AreEqual(emptyString, s.ReadString(true)); Assert.AreEqual(emptyString, s.ReadString(true)); Assert.Throws <ArgumentNullException>(() => s.WriteString(null, false)); Assert.Throws <ArgumentNullException>(() => s.WriteString(null, 0, 0, false)); Assert.Throws <ArgumentNullException>(() => s.WriteString(null, 0, false)); }
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 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 void StringInterning() { var s = new ReusableStream(100); var strings = new[] { "cat", "deer", "snail", "dog", "frog", "human" }; const int max = 4; const string exclude = "frog"; foreach (var str in strings) { s.WriteString(str, false); } s.ResetForReading(); // we're not interning yet - make sure new strings were returned foreach (var str in strings) { var read = s.ReadString(false); Assert.AreEqual(str, read); Assert.AreNotSame(str, read); } s.ResetForReading(); var options = new StringSetOptions(); options.MaxEncodedSizeToLookupInSet = max; Assert.Throws <InvalidOperationException>(() => s.SetDefaultStringSetOptions(options)); var set = new StringSet(10); s.StringSet = set; s.SetDefaultStringSetOptions(options); s.StringSet = null; // should throw because no StringSet has been provided Assert.Throws <InvalidOperationException>(() => s.ReadString(false)); foreach (var str in strings) { if (str != exclude) { set.Add(str); } } s.StringSet = set; // read with interning (but no auto-interning) foreach (var str in strings) { var read = s.ReadString(false); Assert.AreEqual(str, read); if (str.Length <= max && str != exclude) { Assert.AreSame(str, read); } else { Assert.AreNotSame(str, read); } } // make sure the excluded string didn't get added to the set Assert.AreEqual(null, set.GetExistingString(exclude.ToCharArray(), 0, exclude.Length)); s.ResetForReading(); options.PerformDangerousAutoAddToSet = true; s.SetDefaultStringSetOptions(options); // read with auto-interning foreach (var str in strings) { var read = s.ReadString(false); Assert.AreEqual(str, read); if (str.Length <= max && str != exclude) { Assert.AreSame(str, read); } else { Assert.AreNotSame(str, read); } } // make sure the excluded string got added to the set Assert.AreEqual(exclude, set.GetExistingString(exclude.ToCharArray(), 0, exclude.Length)); }
public unsafe void Strings() { // not including ASCII since it won't round-trip for the unicode strings var encodings = new[] { Encoding.UTF7, Encoding.UTF8, Encoding.Unicode, Encoding.BigEndianUnicode, Encoding.UTF32, }; var strings = new[] { "", "a", "cat", @"Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nunc odio ligula, pharetra eget eros et, blandit luctus justo. Fusce ultricies id tortor sit amet laoreet. Cras posuere tellus vel aliquam tristique. Duis et quam sit amet sapien ullamcorper blandit a sed dolor. Duis placerat nisl ac egestas suscipit. Sed lacus tellus, convallis placerat sodales vitae, tempor et urna. Duis ut leo dictum, tempus ante ut, lacinia nisi. Nunc consectetur orci nisl, vitae fringilla justo vestibulum vitae. Proin orci velit, iaculis ut ornare quis, rhoncus in lectus. Donec volutpat convallis faucibus. Donec finibus erat sit amet tortor rhoncus suscipit. Quisque facilisis lacus risus, sit amet pretium ipsum ornare et. Donec nec elementum dui. Nunc volutpat commodo metus ac tincidunt. Aenean eget lectus lacus. Donec mauris libero, accumsan id ex a, mollis rutrum lacus. Praesent mollis pretium ipsum eu faucibus. Fusce posuere congue libero, ut aliquam nulla dapibus vitae. Etiam sit amet convallis justo, sit amet hendrerit diam. Suspendisse eleifend vitae quam ac tempor. Sed fringilla tempus enim in fringilla. Fusce at leo metus. Vestibulum sollicitudin tempus odio, non posuere leo congue lobortis. Maecenas aliquam diam eget urna finibus, vitae egestas ipsum ultrices. Sed risus enim, tempor eget tortor non, malesuada auctor nulla. Aliquam egestas posuere erat, quis interdum elit efficitur sed. Suspendisse malesuada, ipsum id iaculis semper, nunc tortor congue nulla, non auctor est magna vitae ligula. Nulla sit amet orci nisl. Nulla non bibendum felis, id tempor tortor. Nam neque neque, tempus quis semper id, porttitor vitae tortor. Nulla sit amet leo eros. Orci varius natoque penatibus et magnis dis parturient montes, nascetur ridiculus mus. Fusce varius ipsum non risus lobortis, et pretium elit malesuada. Sed luctus fermentum orci, et rutrum lacus faucibus in. Integer sodales leo aliquet mattis tristique. Nam consequat ornare lorem eget fermentum. Vestibulum a lectus sit amet nibh egestas fermentum sit amet at est. Suspendisse quis dapibus metus, sed imperdiet felis. Nulla nec consequat elit. Pellentesque pretium erat ornare felis semper tincidunt. Nullam nec magna lectus. Donec feugiat ligula urna, eget sodales ipsum fermentum sed. Morbi nec metus sit amet neque finibus hendrerit in quis ligula. Morbi lectus nulla, porta sed eros commodo, aliquam scelerisque felis. Proin fringilla pellentesque odio. Sed finibus in dolor non laoreet. Mauris in magna eget ex faucibus varius sed nec arcu. Sed tincidunt ut nulla sit amet rutrum. Mauris at neque neque. Nulla vel urna rhoncus, ultricies quam aliquet, congue nunc. Sed lectus dolor, placerat at tempor at, lacinia non ipsum. Maecenas commodo, lectus eget blandit laoreet, massa nunc egestas leo, non iaculis felis felis at lorem. Ut ut sagittis arcu, et sollicitudin nisi. Aliquam auctor porta rhoncus. Ut est enim, dictum at sollicitudin vitae, feugiat sed urna. Pellentesque pretium mi id nunc commodo, id efficitur metus vulputate. Donec rhoncus, lectus sed tincidunt accumsan, metus odio vehicula lectus, vitae tristique tellus ex id enim.", "っつ雲日御へ保瀬とれろなほニミャメ", "𐐷", "END" }; foreach (var encoding in encodings) { // try writing strings var s = new ReusableStream(10000); s.DefaultEncoding = encoding; foreach (var t in strings) { s.WriteString(t, false); } s.ResetForReading(); foreach (var t in strings) { var str = s.ReadString(false); Assert.AreEqual(t, str); } // try writing char[] s = new ReusableStream(10000); s.DefaultEncoding = encoding; foreach (var t in strings) { s.WriteString(t.ToCharArray(), 0, t.Length, false); } s.ResetForReading(); foreach (var t in strings) { var str = s.ReadString(false); Assert.AreEqual(t, str); } // try writing char* s = new ReusableStream(10000); s.DefaultEncoding = encoding; foreach (var t in strings) { fixed(char *ptr = t) { s.WriteString(ptr, t.Length, false); } } s.ResetForReading(); foreach (var t in strings) { var str = s.ReadString(false); Assert.AreEqual(t, str); } } }