Exemple #1
0
        public void SizePrefixedBytesWorks()
        {
            var pw    = new PaddedWrapper();
            var data1 = new byte[10];
            var data2 = new byte[10];

            Array.Fill(data1, (byte)0xFF);
            Array.Fill(data2, (byte)0x11);

            var spb  = new SizePrefixedBytes();
            var spb2 = new SizePrefixedBytes();

            spb.data  = new byte[10 + sizeof(int)];
            spb2.data = new byte[10 + sizeof(int)];
            BitConverter.TryWriteBytes(spb.data, 10);
            BitConverter.TryWriteBytes(spb2.data, 10);
            Array.Copy(data1, 0, spb.data, sizeof(int), data1.Length);
            Array.Copy(data2, 0, spb2.data, sizeof(int), data1.Length);

            if (!pw.CanPackIn(spb2.data))
            {
                pw = pw.CopyToBigger(spb2.data.Length);
            }
            pw.initFrom(spb);
            pw.PackIn(spb2.data);
        }