Exemple #1
0
        public void Write_InternalFixArray()
        {
            ByteWriter s = new ByteWriter();

            WriteBuilder b = new WriteBuilder();
            Writer       w = b.Create(s);

            ListContainer val = new ListContainer();

            val.Field1    = new int[3];
            val.Field1[0] = 1;
            val.Field1[1] = 2;
            val.Field1[2] = 3;
            val.Field2    = new List <uint>();
            val.Field3    = "";

            w.Write <ListContainer>(val);

            Assert.AreEqual(new byte[] {
                0x00, 0x00, 0x00, 0x01,
                0x00, 0x00, 0x00, 0x02,
                0x00, 0x00, 0x00, 0x03,
                0x00, 0x00, 0x00, 0x00,
                0x00, 0x00, 0x00, 0x00
            }, s.ToArray());
        }
Exemple #2
0
        public void Write_TwoItem()
        {
            ByteWriter s = new ByteWriter();

            WriteBuilder b = new WriteBuilder();
            Writer       w = b.Create(s);

            ListItem val = new ListItem();

            val.Field1        = 1;
            val.Field2        = null;
            val.Field3        = new ListItem();
            val.Field3.Field1 = 1;
            val.Field3.Field2 = 3;
            val.Field3.Field3 = null;

            w.Write <ListItem>(val);

            Assert.AreEqual(new byte[] {
                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
            }, s.ToArray());
        }
Exemple #3
0
        public void WriteVarArray(int[] array, byte[] expected)
        {
            ByteWriter s = new ByteWriter();

            WriteBuilder b = new WriteBuilder();
            Writer       w = b.Create(s);

            w.WriteVar <int[]>(5, array);
            Assert.AreEqual(expected, s.ToArray());
        }
Exemple #4
0
        public void WriteString(string text, byte[] expected)
        {
            ByteWriter s = new ByteWriter();

            WriteBuilder b = new WriteBuilder();
            Writer       w = b.Create(s);

            w.WriteVar <string>(5, text);
            Assert.AreEqual(expected, s.ToArray());
        }
Exemple #5
0
        public void WriteStruct()
        {
            ByteWriter s = new ByteWriter();

            WriteBuilder b = new WriteBuilder();
            Writer       w = b.Create(s);

            StructInt val = new StructInt();

            val.Field1 = 0x1234ABCD;
            val.Field2 = 0xCDEF9876;

            w.Write <StructInt>(val);

            Assert.AreEqual(new byte[] { 0x12, 0x34, 0xAB, 0xCD, 0xCD, 0xEF, 0x98, 0x76 }, s.ToArray());
        }
Exemple #6
0
        public void Write_AttrMapping()
        {
            CompleteFile cf = new CompleteFile();

            cf.FileName         = "sillyprog";
            cf.Type             = new FileType();
            cf.Type.Type        = FileKind.Exec;
            cf.Type.Interpretor = "lisp";
            cf.Owner            = "john";
            cf.Data             = new byte[] { 0x28, 0x71, 0x75, 0x69, 0x74, 0x29 };

            ByteWriter s = new ByteWriter();

            WriteBuilder b = new WriteBuilder()
                             //.Map<CompleteFile>(CompleteFile.Write)
                             //.Map<FileType>(FileType.Write)
            ;
            Writer w = b.Create(s);

            w.Write <CompleteFile>(cf);

            byte[] expected = new byte[]
            {
                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
            };

            Assert.AreEqual(expected, s.ToArray());
        }