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()); }
static Toolkit() { _wb = new WriteBuilder(); _rb = new ReadBuilder(); }
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()); }
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()); }
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()); }