syncmlfw/dm/syncagent/src/nsmldmbitreader.cpp
changeset 0 b497e44ab2fc
equal deleted inserted replaced
-1:000000000000 0:b497e44ab2fc
       
     1 /*
       
     2 * Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies). 
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  Bit reader utility
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 // INCLUDE FILES
       
    21 #include "nsmldmbitreader.h"
       
    22 
       
    23 // ---------------------------------------------------------
       
    24 // TNSmlDMBitreader::TNSmlDMBitreader()
       
    25 // Constructor
       
    26 // ---------------------------------------------------------
       
    27 TNSmlDMBitreader::TNSmlDMBitreader( const TDesC8& aData ) : RDesReadStream(aData), iByte(0), iBits(0)
       
    28 	{
       
    29 	}
       
    30 
       
    31 // ---------------------------------------------------------
       
    32 // TNSmlDMBitreader::ReadUintL()
       
    33 // 
       
    34 // ---------------------------------------------------------
       
    35 TUint32 TNSmlDMBitreader::ReadUintL( TInt aBitcount )
       
    36 	{
       
    37 	if( (aBitcount < 0) || (aBitcount > 32) )
       
    38 		{
       
    39 		User::Leave(KErrOverflow);
       
    40 		}
       
    41 
       
    42 	TUint32 value(0);
       
    43 
       
    44 	while( aBitcount-- )
       
    45 		{
       
    46 		value <<= 1;
       
    47 		value |= FetchNextBitL();
       
    48 		}
       
    49 	return value;
       
    50 	}
       
    51 
       
    52 // ---------------------------------------------------------
       
    53 // TNSmlDMBitreader::ReadL()
       
    54 // 
       
    55 // ---------------------------------------------------------
       
    56 void TNSmlDMBitreader::ReadL( TInt aBitcount, TDes8& aBuffer )
       
    57 	{
       
    58 	if( (aBitcount>>3) > aBuffer.MaxLength() )
       
    59 		{
       
    60 		User::Leave(KErrOverflow);
       
    61 		}
       
    62 	aBuffer.Zero();
       
    63 	for( TInt i = 0; i < (aBitcount>>3); i++ )
       
    64 		{
       
    65 		aBuffer.Append((TUint8)ReadUintL(8));
       
    66 		}
       
    67 	}
       
    68 // ---------------------------------------------------------
       
    69 // TNSmlDMBitreader::FetchNextBitL()
       
    70 // 
       
    71 // ---------------------------------------------------------
       
    72 TUint32 TNSmlDMBitreader::FetchNextBitL()
       
    73 	{
       
    74 	if( --iBits < 0 )
       
    75 		{
       
    76 		iByte = ReadUint8L();
       
    77 		iBits = 7;
       
    78 		}
       
    79 	return (iByte>>iBits)&0x1;
       
    80 	}
       
    81 
       
    82 
       
    83 //  End of File