Comment: | Add support for generating BinaryPack. |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
23c798d4f1f2b413c485438d102027e2 |
User & Date: | js on 2013-02-21 19:35:34 |
Other Links: | manifest | tags |
2013-02-22
| ||
11:32 | Fix ObjC++. check-in: 09bd870f8c user: js tags: trunk | |
2013-02-21
| ||
19:35 | Add support for generating BinaryPack. check-in: 23c798d4f1 user: js tags: trunk | |
16:15 | Add support for parsing BinaryPack. check-in: 12f091ddd6 user: js tags: trunk | |
Modified src/Makefile from [a491e2b6e2] to [4e8a943706].
︙ | ︙ | |||
78 79 80 81 82 83 84 | OFMutex.m \ OFRecursiveMutex.m \ OFThread.m \ OFThreadPool.m \ OFTLSKey.m INCLUDES_THREADS = threading.h | | > | | | | | | | | | | | | | | | 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 | OFMutex.m \ OFRecursiveMutex.m \ OFThread.m \ OFThreadPool.m \ OFTLSKey.m INCLUDES_THREADS = threading.h INCLUDES := ${SRCS:.m=.h} \ OFBinaryPackRepresentation.h \ OFCollection.h \ OFHash.h \ OFJSONRepresentation.h \ OFLocking.h \ OFSerialization.h \ OFTLSSocket.h \ ObjFW.h \ asprintf.h \ autorelease.h \ ${ATOMIC_H} \ block.h \ instance.h \ macros.h \ objfw-defs.h \ ${USE_INCLUDES_THREADS} SRCS += OFArray_adjacent.m \ OFArray_adjacentSubarray.m \ ${AUTORELEASE_M} \ ${INSTANCE_M} \ OFCountedSet_hashtable.m \ |
︙ | ︙ |
Modified src/OFArray.h from [831aff56f7] to [fbd6a9a1ad].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <stdarg.h> #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" @class OFString; enum { OF_SORT_OPTIONS_DESCENDING = 1 }; #ifdef OF_HAVE_BLOCKS typedef void (^of_array_enumeration_block_t)(id object, size_t index, BOOL *stop); typedef BOOL (^of_array_filter_block_t)(id odject, size_t index); typedef id (^of_array_map_block_t)(id object, size_t index); typedef id (^of_array_fold_block_t)(id left, id right); #endif /*! * @brief An abstract class for storing objects in an array. */ @interface OFArray: OFObject <OFCopying, OFMutableCopying, OFCollection, | > | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include <stdarg.h> #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" #import "OFBinaryPackRepresentation.h" @class OFString; enum { OF_SORT_OPTIONS_DESCENDING = 1 }; #ifdef OF_HAVE_BLOCKS typedef void (^of_array_enumeration_block_t)(id object, size_t index, BOOL *stop); typedef BOOL (^of_array_filter_block_t)(id odject, size_t index); typedef id (^of_array_map_block_t)(id object, size_t index); typedef id (^of_array_fold_block_t)(id left, id right); #endif /*! * @brief An abstract class for storing objects in an array. */ @interface OFArray: OFObject <OFCopying, OFMutableCopying, OFCollection, OFSerialization, OFJSONRepresentation, OFBinaryPackRepresentation> #ifdef OF_HAVE_PROPERTIES @property (readonly) size_t count; #endif /*! * @brief Creates a new OFArray. * |
︙ | ︙ |
Modified src/OFArray.m from [1530533acf] to [369534eb2f].
︙ | ︙ | |||
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | */ #include "config.h" #include <stdarg.h> #include <stdlib.h> #import "OFArray.h" #import "OFArray_subarray.h" #import "OFArray_adjacent.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #import "autorelease.h" #import "macros.h" | > > > | 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | */ #include "config.h" #include <stdarg.h> #include <stdlib.h> #include <assert.h> #import "OFArray.h" #import "OFArray_subarray.h" #import "OFArray_adjacent.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFDataArray.h" #import "OFEnumerationMutationException.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #import "autorelease.h" #import "macros.h" |
︙ | ︙ | |||
555 556 557 558 559 560 561 562 563 564 565 566 567 568 | [JSON makeImmutable]; objc_autoreleasePoolPop(pool); return [JSON autorelease]; } - (void)makeObjectsPerformSelector: (SEL)selector { id *objects = [self objects]; size_t i, count = [self count]; for (i = 0; i < count; i++) | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 | [JSON makeImmutable]; objc_autoreleasePoolPop(pool); return [JSON autorelease]; } - (OFDataArray*)binaryPackRepresentation { OFDataArray *data; size_t i, count; void *pool; OFEnumerator *enumerator; id object; data = [OFDataArray dataArray]; count = [self count]; if (count <= 15) { uint8_t tmp = 0x90 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDC; uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDC; uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exceptionWithClass: [self class]]; pool = objc_autoreleasePoolPush(); i = 0; enumerator = [self objectEnumerator]; while ((object = [enumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFDataArray *child; i++; child = [object binaryPackRepresentation]; [data addItems: [child items] count: [child count]]; objc_autoreleasePoolPop(pool2); } assert(i == count); objc_autoreleasePoolPop(pool); return data; } - (void)makeObjectsPerformSelector: (SEL)selector { id *objects = [self objects]; size_t i, count = [self count]; for (i = 0; i < count; i++) |
︙ | ︙ |
Added src/OFBinaryPackRepresentation.h version [c0e0f8d0e9].
> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | /* * Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013 * Jonathan Schleifer <js@webkeks.org> * * All rights reserved. * * This file is part of ObjFW. It may be distributed under the terms of the * Q Public License 1.0, which can be found in the file LICENSE.QPL included in * the packaging of this file. * * Alternatively, it may be distributed under the terms of the GNU General * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ @class OFDataArray; /*! * @brief A protocol implemented by classes that support encoding to a * BinaryPack representation. */ @protocol OFBinaryPackRepresentation /*! * @brief Returns the BinaryPack representation of the object as an OFDataArray. * * @return The BinaryPack representation of the object as an OFDataArray. */ - (OFDataArray*)binaryPackRepresentation; @end |
Modified src/OFDataArray.h from [7029647f44] to [b9fe1f5814].
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSerialization.h" @class OFString; @class OFURL; /*! * @brief A class for storing arbitrary data in an array. * * If you plan to store large hunks of data, you should consider using * OFBigDataArray, which allocates the memory in pages rather than in bytes. * * For security reasons, serialization and deserialization is only implemented * for OFDataArrays with item size 1. */ | > | > | 12 13 14 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 | * Public License, either version 2 or 3, which can be found in the file * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSerialization.h" #import "OFBinaryPackRepresentation.h" @class OFString; @class OFURL; /*! * @brief A class for storing arbitrary data in an array. * * If you plan to store large hunks of data, you should consider using * OFBigDataArray, which allocates the memory in pages rather than in bytes. * * For security reasons, serialization and deserialization is only implemented * for OFDataArrays with item size 1. */ @interface OFDataArray: OFObject <OFCopying, OFComparing, OFSerialization, OFBinaryPackRepresentation> { uint8_t *_items; size_t _count, _itemSize, _capacity; } #ifdef OF_HAVE_PROPERTIES @property (readonly) void *items; |
︙ | ︙ |
Modified src/OFDataArray.m from [786611bf27] to [20c52d7bc7].
︙ | ︙ | |||
612 613 614 615 616 617 618 619 620 621 622 623 624 625 | [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } @end @implementation OFBigDataArray - initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { size_t lastPageByte = [OFSystemInfo pageSize] - 1; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 | [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFDataArray*)binaryPackRepresentation { 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]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (_count <= UINT32_MAX) { uint8_t type = 0xDB; uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)_count); data = [OFDataArray dataArrayWithItemSize: 1 capacity: _count + 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exceptionWithClass: [self class]]; [data addItems: _items count: _count]; return data; } @end @implementation OFBigDataArray - initWithItemSize: (size_t)itemSize capacity: (size_t)capacity { size_t lastPageByte = [OFSystemInfo pageSize] - 1; |
︙ | ︙ |
Modified src/OFDictionary.h from [e73cae8cf9] to [dbe3c67ed9].
︙ | ︙ | |||
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 | #include <stdarg.h> #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" @class OFArray; #ifdef OF_HAVE_BLOCKS typedef void (^of_dictionary_enumeration_block_t)(id key, id object, BOOL *stop); typedef BOOL (^of_dictionary_filter_block_t)(id key, id object); typedef id (^of_dictionary_map_block_t)(id key, id object); #endif /*! * @brief An abstract class for storing objects in a dictionary. * * Keys are copied and thus must conform to the OFCopying protocol. * * Note: Fast enumeration on a dictionary enumerates through the keys of the * dictionary. */ @interface OFDictionary: OFObject <OFCopying, OFMutableCopying, OFCollection, | > | | 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 | #include <stdarg.h> #import "OFObject.h" #import "OFCollection.h" #import "OFEnumerator.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" #import "OFBinaryPackRepresentation.h" @class OFArray; #ifdef OF_HAVE_BLOCKS typedef void (^of_dictionary_enumeration_block_t)(id key, id object, BOOL *stop); typedef BOOL (^of_dictionary_filter_block_t)(id key, id object); typedef id (^of_dictionary_map_block_t)(id key, id object); #endif /*! * @brief An abstract class for storing objects in a dictionary. * * Keys are copied and thus must conform to the OFCopying protocol. * * Note: Fast enumeration on a dictionary enumerates through the keys of the * dictionary. */ @interface OFDictionary: OFObject <OFCopying, OFMutableCopying, OFCollection, OFSerialization, OFJSONRepresentation, OFBinaryPackRepresentation> /*! * @brief Creates a new OFDictionary. * * @return A new autoreleased OFDictionary */ + (instancetype)dictionary; |
︙ | ︙ |
Modified src/OFDictionary.m from [e919261aa6] to [bd2462ab4e].
︙ | ︙ | |||
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <assert.h> #import "OFDictionary.h" #import "OFDictionary_hashtable.h" #import "OFArray.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "autorelease.h" static struct { Class isa; } placeholder; @interface OFDictionary_placeholder: OFDictionary @end | > > > | 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | #include <assert.h> #import "OFDictionary.h" #import "OFDictionary_hashtable.h" #import "OFArray.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFDataArray.h" #import "OFInvalidArgumentException.h" #import "OFOutOfRangeException.h" #import "autorelease.h" #import "macros.h" static struct { Class isa; } placeholder; @interface OFDictionary_placeholder: OFDictionary @end |
︙ | ︙ | |||
660 661 662 663 664 665 666 667 | [JSON appendString: @"}"]; [JSON makeImmutable]; objc_autoreleasePoolPop(pool); return JSON; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | [JSON appendString: @"}"]; [JSON makeImmutable]; objc_autoreleasePoolPop(pool); return JSON; } - (OFDataArray*)binaryPackRepresentation { OFDataArray *data; size_t i, count; void *pool; OFEnumerator *keyEnumerator, *objectEnumerator; id key, object; data = [OFDataArray dataArray]; count = [self count]; if (count <= 15) { uint8_t tmp = 0x80 | ((uint8_t)count & 0xF); [data addItem: &tmp]; } else if (count <= UINT16_MAX) { uint8_t type = 0xDE; uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (count <= UINT32_MAX) { uint8_t type = 0xDF; uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)count); [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exceptionWithClass: [self class]]; pool = objc_autoreleasePoolPush(); i = 0; keyEnumerator = [self keyEnumerator]; objectEnumerator = [self objectEnumerator]; while ((key = [keyEnumerator nextObject]) != nil && (object = [objectEnumerator nextObject]) != nil) { void *pool2 = objc_autoreleasePoolPush(); OFDataArray *child; i++; child = [key binaryPackRepresentation]; [data addItems: [child items] count: [child count]]; child = [object binaryPackRepresentation]; [data addItems: [child items] count: [child count]]; objc_autoreleasePoolPop(pool2); } assert(i == count); objc_autoreleasePoolPop(pool); return data; } @end |
Modified src/OFNull.h from [630bba713d] to [ac99ec5412].
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" /*! * @brief A class for representing null values in collections. */ | > | > | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #import "OFObject.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" #import "OFBinaryPackRepresentation.h" /*! * @brief A class for representing null values in collections. */ @interface OFNull: OFObject <OFCopying, OFSerialization, OFJSONRepresentation, OFBinaryPackRepresentation> /*! * @brief Returns an OFNull singleton. * * @return An OFNull singleton */ + (OFNull*)null; @end |
Modified src/OFNull.m from [ee8c04eb41] to [096eefa101].
︙ | ︙ | |||
17 18 19 20 21 22 23 24 25 26 27 28 29 30 | #include "config.h" #include <stdlib.h> #import "OFNull.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFInvalidArgumentException.h" #import "autorelease.h" static OFNull *null = nil; | > | 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | #include "config.h" #include <stdlib.h> #import "OFNull.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFDataArray.h" #import "OFInvalidArgumentException.h" #import "autorelease.h" static OFNull *null = nil; |
︙ | ︙ | |||
83 84 85 86 87 88 89 90 91 92 93 94 95 96 | return [element autorelease]; } - (OFString*)JSONRepresentation { return @"null"; } - autorelease { return self; } - retain | > > > > > > > > > > > | 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 | return [element autorelease]; } - (OFString*)JSONRepresentation { return @"null"; } - (OFDataArray*)binaryPackRepresentation { OFDataArray *data = [OFDataArray dataArrayWithItemSize: 1 capacity: 1]; uint8_t type = 0xC0; [data addItem: &type]; return data; } - autorelease { return self; } - retain |
︙ | ︙ |
Modified src/OFNumber.h from [b3a58136c1] to [4db74b4fc5].
︙ | ︙ | |||
22 23 24 25 26 27 28 29 30 31 32 33 34 35 | #endif #include <sys/types.h> #import "OFObject.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" /*! @file */ /*! * @brief The C type of a number stored in an OFNumber. */ typedef enum of_number_type_t { | > | 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #endif #include <sys/types.h> #import "OFObject.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" #import "OFBinaryPackRepresentation.h" /*! @file */ /*! * @brief The C type of a number stored in an OFNumber. */ typedef enum of_number_type_t { |
︙ | ︙ | |||
88 89 90 91 92 93 94 | OF_NUMBER_DOUBLE = 0x40 | OF_NUMBER_FLOAT, } of_number_type_t; /*! * @brief Provides a way to store a number in an object. */ @interface OFNumber: OFObject <OFCopying, OFComparing, OFSerialization, | | | 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 | OF_NUMBER_DOUBLE = 0x40 | OF_NUMBER_FLOAT, } of_number_type_t; /*! * @brief Provides a way to store a number in an object. */ @interface OFNumber: OFObject <OFCopying, OFComparing, OFSerialization, OFJSONRepresentation, OFBinaryPackRepresentation> { union of_number_value { BOOL bool_; signed char schar; signed short sshort; signed int sint; signed long slong; |
︙ | ︙ |
Modified src/OFNumber.m from [df1e685381] to [c8342b8a79].
︙ | ︙ | |||
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "autorelease.h" #import "macros.h" #define RETURN_AS(t) \ switch (_type) { \ case OF_NUMBER_BOOL: \ | > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 | #include <math.h> #import "OFNumber.h" #import "OFString.h" #import "OFXMLElement.h" #import "OFXMLAttribute.h" #import "OFDataArray.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "autorelease.h" #import "macros.h" #define RETURN_AS(t) \ switch (_type) { \ case OF_NUMBER_BOOL: \ |
︙ | ︙ | |||
1406 1407 1408 1409 1410 1411 1412 1413 | return @"Infinity"; else return @"-Infinity"; } return [self description]; } @end | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1408 1409 1410 1411 1412 1413 1414 1415 1416 1417 1418 1419 1420 1421 1422 1423 1424 1425 1426 1427 1428 1429 1430 1431 1432 1433 1434 1435 1436 1437 1438 1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 1451 1452 1453 1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 1465 1466 1467 1468 1469 1470 1471 1472 1473 1474 1475 1476 1477 1478 1479 1480 1481 1482 1483 1484 1485 1486 1487 1488 1489 1490 1491 1492 1493 1494 1495 1496 1497 1498 1499 1500 1501 1502 1503 1504 1505 1506 1507 1508 1509 1510 1511 1512 1513 1514 1515 1516 1517 1518 1519 1520 1521 1522 1523 1524 1525 1526 1527 1528 1529 1530 1531 1532 1533 1534 1535 1536 1537 1538 1539 1540 1541 1542 1543 1544 1545 1546 1547 1548 1549 1550 1551 1552 1553 1554 1555 1556 1557 1558 1559 1560 | return @"Infinity"; else return @"-Infinity"; } return [self description]; } - (OFDataArray*)binaryPackRepresentation { OFDataArray *data; if (_type == OF_NUMBER_BOOL) { uint8_t type; data = [OFDataArray dataArrayWithItemSize: 1 capacity: 1]; if (_value.bool_) type = 0xC3; else type = 0xC2; [data addItem: &type]; } else if (_type == OF_NUMBER_FLOAT) { uint8_t type = 0xCA; float tmp = OF_BSWAP_FLOAT_IF_LE(_value.float_); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (_type == OF_NUMBER_DOUBLE) { uint8_t type = 0xCB; double tmp = OF_BSWAP_DOUBLE_IF_LE(_value.double_); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (_type & OF_NUMBER_SIGNED) { intmax_t value = [self intMaxValue]; if (value >= -32 && value < 0) { uint8_t tmp = 0xE0 | ((uint8_t)(value - 32) & 0x1F); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 1]; [data addItem: &tmp]; } else if (value >= INT8_MIN && value <= INT8_MAX) { uint8_t type = 0xD0; int8_t tmp = (int8_t)value; data = [OFDataArray dataArrayWithItemSize: 1 capacity: 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (value >= INT16_MIN && value <= INT16_MAX) { uint8_t type = 0xD1; int16_t tmp = OF_BSWAP16_IF_LE((int16_t)value); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value >= INT32_MIN && value <= INT32_MAX) { uint8_t type = 0xD2; int32_t tmp = OF_BSWAP32_IF_LE((int32_t)value); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value >= INT64_MIN && value <= INT64_MAX) { uint8_t type = 0xD3; int64_t tmp = OF_BSWAP64_IF_LE((int64_t)value); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exceptionWithClass: [self class]]; } else { uintmax_t value = [self uIntMaxValue]; if (value <= 127) { uint8_t tmp = ((uint8_t)value & 0x7F); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 1]; [data addItem: &tmp]; } else if (value <= UINT8_MAX) { uint8_t type = 0xCC; uint8_t tmp = (uint8_t)value; data = [OFDataArray dataArrayWithItemSize: 1 capacity: 2]; [data addItem: &type]; [data addItem: &tmp]; } else if (value <= UINT16_MAX) { uint8_t type = 0xCD; uint16_t tmp = OF_BSWAP16_IF_LE((uint16_t)value); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 3]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value <= UINT32_MAX) { uint8_t type = 0xCE; uint32_t tmp = OF_BSWAP32_IF_LE((uint32_t)value); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 5]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else if (value <= UINT64_MAX) { uint8_t type = 0xCF; uint64_t tmp = OF_BSWAP64_IF_LE((uint64_t)value); data = [OFDataArray dataArrayWithItemSize: 1 capacity: 9]; [data addItem: &type]; [data addItems: &tmp count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exceptionWithClass: [self class]]; } return data; } @end |
Modified src/OFString.h from [a823c4de2d] to [e626a11209].
︙ | ︙ | |||
23 24 25 26 27 28 29 30 31 32 33 34 35 36 | #include <stdarg.h> #include <inttypes.h> #import "OFObject.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" @class OFConstantString; #if defined(__cplusplus) && __cplusplus >= 201103L typedef char16_t of_char16_t; typedef char32_t of_char32_t; #else | > | 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | #include <stdarg.h> #include <inttypes.h> #import "OFObject.h" #import "OFSerialization.h" #import "OFJSONRepresentation.h" #import "OFBinaryPackRepresentation.h" @class OFConstantString; #if defined(__cplusplus) && __cplusplus >= 201103L typedef char16_t of_char16_t; typedef char32_t of_char32_t; #else |
︙ | ︙ | |||
74 75 76 77 78 79 80 | @class OFArray; @class OFURL; /*! * @brief A class for handling strings. */ @interface OFString: OFObject <OFCopying, OFMutableCopying, OFComparing, | | | 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | @class OFArray; @class OFURL; /*! * @brief A class for handling strings. */ @interface OFString: OFObject <OFCopying, OFMutableCopying, OFComparing, OFSerialization, OFJSONRepresentation, OFBinaryPackRepresentation> #ifdef OF_HAVE_PROPERTIES @property (readonly) size_t length; #endif /*! * @brief Creates a new OFString. * |
︙ | ︙ |
Modified src/OFString.m from [6fe7a945dd] to [e8f0aa0e9e].
︙ | ︙ | |||
1584 1585 1586 1587 1588 1589 1590 1591 1592 1593 1594 1595 1596 1597 | [JSON prependString: @"\""]; [JSON appendString: @"\""]; [JSON makeImmutable]; return JSON; } - (of_range_t)rangeOfString: (OFString*)string { return [self rangeOfString: string options: 0 range: of_range(0, [self length])]; } | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 1584 1585 1586 1587 1588 1589 1590 1591 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 1634 1635 1636 1637 1638 1639 1640 | [JSON prependString: @"\""]; [JSON appendString: @"\""]; [JSON makeImmutable]; return JSON; } - (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 count: sizeof(tmp)]; } else @throw [OFOutOfRangeException exceptionWithClass: [self class]]; [data addItems: [self UTF8String] count: length]; return data; } - (of_range_t)rangeOfString: (OFString*)string { return [self rangeOfString: string options: 0 range: of_range(0, [self length])]; } |
︙ | ︙ |