// Collection of code snippets by Arne Vajhøj // (likely posted to comp.os.vms/INFO-VAX, INFO-TPU, MACRO32, eksperten.dk, newz.dk, LinkedIn or other place sometime between 1990 and now) using System; using System.IO; namespace Test { using Protocol.Packets; using Protocol.IO; using Protocol.Validation; public class Program { private static void Dump(MemoryStream ms) { byte[] buf = ms.GetBuffer(); for(int i = 0; i < ms.Length; i++) { Console.Write(" " + buf[i].ToString("X2")); } Console.WriteLine(); } public static void Main(string[] args) { Packet[] p = { new VersionPacket { Version = Version.V2 }, new Protocol.Packets.V2.FooPacket { A = 123, B = 456 }, new BarPacket { C = 789 } }; using(MemoryStream ms = new MemoryStream()) { using(BinaryWriter bw = new BinaryWriter(ms)) { using(PacketWriter pw = new ValidatingPacketWriter(bw, Version.V2, new StandardPacketValidator(), new StandardPacketStreamValidator())) { pw.Write(p); Dump(ms); } } } byte[] buf = { 0x02, 0x01, 0x02, 0x06, 0x02, 0x7B, 0x00, 0xC8, 0x01, 0x04, 0x03, 0x15, 0x03 }; using(MemoryStream ms = new MemoryStream(buf)) { using(BinaryReader br = new BinaryReader(ms)) { using(PacketReader pr = new ValidatingPacketReader(br, Version.V1, new StandardPacketValidator(), new StandardPacketStreamValidator())) { while(true) { try { Packet p1 = pr.Read(); Console.WriteLine(p1.GetType().FullName); } catch(EndOfStreamException) { break; } } } } } } } }