public static void Write(Writer writer, CompleteFile item) { try { writer.WriteVar <string>(MaxNameLen, item.FileName); } catch (SystemException ex) { throw new FormatException("can't write 'FileName' field", ex); } writer.Write <FileType>(item.Type); writer.WriteVar <string>(MaxUserName, item.Owner); writer.WriteVar <byte[]>(MaxFileLen, item.Data); }
public static CompleteFile Read(Reader reader) { CompleteFile result = new CompleteFile(); try { result.FileName = reader.ReadVar<string>(MaxNameLen); } catch (SystemException ex) { throw new FormatException("can't read 'FileName' field", ex); } try { result.Type = reader.Read<FileType>(); } catch (SystemException ex) { throw new FormatException("can't read 'Type' field", ex); } try { result.Owner = reader.ReadVar<string>(MaxUserName); } catch (SystemException ex) { throw new FormatException("can't read 'Owner' field", ex); } try { result.Data = reader.ReadVar<byte[]>(MaxFileLen); } catch (SystemException ex) { throw new FormatException("can't read 'Data' field", ex); } return result; }
public static CompleteFile Read(Reader reader) { CompleteFile result = new CompleteFile(); try { result.FileName = reader.ReadVar <string>(MaxNameLen); } catch (SystemException ex) { throw new FormatException("can't read 'FileName' field", ex); } try { result.Type = reader.Read <FileType>(); } catch (SystemException ex) { throw new FormatException("can't read 'Type' field", ex); } try { result.Owner = reader.ReadVar <string>(MaxUserName); } catch (SystemException ex) { throw new FormatException("can't read 'Owner' field", ex); } try { result.Data = reader.ReadVar <byte[]>(MaxFileLen); } catch (SystemException ex) { throw new FormatException("can't read 'Data' field", ex); } return(result); }
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()); }
public static void Write(Writer writer, CompleteFile item) { try { writer.WriteVar<string>(MaxNameLen, item.FileName); } catch (SystemException ex) { throw new FormatException("can't write 'FileName' field", ex); } writer.Write<FileType>(item.Type); writer.WriteVar<string>(MaxUserName, item.Owner); writer.WriteVar<byte[]>(MaxFileLen, item.Data); }