Differences From Artifact [caaaf51219]:
- File src/OFData+MessagePackValue.m — part of check-in [e0459c419c] at 2020-04-19 14:52:59 on branch trunk — Reduce usage of unions (user: js, size: 13321) [annotate] [blame] [check-ins using] [more...]
To Artifact [464ca7dfaa]:
- File
src/OFData+MessagePackParsing.m
— part of check-in
[25c985fec1]
at
2020-08-25 00:11:24
on branch trunk
— OFNumber: Remove (u)int{8,16,32,64} methods
Since C guarantees minimum sizes for char, short, int, long and long
long, these can be used instead. (user: js, size: 13414) [annotate] [blame] [check-ins using] [more...]
︙ | ︙ | |||
15 16 17 18 19 20 21 | * file. */ #include "config.h" #include <string.h> | | | | 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+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_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 | OFData *data; if (length < 1) @throw [OFTruncatedDataException exception]; /* positive fixint */ if ((buffer[0] & 0x80) == 0) { | | | | 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 numberWithUnsignedChar: buffer[0] & 0x7F]; return 1; } /* negative fixint */ if ((buffer[0] & 0xE0) == 0xE0) { *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 | /* Prefix byte */ switch (buffer[0]) { /* Unsigned integers */ case 0xCC: /* uint8 */ if (length < 2) @throw [OFTruncatedDataException exception]; | | | > | > | > | | | | | 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 numberWithUnsignedChar: buffer[1]]; return 2; case 0xCD: /* uint 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithUnsignedShort: readUInt16(buffer + 1)]; return 3; case 0xCE: /* uint 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithUnsignedLong: readUInt32(buffer + 1)]; return 5; case 0xCF: /* uint 64 */ if (length < 9) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithUnsignedLongLong: readUInt64(buffer + 1)]; return 9; /* Signed integers */ case 0xD0: /* int 8 */ if (length < 2) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithChar: buffer[1]]; return 2; case 0xD1: /* int 16 */ if (length < 3) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithShort: readUInt16(buffer + 1)]; return 3; case 0xD2: /* int 32 */ if (length < 5) @throw [OFTruncatedDataException exception]; *object = [OFNumber numberWithLong: readUInt32(buffer + 1)]; return 5; case 0xD3: /* int 64 */ if (length < 9) @throw [OFTruncatedDataException exception]; *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 | return parseTable(buffer + 5, length - 5, object, readUInt32(buffer + 1), depthLimit) + 5; default: @throw [OFInvalidFormatException exception]; } } | | | | | | 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 (MessagePackParsing) - (id)objectByParsingMessagePack { return [self objectByParsingMessagePackWithDepthLimit: 32]; } - (id)objectByParsingMessagePackWithDepthLimit: (size_t)depthLimit { void *pool = objc_autoreleasePoolPush(); size_t count = self.count; id object; if (self.itemSize != 1) @throw [OFInvalidArgumentException exception]; |
︙ | ︙ |