public bool CheckDataSegment(DataSegment dataSegment)
        {
            if (dataSegment == null)
            {
                return(false);
            }

            return(CrcHash.Compute(dataSegment.DataString).ToString(CultureInfo.InvariantCulture) == dataSegment.Crccode);
        }
        public DataParameter BuildDataParameter <T>(int actionId, T data)
        {
            var parameter = new DataParameter {
                Action = actionId
            };

            parameter.DataString = ProcessToString(data);
            parameter.CrcCode    = CrcHash.Compute(parameter.DataString).ToString(CultureInfo.InvariantCulture);

            return(parameter);
        }
Example #3
0
 public CrcHash(uint polynomial)
 {
     HashSizeValue = 32;
     _crc32Table = (uint[])_crc32TablesCache[polynomial];
     if (_crc32Table == null)
     {
         _crc32Table = CrcHash._buildCRC32Table(polynomial);
         _crc32TablesCache.Add(polynomial, _crc32Table);
     }
     Initialize();
 }
        public DataSegment BuildDataSegment(int index, string dataId, int dataLength, int dataCount, string content)
        {
            var beginPos = index * dataLength;
            var legth    = index == dataCount - 1 ? content.Length - beginPos : dataLength;
            var data     = content.Substring(beginPos, legth);

            var dataSegment = new DataSegment();

            dataSegment.DataId     = dataId;
            dataSegment.Crccode    = CrcHash.Compute(data).ToString(CultureInfo.InvariantCulture);
            dataSegment.DataString = data;
            dataSegment.Index      = index;
            return(dataSegment);
        }
Example #5
0
 // static constructor
 static CrcHash()
 {
     _crc32TablesCache = Hashtable.Synchronized(new Hashtable());
     _defaultCRC = new CrcHash();
 }