Exemple #1
0
        public static void AddToFilterBase(FilterBase fb, uint initial)
        {
            uint rCrc = initial;
            uint wCrc = initial;
            int  rSeq = 0;
            int  wSeq = 0;

            fb.AddFilters(
                fRead: (bv) => {
                if (bv.nextNode != null)
                {
                    throw new NotImplementedException();
                }
                var targetCrc = BitConverter.ToUInt32(bv.bytes, bv.offset + bv.len - 4);
                bv.len       -= 4;
                uint c        = rCrc;
                c             = Append(bv, c);
                c             = Append(BitConverter.GetBytes(rSeq++), c);
                c             = Append(BitConverter.GetBytes(bv.len), c);
                if (c != targetCrc)
                {
                    throw new Exception("CRC32C checksum failed!");
                }
                rCrc = c;
            },
                fWrite: (bv) => {
                uint c = wCrc;
                c      = Append(bv, c);
                c      = Append(BitConverter.GetBytes(wSeq++), c);
                c      = Append(BitConverter.GetBytes(bv.tlen), c);
                wCrc   = c;
                bv.lastNode.nextNode = new BytesView(BitConverter.GetBytes(c));
            });
        }