Changeset 55
- Timestamp:
- 06/26/08 21:43:21 (7 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/doost/util/serializer/archive/BinaryArchive.d
r54 r55 179 179 // Load file format indicator 180 180 uint fmt; 181 loadNumber (fmt);181 loadNumberDirect(fmt); 182 182 183 183 uint altEndianCode = FormatCode; … … 198 198 // Load version number 199 199 uint ver; 200 loadNumber (ver);200 loadNumberDirect(ver); 201 201 if (ver>FormatVersion) { 202 202 throw new ParsingException("Binary File too new"); … … 206 206 // Load size_t.sizeof indicator (tells if it's a 32 or 64 bit platform) 207 207 ubyte sizeof_length; 208 loadNumber (sizeof_length);208 loadNumberDirect(sizeof_length); 209 209 if (sizeof_length != LengthSizeof) { 210 210 // TODO: loading 32bit data on 64 bit platform (or vice versa) … … 225 225 else { 226 226 // write header 227 storage.put(encode(FormatCode));228 storage.put(encode(FormatVersion));229 storage.put(encode(LengthSizeof));227 dumpNumberDirect(FormatCode); 228 dumpNumberDirect(FormatVersion); 229 dumpNumberDirect(LengthSizeof); 230 230 ubyte[ReservedHeaderBytes] pad; 231 231 pad[] = 0x00; … … 305 305 return true; 306 306 } 307 static if(is(VALUE==uint) || 308 is(VALUE==ulong)) 309 { 310 // See note in dumpNumber() about these special cases. 311 if (!loadPackedUInteger(value)) 312 return false; 313 } 307 314 else { 308 315 value = decode!(VALUE)(storage.get(VALUE.sizeof)); … … 314 321 **************************************************************************/ 315 322 bool dumpNumber(VALUE)(ref VALUE value) { 316 static if( is(VALUE==real) || is(VALUE==creal) || is(VALUE==ireal)) { 323 static if( is(VALUE==real) || 324 is(VALUE==creal) || 325 is(VALUE==ireal)) 326 { 317 327 // TODO: implement platform independent multi-precision float 318 328 // to handle any platform-specific 'real' type. … … 326 336 return false; 327 337 } 338 static if(is(VALUE==uint) || 339 is(VALUE==ulong)) 340 { 341 // All uints and ulongs are stored packed for 32/64 bit compatibility. 342 // This makes it so things like size_t can be reliably packed/unpacked 343 // and they will work across the 32/64 divide as long as the actual 344 // size in a size_t doesn't exceed the size of int.max (which should be 345 // most of the time.) 346 if (!dumpPackedUInteger(value)) 347 return false; 348 } 328 349 else { 329 350 storage.put(encode(value)); 330 351 } 352 return true; 353 } 354 355 /*************************************************************************** 356 **************************************************************************/ 357 bool loadNumberDirect(VALUE)(ref VALUE value) { 358 value = decode!(VALUE)(storage.get(VALUE.sizeof)); 359 return true; 360 } 361 362 /*************************************************************************** 363 **************************************************************************/ 364 bool dumpNumberDirect(VALUE)(VALUE value) { 365 storage.put(encode(value)); 331 366 return true; 332 367 } … … 516 551 if (skip(Marker.defref)) { 517 552 uint symbol; 518 if (!traverse(symbol)) throw new ParsingException("Lack of symbol!"); 553 if (!traverse(symbol)) 554 throw new ParsingException("Lack of symbol!"); 519 555 value = registry.get!(TypeDescription, VALUE).address(symbol); 520 556 return true; … … 546 582 if (symbol > 0) { 547 583 storage.put(Marker.defref); 548 storage.put(encode(symbol));584 dumpNumber(symbol); 549 585 return true; 550 586 } … … 578 614 if (defined_ver > 0) { 579 615 storage.put( Marker.verBegin ); 580 storage.put( encode(defined_ver));616 dumpNumber(defined_ver); 581 617 storage.put( Marker.verEnd ); 582 618 }
