blob: 492b436c5e0d0c5e8ea891ce9ab0a7de5a817eed [file] [log] [blame]
liubin281ac462023-07-19 14:22:54 +08001/*==============================================================================
2
3 ds_ASBuffer.h
4
5GENERAL DESCRIPTION
6 A buffer class with utility functions for parsing raw bytes.
7
8EXTERNALIZED FUNCTIONS
9
10INITIALIZATION AND SEQUENCING REQUIREMENTS
11
12 Copyright (c) 2014 by Qualcomm Technologies Incorporated. All Rights Reserved.
13==============================================================================*/
14
15/*==============================================================================
16 EDIT HISTORY FOR MODULE
17
18This section contains comments describing changes made to the module.
19Notice that changes are listed in reverse chronological order.
20
21when who what, where, why
22-------- --- ----------------------------------------------------------
2304/21/14 ml Created file/Initial version.
24==============================================================================*/
25
26#ifndef __DS_AS_BUFFER_H__
27#define __DS_AS_BUFFER_H__
28
29//#include "comdef.h"
30#include "mbtk_type.h"
31class ASString;
32
33
34/*==============================================================================
35CLASS ASBuffer
36
37DESCRIPTION
38 A buffer class with utility functions for parsing raw bytes.
39==============================================================================*/
40class ASBuffer
41{
42public:
43 /*===========================================================================
44 FUNCTION ASBuffer CONSTRUCTOR
45
46 DESCRIPTION
47 Creates a new ASBuffer.
48
49 DEPENDENCIES
50 capacity - The initial buffer capacity to set.
51
52 SIDE EFFECTS
53 None
54 ===========================================================================*/
55 ASBuffer();
56 ASBuffer(uint32 capacity);
57
58 ASBuffer(ASBuffer &buf);
59 ASBuffer(const ASBuffer &buf);
60 ASBuffer(const uint8* buf, uint32 capacity);
61
62 ~ASBuffer();
63
64
65 ASBuffer& operator=(const ASBuffer &rhs);
66
67 /*============================================================================
68 FUNCTION ASBuffer::content
69
70 DESCRIPTION
71 Returns a pointer to the buffer content
72
73 PARAMETERS
74 None
75
76 DEPENDENCIES
77 None
78
79 SIDE EFFECTS
80 None
81 ============================================================================*/
82 const uint8* content() const;
83
84
85
86 /*============================================================================
87 FUNCTION ASBuffer::non_const_content
88
89 DESCRIPTION
90 Returns a pointer to the buffer content. Use this function ONLY if you need
91 a non-const version and it is guaranteed that the returned pointer will
92 never be modified.
93
94 Note: Workaround function for MD5 auth-int. Otherwise shouldn't be used.
95
96 PARAMETERS
97 None
98
99 DEPENDENCIES
100 None
101
102 SIDE EFFECTS
103 None
104 ============================================================================*/
105 uint8* non_const_content();
106
107
108
109 /*============================================================================
110 FUNCTION ASBuffer::c_str
111
112 DESCRIPTION
113 Returns a pointer to the buffer content. This assumes the buffer content is
114 in c-string format
115
116 PARAMETERS
117 None
118
119 DEPENDENCIES
120 None
121
122 SIDE EFFECTS
123 None
124 ============================================================================*/
125 const char* c_str() const;
126
127
128
129 /*============================================================================
130 FUNCTION ASBuffer::size
131
132 DESCRIPTION
133 Returns the size of the buffer
134
135 PARAMETERS
136 None
137
138 DEPENDENCIES
139 None
140
141 SIDE EFFECTS
142 None
143 ============================================================================*/
144 uint32 size() const;
145
146
147
148 /*============================================================================
149 FUNCTION ASBuffer::empty
150
151 DESCRIPTION
152 Returns true if the buffer is empty
153
154 PARAMETERS
155 None
156
157 DEPENDENCIES
158 None
159
160 SIDE EFFECTS
161 None
162 ============================================================================*/
163 bool empty() const;
164
165
166
167 /*============================================================================
168 FUNCTION ASBuffer::error
169
170 DESCRIPTION
171 Returns true if the buffer is in error status due to internal memory
172 allocation failure.
173
174 This can happen when
175 - Constructor fails to allocate memory for the new buffer
176 - Append requires to resize the buffer but fails
177
178 PARAMETERS
179 None
180
181 DEPENDENCIES
182 None
183
184 SIDE EFFECTS
185 None
186 ============================================================================*/
187 bool error() const;
188
189
190
191 /*============================================================================
192 FUNCTION ASBuffer::append
193
194 DESCRIPTION
195 Appends the given data to the buffer. Returns true if append is successful,
196 false if append fails.
197
198 PARAMETERS
199 [In] append_buffer - The data to append
200 [In] size - The number of bytes to append
201
202 DEPENDENCIES
203 None
204
205 SIDE EFFECTS
206 None
207 ============================================================================*/
208 bool append(const uint8* append_buffer, const uint32 size);
209 bool append(const char append_buffer);
210 bool append(const char* append_buffer);
211 bool append(const char* append_buffer, const uint32 size);
212 bool append(const ASBuffer& append_buffer);
213 bool append(const ASString& append_buffer); // temp
214
215
216 /*============================================================================
217 FUNCTION ASBuffer::clear
218
219 DESCRIPTION
220 Returns true if the buffer is in error status due to internal memory
221 allocation failure.
222
223 This can happen when
224 - Constructor fails to allocate memory for the new buffer
225 - Append requires to resize the buffer but fails
226
227 PARAMETERS
228 None
229
230 DEPENDENCIES
231 None
232
233 SIDE EFFECTS
234 None
235 ============================================================================*/
236 void clear();
237
238
239
240private:
241 /*============================================================================
242 FUNCTION ASBuffer::init
243
244 DESCRIPTION
245 Initialize buffer
246
247 PARAMETERS
248 None
249
250 DEPENDENCIES
251 None
252
253 SIDE EFFECTS
254 None
255 ============================================================================*/
256 void init();
257 bool increment_buffer_capacity(const uint32 req_size);
258
259
260 uint8* buffer; // Buffer object. Memory dynamically allocated as necessary
261 uint32 buffer_size;
262 uint32 buffer_capacity;
263 bool error_status; // true if error, else false
264};
265
266
267
268#endif /* __DS_AS_BUFFER_H__ */