ObjFW  Check-in [19f5a60438]

Overview
Comment:Update to BinaryPack1pre1.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: 19f5a604385f4c13dc6ebb95d806d66984e33f2b2581daf9e4873c643626d62f
User & Date: js on 2013-02-23 10:03:02
Other Links: manifest | tags
Context
2013-02-23
18:00
Disallow \u0000 in JSON and fix ObjFW.h. check-in: 9c24db3c6d user: js tags: trunk
10:03
Update to BinaryPack1pre1. check-in: 19f5a60438 user: js tags: trunk
2013-02-22
12:15
Print an error when OFApplication is subclassed. check-in: fb79b7f369 user: js tags: trunk
Changes

Modified src/OFDataArray+BinaryPackValue.m from [05bf2af151] to [2abd788e61].

152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
	}
	if ((buffer[0] & 0xE0) == 0xE0) {
		*object = [OFNumber numberWithInt8:
		    ((int8_t)(buffer[0] & 0x1F)) - 32];
		return 1;
	}

	/* Data */
	if ((buffer[0] & 0xF0) == 0xA0) {
		count = buffer[0] & 0xF;

		if (length < count + 1)
			goto error;

		*object = [OFDataArray dataArrayWithItemSize: 1
						    capacity: count];
		[*object addItems: buffer + 1
			    count: count];

		return count + 1;
	}

	/* String */
	if ((buffer[0] & 0xF0) == 0xB0) {
		count = buffer[0] & 0xF;

		if (length < count + 1)
			goto error;

		*object = [OFString
		    stringWithUTF8String: (const char*)buffer + 1
				  length: count];







<
<
<
<
<
<
<
<
<
<
<
<
<
<
<

|
|







152
153
154
155
156
157
158















159
160
161
162
163
164
165
166
167
168
	}
	if ((buffer[0] & 0xE0) == 0xE0) {
		*object = [OFNumber numberWithInt8:
		    ((int8_t)(buffer[0] & 0x1F)) - 32];
		return 1;
	}
















	/* String */
	if ((buffer[0] & 0xE0) == 0xA0) {
		count = buffer[0] & 0x1F;

		if (length < count + 1)
			goto error;

		*object = [OFString
		    stringWithUTF8String: (const char*)buffer + 1
				  length: count];
286
287
288
289
290
291
292















293
294
295
296
297
298
299
		*object = [OFNumber numberWithBool: NO];
		return 1;
	/* true */
	case 0xC3:
		*object = [OFNumber numberWithBool: YES];
		return 1;
	/* Data */















	case 0xDA:
		if (length < 3)
			goto error;

		count = read_uint16(buffer + 1);

		if (length < count + 3)







>
>
>
>
>
>
>
>
>
>
>
>
>
>
>







271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
		*object = [OFNumber numberWithBool: NO];
		return 1;
	/* true */
	case 0xC3:
		*object = [OFNumber numberWithBool: YES];
		return 1;
	/* Data */
	case 0xD9:
		if (length < 2)
			goto error;

		count = buffer[1];

		if (length < count + 2)
			goto error;

		*object = [OFDataArray dataArrayWithItemSize: 1
						    capacity: count];
		[*object addItems: buffer + 2
			    count: count];

		return count + 2;
	case 0xDA:
		if (length < 3)
			goto error;

		count = read_uint16(buffer + 1);

		if (length < count + 3)
317
318
319
320
321
322
323
324













325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
		*object = [OFDataArray dataArrayWithItemSize: 1
						    capacity: count];
		[*object addItems: buffer + 5
			    count: count];

		return count + 5;
	/* Strings */
	case 0xD8:













		if (length < 3)
			goto error;

		count = read_uint16(buffer + 1);

		if (length < count + 3)
			goto error;

		*object = [OFString
		    stringWithUTF8String: (const char*)buffer + 3
				  length: count];
		return count + 3;
	case 0xD9:
		if (length < 5)
			goto error;

		count = read_uint32(buffer + 1);

		if (length < count + 5)
			goto error;







|
>
>
>
>
>
>
>
>
>
>
>
>
>












|







317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
		*object = [OFDataArray dataArrayWithItemSize: 1
						    capacity: count];
		[*object addItems: buffer + 5
			    count: count];

		return count + 5;
	/* Strings */
	case 0xD6:
		if (length < 2)
			goto error;

		count = buffer[1];

		if (length < count + 2)
			goto error;

		*object = [OFString
		    stringWithUTF8String: (const char*)buffer + 2
				  length: count];
		return count + 2;
	case 0xD7:
		if (length < 3)
			goto error;

		count = read_uint16(buffer + 1);

		if (length < count + 3)
			goto error;

		*object = [OFString
		    stringWithUTF8String: (const char*)buffer + 3
				  length: count];
		return count + 3;
	case 0xD8:
		if (length < 5)
			goto error;

		count = read_uint32(buffer + 1);

		if (length < count + 5)
			goto error;

Modified src/OFDataArray.m from [20c52d7bc7] to [0daf2b33bf].

622
623
624
625
626
627
628
629

630
631
632
633
634

635
636
637
638
639
640
641
	OFDataArray *data;

	if (_itemSize != 1)
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	if (_count <= 15) {

		uint8_t tmp = 0xA0 | ((uint8_t)_count & 0xF);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: _count + 1];


		[data addItem: &tmp];
	} else if (_count <= UINT16_MAX) {
		uint8_t type = 0xDA;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)_count);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: _count + 3];







|
>
|


|

>







622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
	OFDataArray *data;

	if (_itemSize != 1)
		@throw [OFInvalidArgumentException
		    exceptionWithClass: [self class]
			      selector: _cmd];

	if (_count <= UINT8_MAX) {
		uint8_t type = 0xD9;
		uint8_t tmp = (uint8_t)_count;

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: _count + 2];

		[data addItem: &type];
		[data addItem: &tmp];
	} else if (_count <= UINT16_MAX) {
		uint8_t type = 0xDA;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)_count);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: _count + 3];

Modified src/OFString.m from [e8f0aa0e9e] to [d8fe56c8e7].

1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605









1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
- (OFDataArray*)binaryPackRepresentation
{
	OFDataArray *data;
	size_t length;

	length = [self UTF8StringLength];

	if (length <= 15) {
		uint8_t tmp = 0xB0 | ((uint8_t)length & 0xF);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: length + 1];

		[data addItem: &tmp];









	} else if (length <= UINT16_MAX) {
		uint8_t type = 0xD8;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)length);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: length + 3];

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else if (length <= UINT32_MAX) {
		uint8_t type = 0xD9;
		uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)length);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: length + 5];

		[data addItem: &type];
		[data addItems: &tmp







|
|





>
>
>
>
>
>
>
>
>

|









|







1592
1593
1594
1595
1596
1597
1598
1599
1600
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
1613
1614
1615
1616
1617
1618
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
- (OFDataArray*)binaryPackRepresentation
{
	OFDataArray *data;
	size_t length;

	length = [self UTF8StringLength];

	if (length <= 31) {
		uint8_t tmp = 0xA0 | ((uint8_t)length & 0x1F);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: length + 1];

		[data addItem: &tmp];
	} else if (length <= UINT8_MAX) {
		uint8_t type = 0xD6;
		uint8_t tmp = (uint8_t)length;

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: length + 2];

		[data addItem: &type];
		[data addItem: &tmp];
	} else if (length <= UINT16_MAX) {
		uint8_t type = 0xD7;
		uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)length);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: length + 3];

		[data addItem: &type];
		[data addItems: &tmp
			 count: sizeof(tmp)];
	} else if (length <= UINT32_MAX) {
		uint8_t type = 0xD8;
		uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)length);

		data = [OFDataArray dataArrayWithItemSize: 1
						 capacity: length + 5];

		[data addItem: &type];
		[data addItems: &tmp