︙ | | |
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
-
+
-
+
|
* file.
*/
#include "config.h"
#include <string.h>
#import "OFData+MessagePackValue.h"
#import "OFData+MessagePackParsing.h"
#import "OFArray.h"
#import "OFDate.h"
#import "OFDictionary.h"
#import "OFMessagePackExtension.h"
#import "OFNull.h"
#import "OFNumber.h"
#import "OFString.h"
#import "OFInvalidArgumentException.h"
#import "OFInvalidFormatException.h"
#import "OFOutOfRangeException.h"
#import "OFTruncatedDataException.h"
int _OFData_MessagePackValue_reference;
int _OFData_MessagePackParsing_reference;
static size_t parseObject(const unsigned char *buffer, size_t length,
id *object, size_t depthLimit);
static uint16_t
readUInt16(const unsigned char *buffer)
{
|
︙ | | |
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
|
-
+
-
+
|
OFData *data;
if (length < 1)
@throw [OFTruncatedDataException exception];
/* positive fixint */
if ((buffer[0] & 0x80) == 0) {
*object = [OFNumber numberWithUInt8: buffer[0] & 0x7F];
*object = [OFNumber numberWithUnsignedChar: buffer[0] & 0x7F];
return 1;
}
/* negative fixint */
if ((buffer[0] & 0xE0) == 0xE0) {
*object = [OFNumber numberWithInt8:
*object = [OFNumber numberWithChar:
((int8_t)(buffer[0] & 0x1F)) - 32];
return 1;
}
/* fixstr */
if ((buffer[0] & 0xE0) == 0xA0) {
count = buffer[0] & 0x1F;
|
︙ | | |
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
|
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
|
-
+
-
+
+
-
+
+
-
+
+
-
+
-
+
-
+
-
+
|
/* Prefix byte */
switch (buffer[0]) {
/* Unsigned integers */
case 0xCC: /* uint8 */
if (length < 2)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithUInt8: buffer[1]];
*object = [OFNumber numberWithUnsignedChar: buffer[1]];
return 2;
case 0xCD: /* uint 16 */
if (length < 3)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithUInt16: readUInt16(buffer + 1)];
*object = [OFNumber numberWithUnsignedShort:
readUInt16(buffer + 1)];
return 3;
case 0xCE: /* uint 32 */
if (length < 5)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithUInt32: readUInt32(buffer + 1)];
*object = [OFNumber numberWithUnsignedLong:
readUInt32(buffer + 1)];
return 5;
case 0xCF: /* uint 64 */
if (length < 9)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithUInt64: readUInt64(buffer + 1)];
*object = [OFNumber numberWithUnsignedLongLong:
readUInt64(buffer + 1)];
return 9;
/* Signed integers */
case 0xD0: /* int 8 */
if (length < 2)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithInt8: buffer[1]];
*object = [OFNumber numberWithChar: buffer[1]];
return 2;
case 0xD1: /* int 16 */
if (length < 3)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithInt16: readUInt16(buffer + 1)];
*object = [OFNumber numberWithShort: readUInt16(buffer + 1)];
return 3;
case 0xD2: /* int 32 */
if (length < 5)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithInt32: readUInt32(buffer + 1)];
*object = [OFNumber numberWithLong: readUInt32(buffer + 1)];
return 5;
case 0xD3: /* int 64 */
if (length < 9)
@throw [OFTruncatedDataException exception];
*object = [OFNumber numberWithInt64: readUInt64(buffer + 1)];
*object = [OFNumber numberWithLongLong: readUInt64(buffer + 1)];
return 9;
/* Floating point */
case 0xCA:; /* float 32 */
float f;
if (length < 5)
@throw [OFTruncatedDataException exception];
|
︙ | | |
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
|
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
|
-
-
+
+
-
+
-
+
|
return parseTable(buffer + 5, length - 5, object,
readUInt32(buffer + 1), depthLimit) + 5;
default:
@throw [OFInvalidFormatException exception];
}
}
@implementation OFData (MessagePackValue)
- (id)messagePackValue
@implementation OFData (MessagePackParsing)
- (id)objectByParsingMessagePack
{
return [self messagePackValueWithDepthLimit: 32];
return [self objectByParsingMessagePackWithDepthLimit: 32];
}
- (id)messagePackValueWithDepthLimit: (size_t)depthLimit
- (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit
{
void *pool = objc_autoreleasePoolPush();
size_t count = self.count;
id object;
if (self.itemSize != 1)
@throw [OFInvalidArgumentException exception];
|
︙ | | |