btobexprofiles/obexsendservices/obexservicesendutils/src/BTSUDataConverter.cpp
author hgs
Fri, 28 May 2010 17:03:06 +0300
changeset 32 19bd632b5100
permissions -rw-r--r--
201021
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
32
hgs
parents:
diff changeset
     1
/*
hgs
parents:
diff changeset
     2
* Copyright (c) 2002 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     3
* All rights reserved.
hgs
parents:
diff changeset
     4
* This component and the accompanying materials are made available
hgs
parents:
diff changeset
     5
* under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     6
* which accompanies this distribution, and is available
hgs
parents:
diff changeset
     7
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     8
*
hgs
parents:
diff changeset
     9
* Initial Contributors:
hgs
parents:
diff changeset
    10
* Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    11
*
hgs
parents:
diff changeset
    12
* Contributors:
hgs
parents:
diff changeset
    13
*
hgs
parents:
diff changeset
    14
* Description:  Data converter implementation
hgs
parents:
diff changeset
    15
*
hgs
parents:
diff changeset
    16
*/
hgs
parents:
diff changeset
    17
hgs
parents:
diff changeset
    18
hgs
parents:
diff changeset
    19
// INCLUDE FILES
hgs
parents:
diff changeset
    20
#include "BTSUDataConverter.h"
hgs
parents:
diff changeset
    21
#include <es_sock.h> // for BigEndian functions
hgs
parents:
diff changeset
    22
#include "BTSUDebug.h"
hgs
parents:
diff changeset
    23
hgs
parents:
diff changeset
    24
// CONSTANTS
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
// ============================ MEMBER FUNCTIONS ===============================
hgs
parents:
diff changeset
    27
hgs
parents:
diff changeset
    28
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    29
// TBTSUDataConverter::ConvertByteL
hgs
parents:
diff changeset
    30
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    31
//
hgs
parents:
diff changeset
    32
TUint8 TBTSUDataConverter::ConvertByteL( const TPtrC8& aData )
hgs
parents:
diff changeset
    33
    {
hgs
parents:
diff changeset
    34
    if ( aData.Length() != sizeof(TUint8) )
hgs
parents:
diff changeset
    35
        {
hgs
parents:
diff changeset
    36
        User::Leave( KErrArgument );
hgs
parents:
diff changeset
    37
        }
hgs
parents:
diff changeset
    38
    return *aData.Ptr();
hgs
parents:
diff changeset
    39
    }
hgs
parents:
diff changeset
    40
hgs
parents:
diff changeset
    41
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    42
// TBTSUDataConverter::ConvertDataSignedL
hgs
parents:
diff changeset
    43
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    44
//
hgs
parents:
diff changeset
    45
TInt32 TBTSUDataConverter::ConvertDataSignedL( const TPtrC8& aData )
hgs
parents:
diff changeset
    46
    {
hgs
parents:
diff changeset
    47
    if ( aData.Length() != sizeof(TInt32) )
hgs
parents:
diff changeset
    48
        {
hgs
parents:
diff changeset
    49
        User::Leave( KErrArgument );
hgs
parents:
diff changeset
    50
        }
hgs
parents:
diff changeset
    51
    TUint32 rawVal = BigEndian::Get32(aData.Ptr());
hgs
parents:
diff changeset
    52
    return *reinterpret_cast<TInt32*>(&rawVal); // reinterpret cast to extract signed nature "unscathed"
hgs
parents:
diff changeset
    53
    }
hgs
parents:
diff changeset
    54
hgs
parents:
diff changeset
    55
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    56
// TBTSUDataConverter::ConvertDataUnsignedL
hgs
parents:
diff changeset
    57
// -----------------------------------------------------------------------------
hgs
parents:
diff changeset
    58
//
hgs
parents:
diff changeset
    59
TUint32 TBTSUDataConverter::ConvertDataUnsignedL( const TPtrC8& aData )
hgs
parents:
diff changeset
    60
    {
hgs
parents:
diff changeset
    61
    if ( aData.Size() != sizeof(TUint32) )
hgs
parents:
diff changeset
    62
        {
hgs
parents:
diff changeset
    63
        User::Leave( KErrArgument );
hgs
parents:
diff changeset
    64
        }
hgs
parents:
diff changeset
    65
    return BigEndian::Get32(aData.Ptr());
hgs
parents:
diff changeset
    66
    }
hgs
parents:
diff changeset
    67
hgs
parents:
diff changeset
    68
//  End of File