All pastes #2110886 Raw Edit

Miscellany

public text v1 · immutable
#2110886 ·published 2012-02-07 17:44 UTC
rendered paste body
            Console.WriteLine("Starting message round trip serialization...");

            DateTime start = DateTime.Now;

            Messages.Handshake handshake = new Messages.Handshake(new byte[20], " ".Repeat(20));
            Messages.HandshakeFormatter formatter = new Messages.HandshakeFormatter();

            byte[] b = formatter.Format(handshake);

            Messages.Handshake handshake2 = formatter.Unformat(b);

            Messages.Piece piece = new Messages.Piece(100, 5, new byte[128]);
            Messages.MessageFormatter formatter2 = new Messages.MessageFormatter();

            b = formatter2.Format(piece);

            byte[] b2 = new byte[b.Length - 4];// remove the length prefix for non-handshake/keepalive messages
            Array.Copy(b, 4, b2, 0, b2.Length);

            Messages.Piece piece2 = formatter2.Unformat((Messages.MsgId)b[4], b2) as Messages.Piece;
            
            Console.WriteLine("Round trip serialization complete, starting torrent load test...");