csogg.Page.checksum C# (CSharp) Method

checksum() private method

private checksum ( ) : void
return void
        internal void checksum()
        {
            uint crc_reg=0;
            uint a, b;

            for(int i=0;i<header_len;i++)
            {
                a = header_base[header+i] & 0xffu;
                b = (crc_reg >> 24) & 0xff;
                crc_reg = (crc_reg<<8)^crc_lookup[a^b];
                //crc_reg = (crc_reg<<8)^(uint)(crc_lookup[((crc_reg >> 24)&0xff)^(header_base[header+i]&0xff)]);
            }
            for(int i=0;i<body_len;i++)
            {
                a = body_base[body+i] & 0xffu;
                b = (crc_reg >> 24) & 0xff;
                crc_reg = (crc_reg<<8)^crc_lookup[a^b];

                //crc_reg = (crc_reg<<8)^(uint)(crc_lookup[((crc_reg >> 24)&0xff)^(body_base[body+i]&0xff)]);
            }
            header_base[header+22]=(byte)crc_reg/*&0xff*/;
            header_base[header+23]=(byte)(crc_reg>>8)/*&0xff*/;
            header_base[header+24]=(byte)(crc_reg>>16)/*&0xff*/;
            header_base[header+25]=(byte)(crc_reg>>24)/*&0xff*/;
        }

Usage Example

Exemplo n.º 1
0
        public int pageseek(Page og)
        {
            int page = returned;
            int next;
            int bytes = fill - returned;

            if (headerbytes == 0)
            {
                int _headerbytes, i;
                if (bytes < 27)
                {
                    return(0);                         // not enough for a header
                }
                /* verify capture pattern */
                //!!!!!!!!!!!
                if (data[page] != 'O' || data[page + 1] != 'g' || data[page + 2] != 'g' || data[page + 3] != 'S')
                {
                    headerbytes = 0;
                    bodybytes   = 0;

                    // search for possible capture
                    next = 0;
                    for (int ii = 0; ii < bytes - 1; ii++)
                    {
                        if (data[page + 1 + ii] == 'O')
                        {
                            next = page + 1 + ii; break;
                        }
                    }
                    //next=memchr(page+1,'O',bytes-1);
                    if (next == 0)
                    {
                        next = fill;
                    }

                    returned = next;
                    return(-(next - page));
                }
                _headerbytes = (data[page + 26] & 0xff) + 27;
                if (bytes < _headerbytes)
                {
                    return(0);                                   // not enough for header + seg table
                }
                // count up body length in the segment table

                for (i = 0; i < (data[page + 26] & 0xff); i++)
                {
                    bodybytes += (data[page + 27 + i] & 0xff);
                }
                headerbytes = _headerbytes;
            }

            if (bodybytes + headerbytes > bytes)
            {
                return(0);
            }

            // The whole test page is buffered.  Verify the checksum
            lock (chksum)
            {
                // Grab the checksum bytes, set the header field to zero

                Array.Copy(data, page + 22, chksum, 0, 4);
                data[page + 22] = 0;
                data[page + 23] = 0;
                data[page + 24] = 0;
                data[page + 25] = 0;

                // set up a temp page struct and recompute the checksum
                Page log = pageseek_p;
                log.header_base = data;
                log.header      = page;
                log.header_len  = headerbytes;

                log.body_base = data;
                log.body      = page + headerbytes;
                log.body_len  = bodybytes;
                log.checksum();

                // Compare
                if (chksum[0] != data[page + 22] ||
                    chksum[1] != data[page + 23] ||
                    chksum[2] != data[page + 24] ||
                    chksum[3] != data[page + 25])
                {
                    // D'oh.  Mismatch! Corrupt page (or miscapture and not a page at all)
                    // replace the computed checksum with the one actually read in
                    Array.Copy(chksum, 0, data, page + 22, 4);
                    // Bad checksum. Lose sync */

                    headerbytes = 0;
                    bodybytes   = 0;
                    // search for possible capture
                    next = 0;
                    for (int ii = 0; ii < bytes - 1; ii++)
                    {
                        if (data[page + 1 + ii] == 'O')
                        {
                            next = page + 1 + ii; break;
                        }
                    }
                    //next=memchr(page+1,'O',bytes-1);
                    if (next == 0)
                    {
                        next = fill;
                    }
                    returned = next;
                    return(-(next - page));
                }
            }

            // yes, have a whole page all ready to go
            {
                page = returned;

                if (og != null)
                {
                    og.header_base = data;
                    og.header      = page;
                    og.header_len  = headerbytes;
                    og.body_base   = data;
                    og.body        = page + headerbytes;
                    og.body_len    = bodybytes;
                }

                unsynced    = 0;
                returned   += (bytes = headerbytes + bodybytes);
                headerbytes = 0;
                bodybytes   = 0;
                return(bytes);
            }
        }
All Usage Examples Of csogg.Page::checksum