Beispiel #1
0
        public void Read()
        {
            ByteReader s1 = new ByteReader(
                0x00, 0x00, 0x00, 0x07,
                0xCD, 0xEF, 0x98, 0x76);

            ReadBuilder builder1 = new ReadBuilder()
                                   .Map <SimplyInt>(SimplyInt.Read2);
            Reader r1 = builder1.Create(s1);

            var val1 = r1.Read <SimplyInt>();

            Assert.AreEqual(-7, val1.Field1);
            Assert.AreEqual(0xCDEF9876, val1.Field2);


            ByteReader s2 = new ByteReader(
                0x00, 0x00, 0x00, 0x07,
                0xCD, 0xEF, 0x98, 0x76);

            ReadBuilder builder2 = new ReadBuilder()
                                   .Map <SimplyInt>(SimplyInt.Read);
            Reader r2 = builder2.Create(s2);

            var val2 = r2.Read <SimplyInt>();

            Assert.AreEqual(7, val2.Field1);
            Assert.AreEqual(0xCDEF9876, val2.Field2);
        }
Beispiel #2
0
        public void Read()
        {
            ByteReader s1 = new ByteReader(
                0x00, 0x00, 0x00, 0x07,
                0xCD, 0xEF, 0x98, 0x76);

            ReadBuilder builder1 = new ReadBuilder()
                .Map<SimplyInt>(SimplyInt.Read2);
            Reader r1 = builder1.Create(s1);

            var val1 = r1.Read<SimplyInt>();
            Assert.AreEqual(-7, val1.Field1);
            Assert.AreEqual(0xCDEF9876, val1.Field2);

            ByteReader s2 = new ByteReader(
                0x00, 0x00, 0x00, 0x07,
                0xCD, 0xEF, 0x98, 0x76);

            ReadBuilder builder2 = new ReadBuilder()
                .Map<SimplyInt>(SimplyInt.Read);
            Reader r2 = builder2.Create(s2);

            var val2 = r2.Read<SimplyInt>();
            Assert.AreEqual(7, val2.Field1);
            Assert.AreEqual(0xCDEF9876, val2.Field2);
        }
Beispiel #3
0
        public void ReadInt()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x01,
                0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0xFF, 0xFF, 0xFF,
                0x7F, 0xFF, 0xFF, 0xFF);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

             Assert.AreEqual(1, r.Read<int>());
            Assert.AreEqual(4, s.Position);

            Assert.AreEqual(1, r.Read<uint>());
            Assert.AreEqual(8, s.Position);

            Assert.AreEqual(uint.MaxValue, r.Read<uint>());
            Assert.AreEqual(12, s.Position);

            Assert.AreEqual(3, r.ReadFix<byte[]>(3).Length);
            Assert.AreEqual(16, s.Position);

            Assert.AreEqual(int.MaxValue, r.Read<int>());
            Assert.AreEqual(20, s.Position);
        }
Beispiel #4
0
        public void ReadInt()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x01,
                0xFF, 0xFF, 0xFF, 0xFF,
                0xFF, 0xFF, 0xFF, 0xFF,
                0x7F, 0xFF, 0xFF, 0xFF);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            Assert.AreEqual(1, r.Read <int>());
            Assert.AreEqual(4, s.Position);

            Assert.AreEqual(1, r.Read <uint>());
            Assert.AreEqual(8, s.Position);

            Assert.AreEqual(uint.MaxValue, r.Read <uint>());
            Assert.AreEqual(12, s.Position);

            Assert.AreEqual(3, r.ReadFix <byte[]>(3).Length);
            Assert.AreEqual(16, s.Position);

            Assert.AreEqual(int.MaxValue, r.Read <int>());
            Assert.AreEqual(20, s.Position);
        }
Beispiel #5
0
        public void Read_TwoItem()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            var val = r.Read <ListItem>();

            Assert.AreEqual(1, val.Field1);
            Assert.AreEqual(null, val.Field2);
            Assert.IsNotNull(val.Field3);

            Assert.AreEqual(1, val.Field3.Field1);
            Assert.AreEqual(3, val.Field3.Field2);
            Assert.AreEqual(null, val.Field3.Field3);
            Assert.AreEqual(7 * 4, s.Position);
        }
Beispiel #6
0
        public void ReadObject()
        {
            ByteReader  s       = new ByteReader();
            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            r.Read <object>();
        }
Beispiel #7
0
        public void ReadObject()
        {
            ByteReader s = new ByteReader();
            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            r.Read<object>();
        }
Beispiel #8
0
        public void ExceptionRead()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            r.Read <IntEnum>();
        }
Beispiel #9
0
        public void ExceptionRead()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            r.Read<IntEnum>();
        }
Beispiel #10
0
        public void ReadByteOne()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            Assert.AreEqual(ByteEnum.One, r.Read<ByteEnum>());
            Assert.AreEqual(4, s.Position);
        }
Beispiel #11
0
        public void ReadTwo()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x02);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            Assert.AreEqual(IntEnum.Two, r.Read<IntEnum>());
            Assert.AreEqual(4, s.Position);
        }
Beispiel #12
0
        public void ReadByteOne()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            Assert.AreEqual(ByteEnum.One, r.Read <ByteEnum>());
            Assert.AreEqual(4, s.Position);
        }
Beispiel #13
0
        public void ReadTwo()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x02);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            Assert.AreEqual(IntEnum.Two, r.Read <IntEnum>());
            Assert.AreEqual(4, s.Position);
        }
Beispiel #14
0
        public void ReadBool(byte num, bool expected)
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, num);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            bool result = r.Read<bool>();
            Assert.AreEqual(4, s.Position);
            Assert.AreEqual(expected, result);
        }
Beispiel #15
0
        public void ReadBool(byte num, bool expected)
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, num);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            bool result = r.Read <bool>();

            Assert.AreEqual(4, s.Position);
            Assert.AreEqual(expected, result);
        }
Beispiel #16
0
        public void ReadNullable(byte num, int readed, int? expected)
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, num,
                0x00, 0x00, 0x00, 123);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            int? result = r.Read<int?>();

            Assert.AreEqual(readed, s.Position);
            Assert.AreEqual(expected, result);
        }
Beispiel #17
0
        public void ReadStruct()
        {
            ByteReader s = new ByteReader(
                0x12, 0x34, 0xAB, 0xCD,
                0xCD, 0xEF, 0x98, 0x76);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            var val = r.Read<StructInt>();
            Assert.AreEqual(0x1234ABCD, val.Field1);
            Assert.AreEqual(0xCDEF9876, val.Field2);
            Assert.AreEqual(8, s.Position);
        }
Beispiel #18
0
        public void ReadNullable(byte num, int readed, int?expected)
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, num,
                0x00, 0x00, 0x00, 123);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            int?result = r.Read <int?>();

            Assert.AreEqual(readed, s.Position);
            Assert.AreEqual(expected, result);
        }
Beispiel #19
0
        public void Read_AttrMapping()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x09,
                0x73, 0x69, 0x6c, 0x6c,
                0x79, 0x70, 0x72, 0x6f,
                0x67, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x04,
                0x6c, 0x69, 0x73, 0x70,
                0x00, 0x00, 0x00, 0x04,
                0x6a, 0x6f, 0x68, 0x6e,
                0x00, 0x00, 0x00, 0x06,
                0x28, 0x71, 0x75, 0x69,
                0x74, 0x29, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder()
                                  //.Map<CompleteFile>(CompleteFile.Read)
                                  //.Map<FileType>(FileType.Read)
            ;
            Reader r = builder.Create(s);

            CompleteFile result = r.Read <CompleteFile>();

            Assert.AreEqual(12 * 4, s.Position);
            Assert.IsNotNull(result);

//        0      00 00 00 09     ....     -- length of filename = 9
//        4      73 69 6c 6c     sill     -- filename characters
//        8      79 70 72 6f     ypro     -- ... and more characters ...
//       12      67 00 00 00     g...     -- ... and 3 zero-bytes of fill
            Assert.AreEqual("sillyprog", result.FileName);
//       16      00 00 00 02     ....     -- filekind is EXEC = 2
            Assert.AreEqual(FileKind.Exec, result.Type.Type);
            Assert.IsNull(result.Type.Creator);
//       20      00 00 00 04     ....     -- length of interpretor = 4
//       24      6c 69 73 70     lisp     -- interpretor characters
            Assert.AreEqual("lisp", result.Type.Interpretor);
//       28      00 00 00 04     ....     -- length of owner = 4
//       32      6a 6f 68 6e     john     -- owner characters
            Assert.AreEqual("john", result.Owner);
//       36      00 00 00 06     ....     -- length of file data = 6
//       40      28 71 75 69     (qui     -- file data bytes ...
//       44      74 29 00 00     t)..     -- ... and 2 zero-bytes of fill
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(6, result.Data.Length);
            Assert.AreEqual(0x28, result.Data[0]);
            Assert.AreEqual(0x29, result.Data[5]);
        }
Beispiel #20
0
        public void ReadStruct()
        {
            ByteReader s = new ByteReader(
                0x12, 0x34, 0xAB, 0xCD,
                0xCD, 0xEF, 0x98, 0x76);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            var val = r.Read <StructInt>();

            Assert.AreEqual(0x1234ABCD, val.Field1);
            Assert.AreEqual(0xCDEF9876, val.Field2);
            Assert.AreEqual(8, s.Position);
        }
Beispiel #21
0
        public void Read()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x09,
                0x73, 0x69, 0x6c, 0x6c,
                0x79, 0x70, 0x72, 0x6f,
                0x67, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x04,
                0x6c, 0x69, 0x73, 0x70,
                0x00, 0x00, 0x00, 0x04,
                0x6a, 0x6f, 0x68, 0x6e,
                0x00, 0x00, 0x00, 0x06,
                0x28, 0x71, 0x75, 0x69,
                0x74, 0x29, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder()
                .Map<CompleteFile>(CompleteFile.Read)
                .Map<FileType>(FileType.Read);
            Reader r = builder.Create(s);

            CompleteFile result = r.Read<CompleteFile>();

            Assert.AreEqual(12*4, s.Position);
            Assert.IsNotNull(result);

            //        0      00 00 00 09     ....     -- length of filename = 9
            //        4      73 69 6c 6c     sill     -- filename characters
            //        8      79 70 72 6f     ypro     -- ... and more characters ...
            //       12      67 00 00 00     g...     -- ... and 3 zero-bytes of fill
            Assert.AreEqual("sillyprog", result.FileName);
            //       16      00 00 00 02     ....     -- filekind is EXEC = 2
            Assert.AreEqual(FileKind.Exec, result.Type.Type);
            Assert.IsNull(result.Type.Creator);
            //       20      00 00 00 04     ....     -- length of interpretor = 4
            //       24      6c 69 73 70     lisp     -- interpretor characters
            Assert.AreEqual("lisp", result.Type.Interpretor);
            //       28      00 00 00 04     ....     -- length of owner = 4
            //       32      6a 6f 68 6e     john     -- owner characters
            Assert.AreEqual("john", result.Owner);
            //       36      00 00 00 06     ....     -- length of file data = 6
            //       40      28 71 75 69     (qui     -- file data bytes ...
            //       44      74 29 00 00     t)..     -- ... and 2 zero-bytes of fill
            Assert.IsNotNull(result.Data);
            Assert.AreEqual(6, result.Data.Length);
            Assert.AreEqual(0x28, result.Data[0]);
            Assert.AreEqual(0x29, result.Data[5]);
        }
Beispiel #22
0
        public void Read()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x04);

            ReadBuilder builder = new ReadBuilder()
                                  .Map <SimplyInt>(SimplyInt.Read2);
            Reader r = builder.Create(s);

            var val = r.Read <SimplyInt>();

            Assert.AreEqual(-3, val.Field1);
            Assert.AreEqual(4u, val.Field2);
            Assert.AreEqual(8, s.Position);
        }
Beispiel #23
0
        public void Read_Short()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            var val = r.Read <ListItem>();

            Assert.AreEqual(1, val.Field1);
            Assert.AreEqual(null, val.Field2);
            Assert.AreEqual(null, val.Field3);
            Assert.AreEqual(12, s.Position);
        }
Beispiel #24
0
        public void Read_OneItem()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            var val = r.Read<ListItem>();
            Assert.AreEqual(1, val.Field1);
            Assert.AreEqual(3, val.Field2);
            Assert.AreEqual(null, val.Field3);
            Assert.AreEqual(16, s.Position);
        }
Beispiel #25
0
        public void ReadVarList()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x04);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            var val = r.ReadVar<List<int>>(4);
            Assert.AreEqual(3, val.Count);
            Assert.AreEqual(2, val[0]);
            Assert.AreEqual(3, val[1]);
            Assert.AreEqual(4, val[2]);
            Assert.AreEqual(16, s.Position);
        }
Beispiel #26
0
        public void ReadVarArray()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x04);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            var val = r.ReadVar<int[]>(4);
            Assert.AreEqual(3, val.Length);
            Assert.AreEqual(2, val[0]);
            Assert.AreEqual(3, val[1]);
            Assert.AreEqual(4, val[2]);
            Assert.AreEqual(16, s.Position);
        }
Beispiel #27
0
        public void ReadString(byte len, int readed, string expected)
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, len,
                0x48, 0x65, 0x6C, 0x6C,
                0x6F, 0x2C, 0x20, 0x77,
                0x6F, 0x72, 0x6C, 0x64,
                0x21, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            string result = r.ReadVar <string>(30);

            Assert.AreEqual(readed, s.Position);
            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);
        }
Beispiel #28
0
        public void ReadVarArray()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x04);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            var val = r.ReadVar <int[]>(4);

            Assert.AreEqual(3, val.Length);
            Assert.AreEqual(2, val[0]);
            Assert.AreEqual(3, val[1]);
            Assert.AreEqual(4, val[2]);
            Assert.AreEqual(16, s.Position);
        }
Beispiel #29
0
        public void ReadVarList()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x04);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            var val = r.ReadVar <List <int> >(4);

            Assert.AreEqual(3, val.Count);
            Assert.AreEqual(2, val[0]);
            Assert.AreEqual(3, val[1]);
            Assert.AreEqual(4, val[2]);
            Assert.AreEqual(16, s.Position);
        }
Beispiel #30
0
        public void Read_InternalFixArray()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            var val = r.Read<ListContainer>();
            Assert.AreEqual(1, val.Field1[0]);
            Assert.AreEqual(2, val.Field1[1]);
            Assert.AreEqual(3, val.Field1[2]);
            Assert.AreEqual(0, val.Field2.Count);
            Assert.AreEqual("", val.Field3);
            Assert.AreEqual(5*4, s.Position);
        }
Beispiel #31
0
        public void ReadList()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x04);

            ReadBuilder builder = new ReadBuilder()
                                  .Map <SimplyInt>(SimplyInt.Read2);
            Reader r = builder.Create(s);

            var val = r.ReadFix <List <SimplyInt> >(2);

            Assert.AreEqual(2, val.Count);
            Assert.AreEqual(-1, val[0].Field1);
            Assert.AreEqual(2, val[0].Field2);
            Assert.AreEqual(-3, val[1].Field1);
            Assert.AreEqual(4, val[1].Field2);
            Assert.AreEqual(16, s.Position);
        }
Beispiel #32
0
        public void Read_InternalFixArray()
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader      r       = builder.Create(s);

            var val = r.Read <ListContainer>();

            Assert.AreEqual(1, val.Field1[0]);
            Assert.AreEqual(2, val.Field1[1]);
            Assert.AreEqual(3, val.Field1[2]);
            Assert.AreEqual(0, val.Field2.Count);
            Assert.AreEqual("", val.Field3);
            Assert.AreEqual(5 * 4, s.Position);
        }
Beispiel #33
0
        public void ReadString(byte len, int readed, string expected)
        {
            ByteReader s = new ByteReader(
                0x00, 0x00, 0x00, len,
                0x48, 0x65, 0x6C, 0x6C,
                0x6F, 0x2C, 0x20, 0x77,
                0x6F, 0x72, 0x6C, 0x64,
                0x21, 0x00, 0x00, 0x00);

            ReadBuilder builder = new ReadBuilder();
            Reader r = builder.Create(s);

            string result = r.ReadVar<string>(30);
            Assert.AreEqual(readed, s.Position);
            Assert.IsNotNull(result);
            Assert.AreEqual(expected, result);
        }
Beispiel #34
0
 static Toolkit()
 {
     _wb = new WriteBuilder();
     _rb = new ReadBuilder();
 }