32
|
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: Data converter implementation
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
|
|
19 |
// INCLUDE FILES
|
|
20 |
#include "BTSUDataConverter.h"
|
|
21 |
#include <es_sock.h> // for BigEndian functions
|
|
22 |
#include "BTSUDebug.h"
|
|
23 |
|
|
24 |
// CONSTANTS
|
|
25 |
|
|
26 |
// ============================ MEMBER FUNCTIONS ===============================
|
|
27 |
|
|
28 |
// -----------------------------------------------------------------------------
|
|
29 |
// TBTSUDataConverter::ConvertByteL
|
|
30 |
// -----------------------------------------------------------------------------
|
|
31 |
//
|
|
32 |
TUint8 TBTSUDataConverter::ConvertByteL( const TPtrC8& aData )
|
|
33 |
{
|
|
34 |
if ( aData.Length() != sizeof(TUint8) )
|
|
35 |
{
|
|
36 |
User::Leave( KErrArgument );
|
|
37 |
}
|
|
38 |
return *aData.Ptr();
|
|
39 |
}
|
|
40 |
|
|
41 |
// -----------------------------------------------------------------------------
|
|
42 |
// TBTSUDataConverter::ConvertDataSignedL
|
|
43 |
// -----------------------------------------------------------------------------
|
|
44 |
//
|
|
45 |
TInt32 TBTSUDataConverter::ConvertDataSignedL( const TPtrC8& aData )
|
|
46 |
{
|
|
47 |
if ( aData.Length() != sizeof(TInt32) )
|
|
48 |
{
|
|
49 |
User::Leave( KErrArgument );
|
|
50 |
}
|
|
51 |
TUint32 rawVal = BigEndian::Get32(aData.Ptr());
|
|
52 |
return *reinterpret_cast<TInt32*>(&rawVal); // reinterpret cast to extract signed nature "unscathed"
|
|
53 |
}
|
|
54 |
|
|
55 |
// -----------------------------------------------------------------------------
|
|
56 |
// TBTSUDataConverter::ConvertDataUnsignedL
|
|
57 |
// -----------------------------------------------------------------------------
|
|
58 |
//
|
|
59 |
TUint32 TBTSUDataConverter::ConvertDataUnsignedL( const TPtrC8& aData )
|
|
60 |
{
|
|
61 |
if ( aData.Size() != sizeof(TUint32) )
|
|
62 |
{
|
|
63 |
User::Leave( KErrArgument );
|
|
64 |
}
|
|
65 |
return BigEndian::Get32(aData.Ptr());
|
|
66 |
}
|
|
67 |
|
|
68 |
// End of File
|