inc/mdcserializationbuffer.h
changeset 0 c53acadfccc6
equal deleted inserted replaced
-1:000000000000 0:c53acadfccc6
       
     1 /*
       
     2 * Copyright (c) 2009 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:  Serialize and deserialize data between client and server
       
    15 *
       
    16 */
       
    17 
       
    18 #ifndef __MDCSERIALIZATIONBUFFER_H__
       
    19 #define __MDCSERIALIZATIONBUFFER_H__
       
    20 
       
    21 // INCLUDE FILES
       
    22 #include <e32base.h>
       
    23 #include "mdscommoninternal.h"
       
    24 
       
    25 class TMdCSerializationType;
       
    26 
       
    27 typedef TUint16 TSerializedDesLength;
       
    28 
       
    29 const TUint8 KPadding8 = 0xBD;
       
    30 const TInt32 KSerializedDesMaxLength = KMaxTUint16;
       
    31 const TUint32 KNoOffset = 0;
       
    32 
       
    33 /**
       
    34 * An automatic serializtion buffer class. 
       
    35 * The class provides insertion functionality for multiple variable types.
       
    36 */
       
    37 NONSHARABLE_CLASS(CMdCSerializationBuffer): public CBase
       
    38     {
       
    39     public:
       
    40 
       
    41 		#ifndef _DEBUG
       
    42 			const static TUint32 KRequiredSizeForTypeCheck = 0;
       
    43 		#else
       
    44 			const static TUint32 KRequiredSizeForTypeCheck = sizeof( TUint16 );
       
    45 		#endif
       
    46 
       
    47     	const static TUint32 KRequiredSizeForTBool   = sizeof( TInt32 ) + 2*KRequiredSizeForTypeCheck;
       
    48     	const static TUint32 KRequiredSizeForTInt8   = sizeof( TInt16 ) + 2*KRequiredSizeForTypeCheck;
       
    49     	const static TUint32 KRequiredSizeForTUint8  = sizeof( TUint16 ) + 2*KRequiredSizeForTypeCheck;
       
    50     	const static TUint32 KRequiredSizeForTInt16  = sizeof( TInt16 ) + KRequiredSizeForTypeCheck;
       
    51     	const static TUint32 KRequiredSizeForTUint16 = sizeof( TUint16 ) + KRequiredSizeForTypeCheck;
       
    52     	const static TUint32 KRequiredSizeForTInt32  = sizeof( TInt32 ) + KRequiredSizeForTypeCheck;
       
    53     	const static TUint32 KRequiredSizeForTUint32 = sizeof( TUint32 ) + KRequiredSizeForTypeCheck;
       
    54     	const static TUint32 KRequiredSizeForTInt64  = sizeof( TInt64 ) + KRequiredSizeForTypeCheck;
       
    55     	const static TUint32 KRequiredSizeForTReal32 = sizeof( TReal32 ) + KRequiredSizeForTypeCheck;
       
    56     	const static TUint32 KRequiredSizeForTReal64 = sizeof( TReal64 ) + KRequiredSizeForTypeCheck;
       
    57     	const static TUint32 KRequiredSizeForTTime   = sizeof( TInt64 ) + KRequiredSizeForTypeCheck;
       
    58 
       
    59 		// artificial types
       
    60 		const static TUint32 KRequiredSizeForTItemId   = sizeof( TItemId ) + KRequiredSizeForTypeCheck;
       
    61 		const static TUint32 KRequiredSizeForTDefId    = sizeof( TDefId ) + KRequiredSizeForTypeCheck;
       
    62 		const static TUint32 KRequiredSizeForEmptyText = sizeof( TSerializedDesLength ) + KRequiredSizeForTypeCheck;
       
    63 		const static TUint32 KRequiredSizeForTMdCValueUnion = sizeof( TMdCValueUnion ) + KRequiredSizeForTypeCheck;
       
    64 
       
    65     public: // public definitions
       
    66     	/**
       
    67         * Returns required buffer size for given 8-bit descriptor
       
    68         * @param aDes 8-bit descriptor
       
    69         * @return required size for descriptor (descriptor's length is limited to KSerializedDesMaxLength)
       
    70     	*/
       
    71     	IMPORT_C static TUint32 RequiredSize( const TDesC8& aDes );
       
    72 
       
    73     	/**
       
    74         * Returns required buffer size for given 16-bit descriptor
       
    75         * @param aDes 16-bit descriptor
       
    76         * @return required size for descriptor (descriptor's length is limited to KSerializedDesMaxLength)
       
    77     	*/
       
    78     	IMPORT_C static TUint32 RequiredSize( const TDesC16& aDes );
       
    79     
       
    80         /**
       
    81         * Static constructor
       
    82         * @param aSize size of the buffer
       
    83         * @return buffer instance
       
    84         */
       
    85         IMPORT_C static CMdCSerializationBuffer* NewL( TInt32 aSize );
       
    86 
       
    87         /**
       
    88         * Static constructor
       
    89         * @param aSize size of the buffer
       
    90         * @return buffer instance
       
    91         */
       
    92         IMPORT_C static CMdCSerializationBuffer* NewLC( TInt32 aSize );
       
    93 
       
    94         /**
       
    95          * Static constructor
       
    96          * @param aBuffer pointer to the buffer
       
    97          * @param aSize size of the buffer
       
    98          * @return buffer instance
       
    99          */
       
   100         IMPORT_C static CMdCSerializationBuffer* NewL( TUint8* aBuffer, TInt32 aSize );
       
   101 
       
   102         /**
       
   103          * Static constructor
       
   104          * @param aBuffer pointer to the buffer
       
   105          * @param aSize size of the buffer
       
   106          * @return buffer instance
       
   107          */
       
   108         IMPORT_C static CMdCSerializationBuffer* NewLC( TUint8* aBuffer, TInt32 aSize );
       
   109 
       
   110         /**
       
   111          * Static constructor
       
   112          * @param aMessage received message
       
   113          * @param aIndex index of wanted message
       
   114          * @return buffer instance
       
   115          */
       
   116         IMPORT_C static CMdCSerializationBuffer* NewL(const RMessage2 &aMsg, TInt aIndex );
       
   117          
       
   118         /**
       
   119          * Static constructor
       
   120          * @param aMessage received message
       
   121          * @param aIndex index of wanted message
       
   122          * @return buffer instance
       
   123          */
       
   124         IMPORT_C static CMdCSerializationBuffer* NewLC(const RMessage2 &aMsg, TInt aIndex);
       
   125 
       
   126         /**
       
   127          * Static constructor
       
   128          * @param aBuffer buffer to copy data from
       
   129          * @return buffer instance
       
   130          */
       
   131         IMPORT_C static CMdCSerializationBuffer* NewL( const CMdCSerializationBuffer& aBuffer );
       
   132 
       
   133         /**
       
   134          * Static constructor
       
   135          * @param aBuffer buffer to copy data from
       
   136          * @return buffer instance
       
   137          */
       
   138         IMPORT_C static CMdCSerializationBuffer* NewLC( const CMdCSerializationBuffer& aBuffer );
       
   139 
       
   140       
       
   141 
       
   142         virtual ~CMdCSerializationBuffer();
       
   143 
       
   144         /**
       
   145         * Get pointer to serialized buffer.
       
   146         * @return serialized buffer pointer
       
   147         */
       
   148 		IMPORT_C TPtr8 Buffer() const;
       
   149 
       
   150         /**
       
   151         * Get pointer to serialized buffer.
       
   152         * @return serialized buffer pointer
       
   153         */
       
   154 		IMPORT_C TPtr8* BufferPtr() const;
       
   155 
       
   156         /**
       
   157         * Get pointer to serialized buffer.
       
   158         * @return serialized buffer pointer
       
   159         */
       
   160 		IMPORT_C const TPtr8* BufferConstPtr() const;
       
   161 
       
   162     	/**
       
   163     	* Return size of the buffer.
       
   164     	* @return size of the buffer
       
   165     	*/
       
   166     	IMPORT_C TUint32 Size() const;
       
   167 
       
   168         /**
       
   169         * Change position of the serialized buffer.
       
   170         * @param aPosition value to be insert to current position
       
   171         * @return new buffer position
       
   172         */
       
   173 		IMPORT_C void PositionL( TUint32 aPosition );
       
   174 
       
   175         /**
       
   176         * Get current position of the serialized buffer.
       
   177         * @return current buffer position
       
   178         */
       
   179 		IMPORT_C TUint32 Position() const;
       
   180 
       
   181         /**
       
   182         * Insert TBool value to serialized buffer and move buffer's position 
       
   183         * to after inserted value.
       
   184         * @param aValue value to be insert to current position
       
   185         * @return new buffer position
       
   186         */
       
   187 		IMPORT_C TUint32 InsertL(TBool aValue);
       
   188 
       
   189         /**
       
   190         * Insert TInt8 value to serialized buffer and move buffer's position 
       
   191         * to after inserted value.
       
   192         * @param aValue value to be insert to current position
       
   193         * @return new buffer position
       
   194         */
       
   195 		IMPORT_C TUint32 InsertL(TInt8 aValue);
       
   196 
       
   197         /**
       
   198         * Insert TUint8 value to serialized buffer and move buffer's position 
       
   199         * to after inserted value.
       
   200         * @param aValue value to be insert to current position
       
   201         * @return new buffer position
       
   202         */
       
   203 		IMPORT_C TUint32 InsertL(TUint8 aValue);
       
   204 
       
   205         /**
       
   206         * Insert TInt16 value to serialized buffer and move buffer's position 
       
   207         * to after inserted value.
       
   208         * @param aValue value to be insert to current position
       
   209         * @return new buffer position
       
   210         */
       
   211 		IMPORT_C TUint32 InsertL(TInt16 aValue);
       
   212 
       
   213         /**
       
   214         * Insert TUint16 value to serialized buffer and move buffer's position 
       
   215         * to after inserted value.
       
   216         * @param aValue value to be insert to current position
       
   217         * @return new buffer position
       
   218         */
       
   219 		IMPORT_C TUint32 InsertL(TUint16 aValue);
       
   220 
       
   221         /**
       
   222         * Insert TInt32 value to serialized buffer and move buffer's position 
       
   223         * to after inserted value.
       
   224         * @param aValue value to be insert to current position
       
   225         * @return new buffer position
       
   226         */
       
   227 		IMPORT_C TUint32 InsertL(TInt32 aValue);
       
   228 
       
   229         /**
       
   230         * Insert TUint32 value to serialized buffer and move buffer's position 
       
   231         * to after inserted value.
       
   232         * @param aValue value to be insert to current position
       
   233         * @return new buffer position
       
   234         */
       
   235 		IMPORT_C TUint32 InsertL(TUint32 aValue);
       
   236 
       
   237         /**
       
   238         * Insert TUint value to serialized buffer and move buffer's position 
       
   239         * to after inserted value.
       
   240         * @param aValue value to be insert to current position
       
   241         * @return new buffer position
       
   242         */
       
   243 		IMPORT_C TUint32 InsertL(TUint aValue);
       
   244 
       
   245         /**
       
   246         * Insert TInt64 value to serialized buffer and move buffer's position 
       
   247         * to after inserted value.
       
   248         * @param aValue value to be insert to current position
       
   249         * @return new buffer position
       
   250         */
       
   251 		IMPORT_C TUint32 InsertL(TInt64 aValue);
       
   252 
       
   253         /**
       
   254         * Insert TReal32 value to serialized buffer and move buffer's position 
       
   255         * to after inserted value.
       
   256         * @param aValue value to be insert to current position
       
   257         * @return new buffer position
       
   258         */
       
   259 		IMPORT_C TUint32 InsertL(TReal32 aValue);
       
   260 
       
   261         /**
       
   262         * Insert TReal64 value to serialized buffer and move buffer's position 
       
   263         * to after inserted value.
       
   264         * @param aValue value to be insert to current position
       
   265         * @return new buffer position
       
   266         */
       
   267 		IMPORT_C TUint32 InsertL(TReal64 aValue);
       
   268 
       
   269         /**
       
   270         * Insert TTime value to serialized buffer and move buffer's position 
       
   271         * to after inserted value.
       
   272         * @param aValue value to be insert to current position
       
   273         * @return new buffer position
       
   274         */
       
   275 		IMPORT_C TUint32 InsertL(TTime aValue);
       
   276 
       
   277         /**
       
   278         * Insert TDesC8 value to serialized buffer and move buffer's position 
       
   279         * to after inserted value.
       
   280         * @param aValue value to be insert to current position
       
   281         * @return new buffer position
       
   282         */
       
   283 		IMPORT_C TUint32 InsertL(TDesC8& aValue);
       
   284 
       
   285         /**
       
   286         * Insert TDesC16 value to serialized buffer and move buffer's position 
       
   287         * to after inserted value.
       
   288         * @param aValue value to be insert to current position
       
   289         * @return new buffer position
       
   290         */
       
   291 		IMPORT_C TUint32 InsertL(TDesC16& aValue);
       
   292 
       
   293 		/**
       
   294          * Insert TMdCValueUnion value to serialized buffer and move buffer's position 
       
   295          * to after inserted value.
       
   296          * @param aValue value to be insert to current position
       
   297          * @return new buffer position
       
   298          */
       
   299  		IMPORT_C TUint32 InsertL(TMdCValueUnion& aValue);
       
   300 
       
   301 		/**
       
   302          * Insert TMdCSerializationType value to serialized buffer and move buffer's position 
       
   303          * to after inserted value.
       
   304          * @param aValue value to be insert to current position
       
   305          * @param aSize size of value
       
   306          * @return new buffer position
       
   307          */
       
   308  		IMPORT_C TUint32 InsertL(TMdCSerializationType& aValue, TUint32 aSize);
       
   309 
       
   310         /**
       
   311         * Receive TBool value from serialized buffer's current position and 
       
   312         * move buffer's position to after received value.
       
   313         * @param aDestination value received from serialized buffer
       
   314         * @return new buffer position
       
   315         */
       
   316 		IMPORT_C TUint32 ReceiveL(TBool& aDestination);
       
   317 
       
   318         /**
       
   319         * Receive TInt8 value from serialized buffer's current position and 
       
   320         * move buffer's position to after received value.
       
   321         * @param aDestination value received from serialized buffer
       
   322         * @return new buffer position
       
   323         */
       
   324 		IMPORT_C TUint32 ReceiveL(TInt8& aDestination);
       
   325 
       
   326         /**
       
   327         * Receive TUint8 value from serialized buffer's current position and 
       
   328         * move buffer's position to after received value.
       
   329         * @param aDestination value received from serialized buffer
       
   330         * @return new buffer position
       
   331         */
       
   332 		IMPORT_C TUint32 ReceiveL(TUint8& aDestination);
       
   333 
       
   334         /**
       
   335         * Receive TInt16 value from serialized buffer's current position and 
       
   336         * move buffer's position to after received value.
       
   337         * @param aDestination value received from serialized buffer
       
   338         * @return new buffer position
       
   339         */
       
   340 		IMPORT_C TUint32 ReceiveL(TInt16& aDestination);
       
   341 
       
   342         /**
       
   343         * Receive TUint16 value from serialized buffer's current position and 
       
   344         * move buffer's position to after received value.
       
   345         * @param aDestination value received from serialized buffer
       
   346         * @return new buffer position
       
   347         */
       
   348 		IMPORT_C TUint32 ReceiveL(TUint16& aDestination);
       
   349 
       
   350         /**
       
   351         * Receive TInt32 value from serialized buffer's current position and 
       
   352         * move buffer's position to after received value.
       
   353         * @param aDestination value received from serialized buffer
       
   354         * @return new buffer position
       
   355         */
       
   356 		IMPORT_C TUint32 ReceiveL(TInt32& aDestination);
       
   357 
       
   358         /**
       
   359         * Receive TUint32 value from serialized buffer's current position and 
       
   360         * move buffer's position to after received value.
       
   361         * @param aDestination value received from serialized buffer
       
   362         * @return new buffer position
       
   363         */
       
   364 		IMPORT_C TUint32 ReceiveL(TUint32& aDestination);
       
   365 
       
   366         /**
       
   367         * Receive TInt64 value from serialized buffer's current position and 
       
   368         * move buffer's position to after received value.
       
   369         * @param aDestination value received from serialized buffer
       
   370         * @return new buffer position
       
   371         */
       
   372 		IMPORT_C TUint32 ReceiveL(TInt64& aDestination);
       
   373 
       
   374         /**
       
   375         * Receive TUint value from serialized buffer's current position and 
       
   376         * move buffer's position to after received value.
       
   377         * @param aDestination value received from serialized buffer
       
   378         * @return new buffer position
       
   379         */
       
   380 		IMPORT_C TUint32 ReceiveL(TUint& aDestination);
       
   381 
       
   382         /**
       
   383         * Receive TReal32 value from serialized buffer's current position and 
       
   384         * move buffer's position to after received value.
       
   385         * @param aDestination value received from serialized buffer
       
   386         * @return new buffer position
       
   387         */
       
   388 		IMPORT_C TUint32 ReceiveL(TReal32& aDestination);
       
   389 
       
   390         /**
       
   391         * Receive TReal64 value from serialized buffer's current position and 
       
   392         * move buffer's position to after received value.
       
   393         * @param aDestination value received from serialized buffer
       
   394         * @return new buffer position
       
   395         */
       
   396 		IMPORT_C TUint32 ReceiveL(TReal64& aDestination);
       
   397 
       
   398         /**
       
   399         * Receive TTime value from serialized buffer's current position and 
       
   400         * move buffer's position to after received value.
       
   401         * @param aDestination value received from serialized buffer
       
   402         * @return new buffer position
       
   403         */
       
   404 		IMPORT_C TUint32 ReceiveL(TTime& aDestination);
       
   405 
       
   406         /**
       
   407          * Receive TMdCValueUnion value from serialized buffer's current position and 
       
   408          * move buffer's position to after received value.
       
   409          * @param aDestination value received from serialized buffer
       
   410          * @return new buffer position
       
   411          */
       
   412  		IMPORT_C TUint32 ReceiveL(TMdCValueUnion& aDestination);
       
   413 
       
   414 		/**
       
   415          * Receive TMdCSerializationType value from serialized buffer's current position and 
       
   416          * move buffer's position to after received value.
       
   417          * @param aDestination value received from serialized buffer
       
   418          * @param aSize size of value
       
   419          * @return new buffer position
       
   420          */
       
   421  		IMPORT_C TUint32 ReceiveL(TMdCSerializationType& aDestination, TUint32 aSize);
       
   422 
       
   423         /**
       
   424         * Receive the length of descriptor which is in the current position of
       
   425         * the serialized buffer. (Current position of the buffer will not change.)
       
   426         * @return the length of descriptor
       
   427         */
       
   428 		IMPORT_C TSerializedDesLength ReceiveDesciptorLength() const;
       
   429 
       
   430         /**
       
   431         * Receive 8-bit descriptor value from serialized buffer's current 
       
   432         * position and move buffer's position to after received value.
       
   433         * @param aDestination value received from serialized buffer
       
   434         * @return new buffer position
       
   435         */
       
   436 		IMPORT_C TUint32 ReceiveL(TDes8& aDestination);
       
   437 
       
   438         /**
       
   439         * Receive 16-bit descriptor value from serialized buffer's current 
       
   440         * position and move buffer's position to after received value.
       
   441         * @param aDestination value received from serialized buffer
       
   442         * @return new buffer position
       
   443         */
       
   444 		IMPORT_C TUint32 ReceiveL(TDes16& aDestination);
       
   445 
       
   446         /**
       
   447         * Receive 8-bit descriptor value from serialized buffer's current 
       
   448         * position and move buffer's position to after received value.
       
   449         * @return descriptor buffer, which must be destroyed by receiver
       
   450         */
       
   451 		IMPORT_C HBufC8* ReceiveDes8L();
       
   452 
       
   453         /**
       
   454         * Receive 16-bit descriptor value from serialized buffer's current 
       
   455         * position and move buffer's position to after received value.
       
   456         * @return descriptor buffer, which must be destroyed by receiver
       
   457         */
       
   458 		IMPORT_C HBufC16* ReceiveDes16L();
       
   459 
       
   460         /**
       
   461         * Receive pointer to 8-bit descriptor value from serialized buffer's
       
   462         * current position and move buffer's position to after received value.
       
   463         * @return descriptor pointer
       
   464         */
       
   465 		IMPORT_C TPtrC8 ReceivePtr8L();
       
   466 
       
   467         /**
       
   468         * Receive pointer to 16-bit descriptor value from serialized buffer's
       
   469         * current position and move buffer's position to after received value.
       
   470         * @return descriptor pointer
       
   471         */
       
   472 		IMPORT_C TPtrC16 ReceivePtr16L();
       
   473 
       
   474     private:
       
   475 
       
   476         /**
       
   477         * Default constructor
       
   478         */
       
   479         CMdCSerializationBuffer();
       
   480 
       
   481         /**
       
   482         * 2nd phase constructor
       
   483         * @param aInitialSize size of the buffer
       
   484         */
       
   485         void ConstructL( TInt32 aSize );
       
   486 
       
   487         /**
       
   488         * 2nd phase constructor
       
   489         * @param aInitialSize pointer to the buffer
       
   490         * @param aInitialSize size of the buffer
       
   491         */
       
   492         void ConstructL( TUint8* aBuffer, TInt32 aSize );
       
   493 
       
   494 	#ifdef _DEBUG
       
   495         void InsertTypeL( TUint16 aType );
       
   496 		#define INSERTTYPE(A) InsertTypeL( (TUint16)A );
       
   497 
       
   498         void CheckTypeL( TUint16 aType );
       
   499 		#define CHECKTYPE(A) CheckTypeL( (TUint16)A );
       
   500         
       
   501         const TDesC& GetPropertyName( TUint16 aType );
       
   502 	#else
       
   503 	#define INSERTTYPE(A)
       
   504 	#define CHECKTYPE(A)
       
   505 	#endif
       
   506 
       
   507     private:
       
   508 
       
   509         /**
       
   510         * The heap buffer
       
   511         */
       
   512         HBufC8* iHeapBuffer;
       
   513 
       
   514         /**
       
   515         * The pointer to buffer
       
   516         */
       
   517         TPtr8 iBuffer;
       
   518 
       
   519         /**
       
   520         * Current position of the buffer
       
   521         */
       
   522         TUint32 iPosition;
       
   523 	};
       
   524 
       
   525 	
       
   526 /**
       
   527  * definitions belongs to querycriteria(de)serialization
       
   528  * files: mdsquerycriteriadeserialization.h, mdequerycriteriaserialization.h
       
   529  */
       
   530 const TUint32 KOffsetResultMode = 0; // The begin of the buffer
       
   531 const TUint32 KOffsetQueryType = KOffsetResultMode + CMdCSerializationBuffer::KRequiredSizeForTInt32;
       
   532 const TUint32 KOffsetNamespaceDefId = KOffsetQueryType + CMdCSerializationBuffer::KRequiredSizeForTDefId;
       
   533 const TUint32 KOffsetObjectDefId = KOffsetNamespaceDefId + CMdCSerializationBuffer::KRequiredSizeForTDefId;
       
   534 const TUint32 KOffsetObjectDefsIds = KOffsetObjectDefId + CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   535 const TUint32 KOffsetLimit = KOffsetObjectDefsIds + CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   536 const TUint32 KOffsetOffset = KOffsetLimit + CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   537 const TUint32 KOffsetOptimizationFlags = KOffsetOffset + CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   538 const TUint32 KOffsetRootCondition = KOffsetOptimizationFlags + CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   539 const TUint32 KOffsetOrderRules = KOffsetRootCondition + CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   540 const TUint32 KOffsetPropertyFilters = KOffsetOrderRules + CMdCSerializationBuffer::KRequiredSizeForTUint32;
       
   541 
       
   542 	
       
   543 
       
   544 #endif // __MDCSERIALIZATIONBUFFER_H__