public void TestHighScore() { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); HighScoreObject hs1 = new HighScoreObject(); hs1.Name = "Speed Run"; hs1.HighScore = 10000; Stopwatch s = Stopwatch.StartNew(); byte[] bytes = default(byte[]); for (int i = 0; i < 1000000; i++) { bytes = patternBuffer.Energize(hs1); } s.Stop(); Console.WriteLine("Serialize: " + s.ElapsedMilliseconds); HighScoreObject hs2 = null; s = Stopwatch.StartNew(); for (int i = 0; i < 1000000; i++) { hs2 = (HighScoreObject)patternBuffer.Energize(bytes); } s.Stop(); Console.WriteLine("Deserialize: " + s.ElapsedMilliseconds); Console.WriteLine("Size: " + bytes.Length + " bytes"); }
public void TestDoubleObjectSerialization() { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); DoubleObject o1 = new DoubleObject(1.2929348); byte[] bytes = patternBuffer.Energize(o1); Assert.AreEqual(9, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is DoubleObject); Assert.AreEqual(o1.DoubleValue, ((DoubleObject)o).DoubleValue); Assert.IsFalse(o1 == o); }
public void TestByteObjectSerialization() { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); ByteObject b = new ByteObject(37); byte[] bytes = patternBuffer.Energize(b); Assert.AreEqual(2, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is ByteObject); Assert.AreEqual(b.ByteValue, ((ByteObject)o).ByteValue); Assert.IsFalse(b == o); }
public void TestVUShortObjectSerialization(ushort value, int byteCount) { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); VUShortObject u = new VUShortObject(value); byte[] bytes = patternBuffer.Energize(u); Assert.AreEqual(byteCount, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is VUShortObject); Assert.AreEqual(u.VushortValue, ((VUShortObject)o).VushortValue); Assert.IsFalse(u == o); }
public void TestULongObjectSerialization(ulong value, int byteCount) { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); ULongObject u = new ULongObject(value); byte[] bytes = patternBuffer.Energize(u); Assert.AreEqual(byteCount, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is ULongObject); Assert.AreEqual(u.UlongValue, ((ULongObject)o).UlongValue); Assert.IsFalse(u == o); }
public void TestStringObjectSerialization() { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); StringObject stringObject = new StringObject("foobar"); byte[] bytes = patternBuffer.Energize(stringObject); Assert.AreEqual(8, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is StringObject); Assert.AreEqual(stringObject.StringValue, ((StringObject)o).StringValue); Assert.IsFalse(stringObject == o); }
public void TestShortObjectSerialization(short value, int byteCount) { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); ShortObject s = new ShortObject(value); byte[] bytes = patternBuffer.Energize(s); Assert.AreEqual(byteCount, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is ShortObject); Assert.AreEqual(s.ShortValue, ((ShortObject)o).ShortValue); Assert.IsFalse(s == o); }
public void TestVLongObjectSerialization(long value, int byteCount) { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); VLongObject l1 = new VLongObject(value); byte[] bytes = patternBuffer.Energize(l1); Assert.AreEqual(byteCount, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is VLongObject); Assert.AreEqual(l1.VlongValue, ((VLongObject)o).VlongValue); Assert.IsFalse(l1 == o); }
public void TestIntObjectSerialization(int value, int byteCount) { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); IntObject intObject = new IntObject(12345); byte[] bytes = patternBuffer.Energize(intObject); Assert.AreEqual(6, bytes.Length); object o = patternBuffer.Energize(bytes); Assert.IsTrue(o is IntObject); Assert.AreEqual(intObject.IntValue, ((IntObject)o).IntValue); Assert.IsFalse(intObject == o); }
public void TestEverythingObjectSerialization() { PrimitiveTestPatternBuffer patternBuffer = new PrimitiveTestPatternBuffer(); EverythingObject e1 = new EverythingObject(); e1.StringValue = "foo"; Stopwatch s = Stopwatch.StartNew(); byte[] bytes; for (int i = 0; i < 10000000; i++) { bytes = patternBuffer.Energize(e1); } s.Stop(); Console.WriteLine(s.ElapsedMilliseconds); }