public void ShouldSerializeTimeSpan( [Values(1, 10, 100, 10000)] int numberOfEntries) { var randomDateTimes = Helpers.GetRandomDateTimes(numberOfEntries); var stream = new MemoryStream(); using(var writer = new PrimitiveWriter(stream)) { for(var i = 0; i < randomDateTimes.Length; i++) { writer.Write(randomDateTimes[i]); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { for(var i = 0; i < randomDateTimes.Length; i++) { Assert.AreEqual(randomDateTimes[i], reader.ReadDateTime()); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public void ShouldWriteAndReadLongs( [Values(1, 10, 100, 10000, 1000*1000)] int numberOfLongs) { var randomLongs = Helpers.GetRandomLongs(numberOfLongs); var stream = new MemoryStream(); using(var writer = new PrimitiveWriter(stream, buffered)) { for(var i = 0; i < randomLongs.Length; i++) { writer.Write(randomLongs[i]); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream, buffered)) { for(var i = 0; i < randomLongs.Length; i++) { var read = reader.ReadInt64(); Assert.AreEqual(randomLongs[i], read); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public void ShouldReadAndWriteLimits() { var stream = new MemoryStream(); using(var writer = new PrimitiveWriter(stream)) { writer.Write(byte.MinValue); writer.Write(byte.MaxValue); writer.Write(sbyte.MinValue); writer.Write(sbyte.MaxValue); writer.Write(short.MinValue); writer.Write(short.MaxValue); writer.Write(ushort.MinValue); writer.Write(ushort.MaxValue); writer.Write(int.MinValue); writer.Write(int.MaxValue); writer.Write(uint.MinValue); writer.Write(uint.MaxValue); writer.Write(long.MinValue); writer.Write(long.MaxValue); writer.Write(ulong.MinValue); writer.Write(ulong.MaxValue); } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { Assert.AreEqual(byte.MinValue, reader.ReadByte()); Assert.AreEqual(byte.MaxValue, reader.ReadByte()); Assert.AreEqual(sbyte.MinValue, reader.ReadSByte()); Assert.AreEqual(sbyte.MaxValue, reader.ReadSByte()); Assert.AreEqual(short.MinValue, reader.ReadInt16()); Assert.AreEqual(short.MaxValue, reader.ReadInt16()); Assert.AreEqual(ushort.MinValue, reader.ReadUInt16()); Assert.AreEqual(ushort.MaxValue, reader.ReadUInt16()); Assert.AreEqual(int.MinValue, reader.ReadInt32()); Assert.AreEqual(int.MaxValue, reader.ReadInt32()); Assert.AreEqual(uint.MinValue, reader.ReadUInt32()); Assert.AreEqual(uint.MaxValue, reader.ReadUInt32()); Assert.AreEqual(long.MinValue, reader.ReadInt64()); Assert.AreEqual(long.MaxValue, reader.ReadInt64()); Assert.AreEqual(ulong.MinValue, reader.ReadUInt64()); Assert.AreEqual(ulong.MaxValue, reader.ReadUInt64()); } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public void ShouldHandleNotAlignedWrites() { const int iterationCount = 80000; var stream = new MemoryStream(); using(var writer = new PrimitiveWriter(stream)) { writer.Write((byte)1); for(var i = 0; i < iterationCount; i++) { writer.Write(int.MaxValue); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { Assert.AreEqual((byte)1, reader.ReadByte()); for(var i = 0; i < iterationCount; i++) { Assert.AreEqual(int.MaxValue, reader.ReadInt32()); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public void ShouldWriteAndReadStrings( [Values(1, 100, 10000)] int numberOfStrings, [Values(true, false)] bool withLongStrings) { const int maxLength = 100; const int longStringLength = 8000; const int longStringProbability = 10; var random = Helpers.Random; var strings = new string[numberOfStrings]; for(var i = 0; i < strings.Length; i++) { int length; if(withLongStrings && random.Next()%longStringProbability == 0) { length = longStringLength; } else { length = random.Next(maxLength); } strings[i] = Helpers.GetRandomString(length); } var stream = new MemoryStream(); using(var writer = new PrimitiveWriter(stream)) { for(var i = 0; i < strings.Length; i++) { writer.Write(strings[i]); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { for(var i = 0; i < strings.Length; i++) { Assert.AreEqual(strings[i], reader.ReadString()); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
protected virtual void WriteUpdateFlag_0x8(PrimitiveWriter writer, UpdateFieldFlags relation) { writer.Write(this.EntityId.LowRaw); }
public void ShouldWriteAndReadByteArray( [Values(10, 1000, 100000)] int count ) { var stream = new MemoryStream(); byte[] array; using(var writer = new PrimitiveWriter(stream)) { array = new byte[count]; Helpers.Random.NextBytes(array); writer.Write(array); } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); byte[] copy; using(var reader = new PrimitiveReader(stream)) { copy = reader.ReadBytes(count); } CollectionAssert.AreEqual(array, copy); Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public void ShouldWriteAndReadNegativeInt() { var value = -Helpers.Random.Next(); var stream = new MemoryStream(); using(var writer = new PrimitiveWriter(stream)) { writer.Write(value); } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { Assert.AreEqual(value, reader.ReadInt32()); } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public TypeStamper(PrimitiveWriter writer) { this.writer = writer; alreadyWritten = new HashSet <Type>(); }
public override void Write(PrimitiveWriter writer) { writer.WriteInt(EntityId); writer.WriteByte(Status); }
public override void Write(PrimitiveWriter writer) { writer.WriteLong(Payload); }
protected override void WriteUpdateFlag_0x10(PrimitiveWriter writer, UpdateFieldFlags relation) { writer.Write(150754760); // TODO - wtf? //base.WriteUpdateFlag_0x10(writer, relation); }
public override void Write(PrimitiveWriter writer) { writer.WriteByte((byte)Position); writer.WriteStringProto(ScoreName); }
protected override void WriteMovementUpdate(PrimitiveWriter writer, UpdateFieldFlags relation) { writer.Write(this.Position); writer.WriteFloat(this.Orientation); }
public override void Write(PrimitiveWriter writer) { writer.WriteBlockPosProto(Position); }
public abstract void Write(PrimitiveWriter writer);
public override void Write(PrimitiveWriter writer) => writer.WriteSByte(Value);
protected override void WriteMovementUpdate(PrimitiveWriter writer, UpdateFieldFlags relation) { // UpdateFlag.StationaryObject writer.Write(Position); writer.WriteFloat(Orientation); }
/// <summary> /// Writes the data shared in movement packets and the create block of the update packet /// This is used in /// <list type="String"> /// SMSG_UPDATE_OBJECT /// MSG_MOVE_* /// MSG_MOVE_SET_*_SPEED /// </list> /// </summary> /// <param name="packet"></param> public void WriteMovementPacketInfo(PrimitiveWriter packet) { WriteMovementPacketInfo(packet, ref m_position, m_orientation); }
public override void Write(PrimitiveWriter writer) { writer.WriteStringProto(Uuid.ToString()); writer.WriteStringProto(Username); }
protected virtual void WriteUpdateFlag_0x10(PrimitiveWriter writer, UpdateFieldFlags relation) { writer.Write(1); }
public TypeStamper(PrimitiveWriter writer, bool treatCollectionAsUserObject) { this.writer = writer; this.treatCollectionAsUserObject = treatCollectionAsUserObject; alreadyWritten = new HashSet <Type>(); }
protected virtual void WriteTypeSpecificMovementUpdate(PrimitiveWriter writer, UpdateFieldFlags relation, UpdateFlags updateFlags) { }
public void ShouldCopyFromStream() { var stream = new MemoryStream(); var testArray = Enumerable.Range(0, 1000).Select(x => (byte)x).ToArray(); var testStream = new MemoryStream(testArray); using(var writer = new PrimitiveWriter(stream, buffered)) { writer.CopyFrom(testStream, testArray.Length); } stream.Seek(0, SeekOrigin.Begin); var secondStream = new MemoryStream(testArray.Length); using(var reader = new PrimitiveReader(stream, buffered)) { reader.CopyTo(secondStream, testArray.Length); } CollectionAssert.AreEqual(testArray, secondStream.ToArray()); }
/// <summary> /// Writes the major portion of the create block. /// This handles flags 0x20, 0x40, and 0x100, they are exclusive to each other /// The content depends on the object's type /// </summary> /// <param name="writer"></param> /// <param name="relation"></param> protected virtual void WriteMovementUpdate(PrimitiveWriter writer, UpdateFieldFlags relation) { }
public override void Write(PrimitiveWriter writer) { writer.WriteVarint(KeepAliveId); }
/// <summary>Writes the server's proof.</summary> /// <param name="packet">the packet to write to</param> public void WriteServerProof(PrimitiveWriter packet) { packet.WriteBigInt(this.m_srp.ServerSessionKeyProof, 20); }
public virtual void Save(PrimitiveWriter writer) { }
public override void Write(PrimitiveWriter writer) { writer.WriteVarint(EntityId); }
public async ValueTask Write(PrimitiveWriter primitiveWriter, CancellationToken cancellationToken) { await primitiveWriter.Write(Identity, cancellationToken); await primitiveWriter.Write(true, cancellationToken); }
public override void Write(PrimitiveWriter writer) { writer.WriteChatRootProto(Reason); }
public void ShouldWriteAndReadGuid( [Values(10, 1000, 100000)] int count ) { var stream = new MemoryStream(); var array = new Guid[count]; using(var writer = new PrimitiveWriter(stream)) { for(var i = 0; i < count; i++) { var guid = Guid.NewGuid(); array[i] = guid; writer.Write(guid); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { for(var i = 0; i < count; i++) { Assert.AreEqual(array[i], reader.ReadGuid()); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
protected override void WriteTypeSpecificMovementUpdate(PrimitiveWriter writer, UpdateFieldFlags relation, UpdateFlags updateFlags) { base.WriteTypeSpecificMovementUpdate(writer, relation, updateFlags); writer.Write(m_entry.VehicleId); writer.Write(m_entry.VehicleAimAdjustment); }
public void ShouldWriteAndReadPartsOfByteArrays() { var arrays = new byte[100][]; for(var i = 0; i < arrays.Length; i++) { arrays[i] = Enumerable.Range(0, 256).Select(x => (byte)x).ToArray(); } var stream = new MemoryStream(); using(var writer = new PrimitiveWriter(stream)) { for(var i = 0; i < arrays.Length; i++) { writer.Write(arrays[i], i, arrays[i].Length - i); } } var position = stream.Position; stream.Seek(0, SeekOrigin.Begin); using(var reader = new PrimitiveReader(stream)) { for(var i = 0; i < arrays.Length; i++) { var writtenLength = arrays[i].Length - i; var writtenArray = reader.ReadBytes(writtenLength); var subarray = new byte[writtenLength]; Array.Copy(arrays[i], i, subarray, 0, writtenLength); CollectionAssert.AreEqual(subarray, writtenArray); } } Assert.AreEqual(position, stream.Position, StreamCorruptedMessage); }
public override void Write(PrimitiveWriter writer) { // TODO: will do later. }
public override void Write(PrimitiveWriter writer) { writer.WriteBlockPosProto(Location); writer.WriteByte(Action); writer.WriteNbtBlob(NbtData); }
public override void Write(PrimitiveWriter writer) { writer.WriteVarint(EntityId); writer.WriteBlockPosProto(Location); }
protected override void WriteUpdateFlag_0x10(PrimitiveWriter writer, UpdateFieldFlags relation) { writer.Write(150754760); }
public override void Write(PrimitiveWriter writer) { writer.WriteChatRootProto(ChatRoot); writer.WriteByte((byte)Position); }
public override void Write(PrimitiveWriter writer) { writer.WriteBlockPosProto(Location); writer.WriteVarint(BlockStateId.ToShort()); }
public TypeStamper(PrimitiveWriter writer) { this.writer = writer; alreadyWritten = new HashSet<Type>(); }