|
1 // Copyright (c) 1997-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // Packet Info Headers |
|
15 // |
|
16 // |
|
17 |
|
18 #include <nifmbuf.h> |
|
19 |
|
20 EXPORT_C TMBufMark::TMBufMark() |
|
21 { |
|
22 iMBuf = NULL; |
|
23 iPtr = 0; |
|
24 iOffset = -1; |
|
25 } |
|
26 |
|
27 EXPORT_C TMBufMark::TMBufMark(const TMBufMark& aParser) |
|
28 { |
|
29 iMBuf = aParser.iMBuf; |
|
30 iPtr = aParser.iPtr; |
|
31 iOffset = aParser.iOffset; |
|
32 } |
|
33 |
|
34 EXPORT_C TMBufMark::TMBufMark(const RMBufChain& aChain, TInt aOffset/*=0*/) |
|
35 { |
|
36 Set(aChain, aOffset); |
|
37 } |
|
38 |
|
39 EXPORT_C void TMBufMark::Set(const RMBufChain& aChain, TInt aOffset) |
|
40 { |
|
41 iOffset = aOffset; |
|
42 if (aOffset!=0) |
|
43 { |
|
44 TInt n, o; |
|
45 aChain.Goto(aOffset, iMBuf, o, n); |
|
46 iPtr = o-iMBuf->Offset(); |
|
47 } |
|
48 else |
|
49 { |
|
50 iMBuf = (RMBuf*)aChain.First(); |
|
51 iPtr = 0; |
|
52 } |
|
53 } |
|
54 |
|
55 EXPORT_C void TMBufMark::Skip(TInt aLength) |
|
56 // |
|
57 // Skip over data |
|
58 // |
|
59 { |
|
60 while (aLength>0 && iMBuf!=NULL) |
|
61 { |
|
62 TInt n = Min(iMBuf->Length()-iPtr, aLength); |
|
63 aLength -= n; |
|
64 iOffset += n; |
|
65 iPtr += n; |
|
66 if (iPtr>iMBuf->Length()) |
|
67 { |
|
68 iPtr = 0; |
|
69 iMBuf = iMBuf->Next(); |
|
70 } |
|
71 } |
|
72 } |
|
73 |
|
74 EXPORT_C void TMBufMark::Get(TDes8& aBuf) |
|
75 // |
|
76 // Get data into a descriptor |
|
77 // |
|
78 { |
|
79 TInt len = aBuf.Length(); |
|
80 TUint8* ptr = (TUint8*)aBuf.Ptr(); |
|
81 |
|
82 while (len>0 && iMBuf!=NULL) |
|
83 { |
|
84 TInt n = Min(iMBuf->Length()-iPtr, len); |
|
85 Mem::Copy(ptr, iMBuf->Ptr()+iPtr, n); |
|
86 len -= n; |
|
87 ptr += n; |
|
88 iOffset += n; |
|
89 iPtr += n; |
|
90 if (iPtr>iMBuf->Length()) |
|
91 { |
|
92 iPtr = 0; |
|
93 iMBuf = iMBuf->Next(); |
|
94 } |
|
95 } |
|
96 if (len>0) |
|
97 aBuf.SetLength(aBuf.Length()-len); |
|
98 } |
|
99 |
|
100 EXPORT_C void TMBufMark::Get(TUint8* aPtr, TInt aLen) |
|
101 // |
|
102 // Get data into a buffer |
|
103 // |
|
104 { |
|
105 while (aLen>0 && iMBuf!=NULL) |
|
106 { |
|
107 TInt n = Min(iMBuf->Length()-iPtr, aLen); |
|
108 Mem::Copy(aPtr, iMBuf->Ptr()+iPtr, n); |
|
109 aLen -= n; |
|
110 aPtr += n; |
|
111 iOffset += n; |
|
112 iPtr += n; |
|
113 if (iPtr>iMBuf->Length()) |
|
114 { |
|
115 iPtr = 0; |
|
116 iMBuf = iMBuf->Next(); |
|
117 } |
|
118 } |
|
119 } |