Update contrib.
1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of the License "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // e32\debug\crashMonitor\src\scmchksum.cpp
23 #include <scmdatatypes.h>
30 TScmChecksum::TScmChecksum()
38 * ChecksumBlock - calculate checksum values for given data
39 * @param aData - the data to checksum
40 * @param aLen - the length of the data to checksum
43 void TScmChecksum::ChecksumBlock(const TUint8* aData, TUint aLen)
47 * Note there is Symbian CRC implementation to be found in the following
48 * \src\cedar\generic\tools\e32tools\elf2e32\source\checksum.h
49 * \src\cedar\generic\tools\e32tools\elf2e32\source\checksum.cpp
50 * this however may be no good to us
51 * as we need to produce a single checksum even though the entire data may be
52 * read in different size blocks - and the entire data may not be available
53 * (the comm port requirement is for read only )
54 * If we do however want to use the CRC then this is the place to insert the code
61 for(TUint i=0;i<aLen;i++)
63 TUint8 val = *(aData+i);
78 * ChecksumBlock - calculate checksum values for given data
79 * @param aData - descriptor containing the data to checksum
82 void TScmChecksum::ChecksumBlock(const TDesC8& aDes)
84 ChecksumBlock(aDes.Ptr(), aDes.Length());
88 * ChecksumBlock - operator ==
89 * @param aOther - the TScmChecksum to compare too
90 * @return ETrue is objects match - otherwise EFalse
92 TBool TScmChecksum::operator == (const TScmChecksum& aOther) const
94 return (iLength == aOther.iLength && iSum == aOther.iSum && iZeroCount == aOther.iZeroCount);
98 * ChecksumBlock - operator !=
99 * @param aOther - the TScmChecksum to compare too
100 * @return EFalse if objects match - otherwise ETrue
102 TBool TScmChecksum::operator != (const TScmChecksum& aOther) const
104 return !(*this == aOther);
109 * @return size of this object when streamed in bytes
111 TInt TScmChecksum::GetSize() const
117 * Serialize - writes this object to the supplied byte stream
118 * @param aItem - aWriter - the TByteStreamWriter that will be written to
119 * @return One of the OS wide codes
121 TInt TScmChecksum::Serialize(TByteStreamWriter& aWriter)
123 TInt startPos = aWriter.CurrentPosition();
124 aWriter.WriteInt(iLength);
125 aWriter.WriteInt(iSum);
126 aWriter.WriteInt(iZeroCount);
127 TInt sizeWritten = aWriter.CurrentPosition() - startPos;
128 if(sizeWritten != GetSize())
130 // error between actual size & real size in data
131 CLTRACE("TScmChecksum serialization size error");
139 * Deserialize - read this objects state from the supplied byte stream
140 * @param aItem - aReader - the TByteStreamReader that will be read from
141 * @return One of the OS wide codes
143 TInt TScmChecksum::Deserialize(TByteStreamReader& aReader)
145 TInt startPos = aReader.CurrentPosition();
146 // do we need a version check here - will it change ?
147 iLength = aReader.ReadInt();
148 iSum = aReader.ReadInt();
149 iZeroCount = aReader.ReadInt();
151 TInt sizeRead = aReader.CurrentPosition() - startPos;
152 if(sizeRead != GetSize())
154 // error between actual size & real size in data
155 CLTRACE("TScmChecksum Deserialization size error");
162 void TScmChecksum::Reset()
164 iLength = iSum = iZeroCount = 0;