Overview
Comment: | MessagePack: Add support for the date extension |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
3395923962fe1df1002b4e21f4c59379 |
User & Date: | js on 2018-05-26 14:43:14 |
Other Links: | manifest | tags |
Context
2018-05-26
| ||
14:46 | Use trunc() instead of floor() in several places check-in: 3c20dd5f95 user: js tags: trunk | |
14:43 | MessagePack: Add support for the date extension check-in: 3395923962 user: js tags: trunk | |
09:03 | .travis.yml: Test building without Amiga library check-in: e17f5ee09c user: js tags: trunk | |
Changes
Modified src/OFData+MessagePackValue.m from [141d6da6b8] to [dd53d00818].
︙ | ︙ | |||
16 17 18 19 20 21 22 | */ #include "config.h" #include <string.h> #import "OFData+MessagePackValue.h" | | | | > | | | | 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 <string.h> #import "OFData+MessagePackValue.h" #import "OFArray.h" #import "OFDate.h" #import "OFDictionary.h" #import "OFMessagePackExtension.h" #import "OFNull.h" #import "OFNumber.h" #import "OFString.h" #import "OFInvalidFormatException.h" int _OFData_MessagePackValue_reference; static size_t parseObject(const uint8_t *buffer, size_t length, id *object, size_t depthLimit); |
︙ | ︙ | |||
148 149 150 151 152 153 154 155 156 157 158 159 160 | forKey: key]; objc_autoreleasePoolPop(pool); } return pos; } static size_t parseObject(const uint8_t *buffer, size_t length, id *object, size_t depthLimit) { size_t count; | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > < | 149 150 151 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 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 | forKey: key]; objc_autoreleasePoolPop(pool); } return pos; } static OFDate * createDate(OFData *data) { switch ([data count]) { case 4: { uint32_t timestamp; memcpy(×tamp, [data items], 4); timestamp = OF_BSWAP32_IF_LE(timestamp); return [OFDate dateWithTimeIntervalSince1970: timestamp]; } case 8: { uint64_t combined; memcpy(&combined, [data items], 8); combined = OF_BSWAP64_IF_LE(combined); return [OFDate dateWithTimeIntervalSince1970: (double)(combined & 0x3FFFFFFFF) + (double)(combined >> 34) / 1000000000]; } case 12: { uint32_t nanoseconds; int64_t seconds; memcpy(&nanoseconds, [data items], 4); memcpy(&seconds, (char *)[data items] + 4, 8); nanoseconds = OF_BSWAP32_IF_LE(nanoseconds); seconds = OF_BSWAP64_IF_LE(seconds); return [OFDate dateWithTimeIntervalSince1970: (double)seconds + (double)nanoseconds / 1000000000]; } default: @throw [OFInvalidFormatException exception]; } } static id createExtension(int8_t type, OFData *data) { switch (type) { case -1: return createDate(data); default: return [OFMessagePackExtension extensionWithType: type data: data]; } } static size_t parseObject(const uint8_t *buffer, size_t length, id *object, size_t depthLimit) { size_t count; OFData *data; if (length < 1) goto error; /* positive fixint */ if ((buffer[0] & 0x80) == 0) { |
︙ | ︙ | |||
337 338 339 340 341 342 343 | goto error; count = buffer[1]; if (length < count + 3) goto error; | < < | < < < < | < < < < | < < < < | < < < < | < < < < | < < < < | < < < < | < < | 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | goto error; count = buffer[1]; if (length < count + 3) goto error; data = [[OFData alloc] initWithItems: buffer + 3 count: count]; @try { *object = createExtension(buffer[2], data); } @finally { [data release]; } return count + 3; case 0xC8: /* ext 16 */ if (length < 4) goto error; count = readUInt16(buffer + 1); if (length < count + 4) goto error; data = [[OFData alloc] initWithItems: buffer + 4 count: count]; @try { *object = createExtension(buffer[3], data); } @finally { [data release]; } return count + 4; case 0xC9: /* ext 32 */ if (length < 6) goto error; count = readUInt32(buffer + 1); if (length < count + 6) goto error; data = [[OFData alloc] initWithItems: buffer + 6 count: count]; @try { *object = createExtension(buffer[5], data); } @finally { [data release]; } return count + 6; case 0xD4: /* fixext 1 */ if (length < 3) goto error; data = [[OFData alloc] initWithItems: buffer + 2 count: 1]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 3; case 0xD5: /* fixext 2 */ if (length < 4) goto error; data = [[OFData alloc] initWithItems: buffer + 2 count: 2]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 4; case 0xD6: /* fixext 4 */ if (length < 6) goto error; data = [[OFData alloc] initWithItems: buffer + 2 count: 4]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 6; case 0xD7: /* fixext 8 */ if (length < 10) goto error; data = [[OFData alloc] initWithItems: buffer + 2 count: 8]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 10; case 0xD8: /* fixext 16 */ if (length < 18) goto error; data = [[OFData alloc] initWithItems: buffer + 2 count: 16]; @try { *object = createExtension(buffer[1], data); } @finally { [data release]; } return 18; /* Strings */ case 0xD9: /* str 8 */ |
︙ | ︙ |
Modified src/OFDate.h from [87064cce5f] to [68640e4769].
︙ | ︙ | |||
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * 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. */ #import "OFObject.h" #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFConstantString; /*! * @class OFDate OFDate.h ObjFW/OFDate.h * * @brief A class for storing, accessing and comparing dates. */ | > | > | 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 | * 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. */ #import "OFObject.h" #import "OFMessagePackRepresentation.h" #import "OFSerialization.h" OF_ASSUME_NONNULL_BEGIN @class OFString; @class OFConstantString; /*! * @class OFDate OFDate.h ObjFW/OFDate.h * * @brief A class for storing, accessing and comparing dates. */ @interface OFDate: OFObject <OFCopying, OFComparing, OFSerialization, OFMessagePackRepresentation> { of_time_interval_t _seconds; } #ifdef OF_HAVE_CLASS_PROPERTIES @property (class, readonly, nonatomic) OFDate *distantFuture; @property (class, readonly, nonatomic) OFDate *distantPast; |
︙ | ︙ |
Modified src/OFDate.m from [6f5701bcb5] to [8b281f77b2].
︙ | ︙ | |||
20 21 22 23 24 25 26 | #include <limits.h> #include <time.h> #include <math.h> #include <sys/time.h> #import "OFDate.h" | | | > > | 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 | #include <limits.h> #include <time.h> #include <math.h> #include <sys/time.h> #import "OFDate.h" #import "OFData.h" #import "OFDictionary.h" #import "OFMessagePackExtension.h" #ifdef OF_HAVE_THREADS # import "OFMutex.h" #endif #import "OFString.h" #import "OFSystemInfo.h" #import "OFXMLElement.h" #import "OFInitializationFailedException.h" #import "OFInvalidArgumentException.h" #import "OFInvalidFormatException.h" #import "OFOutOfRangeException.h" #import "of_strptime.h" |
︙ | ︙ | |||
437 438 439 440 441 442 443 444 445 446 447 448 449 450 | [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (uint32_t)microsecond { return (uint32_t)((_seconds - floor(_seconds)) * 1000000); } - (uint8_t)second | > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > | 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 | [element retain]; objc_autoreleasePoolPop(pool); return [element autorelease]; } - (OFData *)messagePackRepresentation { void *pool = objc_autoreleasePoolPush(); int64_t seconds = (int64_t)_seconds; uint32_t nanoseconds = (_seconds - trunc(_seconds)) * 1000000000; OFData *ret; if (seconds >= 0 && seconds < 0x400000000) { if (seconds <= UINT32_MAX && nanoseconds == 0) { uint32_t seconds32 = (uint32_t)seconds; OFData *data; seconds32 = OF_BSWAP32_IF_LE(seconds32); data = [OFData dataWithItems: &seconds32 count: sizeof(seconds32)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } else { uint64_t combined = ((uint64_t)nanoseconds << 34) | (uint64_t)seconds; OFData *data; combined = OF_BSWAP64_IF_LE(combined); data = [OFData dataWithItems: &combined count: sizeof(combined)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } } else { OFMutableData *data = [OFMutableData dataWithCapacity: 12]; seconds = OF_BSWAP64_IF_LE(seconds); nanoseconds = OF_BSWAP32_IF_LE(nanoseconds); [data addItems: &nanoseconds count: sizeof(nanoseconds)]; [data addItems: &seconds count: sizeof(seconds)]; ret = [[OFMessagePackExtension extensionWithType: -1 data: data] messagePackRepresentation]; } [ret retain]; objc_autoreleasePoolPop(pool); return [ret autorelease]; } - (uint32_t)microsecond { return (uint32_t)((_seconds - floor(_seconds)) * 1000000); } - (uint8_t)second |
︙ | ︙ |