crashanalysercmd/PerfToolsSharedLibraries/Engine/SymbianUtils/MarshallingUtils/MarshalHelper.cs
equal
deleted
inserted
replaced
|
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: |
|
15 * |
|
16 */ |
|
17 using System; |
|
18 using System.Collections.Generic; |
|
19 using System.Text; |
|
20 using System.Text.RegularExpressions; |
|
21 using System.IO; |
|
22 using System.Runtime.InteropServices; |
|
23 |
|
24 namespace SymbianUtils.MarshallingUtils |
|
25 { |
|
26 public static class MarshalHelper |
|
27 { |
|
28 #region Constructors |
|
29 #endregion |
|
30 |
|
31 #region API |
|
32 public static T Read<T>( byte[] aData ) |
|
33 { |
|
34 return Read<T>( aData, 0 ); |
|
35 } |
|
36 |
|
37 public static T Read<T>( byte[] aData, int aOffset ) |
|
38 { |
|
39 int size = Marshal.SizeOf( typeof( T ) ); |
|
40 |
|
41 byte[] buffer = new byte[ size ]; |
|
42 for ( int i = 0; i < buffer.Length; i++ ) |
|
43 { |
|
44 int pos = aOffset + i; |
|
45 buffer[ i ] = aData[ pos ]; |
|
46 } |
|
47 |
|
48 GCHandle handle = GCHandle.Alloc( buffer, GCHandleType.Pinned ); |
|
49 T ret = (T) Marshal.PtrToStructure( handle.AddrOfPinnedObject(), typeof( T ) ); |
|
50 handle.Free(); |
|
51 |
|
52 return ret; |
|
53 } |
|
54 #endregion |
|
55 |
|
56 #region Properties |
|
57 #endregion |
|
58 |
|
59 #region Internal methods |
|
60 #endregion |
|
61 |
|
62 #region Data members |
|
63 #endregion |
|
64 } |
|
65 } |