Exemplo n.º 1
0
 public void Deserialze(Deserializer serializedData)
 {
     Field1 = serializedData.GetInt32();
     Field2 = serializedData.GetInt32();
     Field3 = serializedData.GetString();
     nts    = new NestedTestSerialzer();
     nts.Deserialze(serializedData);
 }
Exemplo n.º 2
0
        public void Read1NegatveIntAndThenTryToReadAnInvalidIntThrowsException()
        {
            var data = "-0000000005" +
                       "-000000001"; //here is a 0 missing on purpose
            var des = new Deserializer(data);

            Assert.AreEqual(-5, des.GetInt32());
            Assert.Throws <ParserException>(() => { des.GetInt32(); });
        }
Exemplo n.º 3
0
        public void Read2NegativeAnd1PositiveIntFromDataSuccess()
        {
            var data = "-0000000005" +
                       "-0000000001" +
                       "0000000000";
            var des = new Deserializer(data);

            Assert.AreEqual(-5, des.GetInt32());
            Assert.AreEqual(-1, des.GetInt32());
            Assert.AreEqual(0, des.GetInt32());
        }
Exemplo n.º 4
0
        public void GetStringFromDataWithOneStringAndOneIntSucces()
        {
            var originalData = "testHalloHelp";
            var data         = originalData.Length.ToString("D10") + originalData;

            data = 123.ToString("D10") + data + 456.ToString("D10");
            var des = new Deserializer(data);

            Assert.AreEqual(123, des.GetInt32());
            Assert.IsTrue(des.GetString() == originalData);
            Assert.AreEqual(456, des.GetInt32());
        }
Exemplo n.º 5
0
        public void SerialzeAndDeserialze2IntSuccess()
        {
            var originalvalue  = 246799999;
            var originalvalue2 = -598746565;


            ser.AddInt32(originalvalue);
            ser.AddInt32(originalvalue2);
            var serializedData = ser.FinalizeSerializationProcess();
            var des            = new Deserializer(serializedData);

            Assert.AreEqual(originalvalue, des.GetInt32());
            Assert.AreEqual(originalvalue2, des.GetInt32());
        }
Exemplo n.º 6
0
        public void ReadIntFromArrayWithLegalDataFor4IntsSuccess()
        {
            var data = "0000001234" +
                       "0000002345" +
                       "0000003456" +
                       "0000004567";
            var des = new Deserializer(data);

            Assert.AreEqual(1234, des.GetInt32());
            Assert.AreEqual(2345, des.GetInt32());
            Assert.AreEqual(3456, des.GetInt32());
            Assert.AreEqual(4567, des.GetInt32());
            Assert.AreEqual(40, des.CurrentPosition);
        }
Exemplo n.º 7
0
        public void ReadIntFromArrayWithLegalDataFor4IntsButTryToRead5FailsWithException()
        {
            var data = "0000001234" +
                       "0000002345" +
                       "0000003456" +
                       "0000004567";
            var des = new Deserializer(data);

            Assert.AreEqual(1234, des.GetInt32());
            Assert.AreEqual(2345, des.GetInt32());
            Assert.AreEqual(3456, des.GetInt32());
            Assert.AreEqual(4567, des.GetInt32());
            Assert.Throws <ParserException>(
                () => { des.GetInt32(); });
        }
Exemplo n.º 8
0
        public void ReadIntFromArrayWithLegalDataFor1NegativeIntSuccess()
        {
            var data = "-0000001234";
            var des  = new Deserializer(data);

            Assert.AreEqual(-1234, des.GetInt32());
            Assert.AreEqual(11, des.CurrentPosition);
        }
Exemplo n.º 9
0
        public void Serialize2IntsAndDeserialzeStringThrowsException()
        {
            var originalvalue  = -12569;
            var originalvalue2 = 987654;

            ser.AddInt32(originalvalue);
            ser.AddInt32(originalvalue2);
            var serializedData = ser.FinalizeSerializationProcess();
            var des            = new Deserializer(serializedData);

            Assert.AreEqual(originalvalue, des.GetInt32());
            Assert.Throws <ParserException>(() => { des.GetString(); });
        }
Exemplo n.º 10
0
        private static void Main()
        {
            var serial = new Serializer();

            serial.AddInt32(0);
            serial.AddString("Pb4");
            serial.AddString("Pb4.1");
            serial.AddString("Update");

            var final = serial.FinalizeSerializationProcess();

            var des = new Deserializer(final);

            var i1 = des.GetInt32();
            var s1 = des.GetString();
            var s2 = des.GetString();
            var s3 = des.GetString();

            Console.WriteLine("blub");
        }
Exemplo n.º 11
0
        public void SerializeAndDeserialize4RandomValuesOfDifferentType()
        {
            var    rand          = new Random(Guid.NewGuid().GetHashCode());
            var    value1        = LongRandom(0, long.MaxValue, rand);
            var    value2        = rand.Next(0, int.MaxValue);
            double value3        = LongRandom(0, long.MinValue, rand) + rand.Next(0, 5000) / 1000;
            var    value4        = rand.Next() % 2 == 0;
            var    value5Builder = new StringBuilder();

            for (var i = 0; i < 50; i++)
            {
                //just using numbers as string. should still work
                value5Builder.Append(rand.Next());
            }

            var value5 = value5Builder.ToString();

            TestContext.Out.WriteLine($"long value:{value1}");
            TestContext.Out.WriteLine($"int value:{value2}");
            TestContext.Out.WriteLine($"double value:{value3}");
            TestContext.Out.WriteLine($"bool value:{value4}");
            TestContext.Out.WriteLine($"string value:{value5}");


            ser.AddLong(value1);
            ser.AddInt32(value2);
            ser.AddDouble(value3);
            ser.AddBool(value4);
            ser.AddString(value5);

            var final = ser.FinalizeSerializationProcess();
            var des   = new Deserializer(final);

            Assert.AreEqual(value1, des.GetLong());
            Assert.AreEqual(value2, des.GetInt32());
            Assert.AreEqual(value3, des.GetDouble());
            Assert.AreEqual(value4, des.GetBool());
            var value = des.GetString();

            Assert.AreEqual(value5, value);
        }
Exemplo n.º 12
0
 public void Deserialze(Deserializer serializedData)
 {
     Field1 = serializedData.GetInt32();
     Field2 = serializedData.GetString();
 }