| 280 | |
| 281 | template <typename OUTPUT, typename IntType> |
| 282 | bool write_bigendian_number(OUTPUT* fp, IntType value, size_t length) |
| 283 | { |
| 284 | unsigned char byte; |
| 285 | // We require IntType to be unsigned or else the shifting gets all screwy. |
| 286 | SPP_COMPILE_ASSERT(static_cast<IntType>(-1) > static_cast<IntType>(0), "serializing_int_requires_an_unsigned_type"); |
| 287 | for (size_t i = 0; i < length; ++i) |
| 288 | { |
| 289 | byte = (sizeof(value) <= length-1 - i) |
| 290 | ? static_cast<unsigned char>(0) : static_cast<unsigned char>((value >> ((length-1 - i) * 8)) & 255); |
| 291 | if (!write_data(fp, &byte, sizeof(byte))) return false; |
| 292 | } |
| 293 | return true; |
| 294 | } |
| 295 | |
| 296 | // If your keys and values are simple enough, you can pass this |
| 297 | // serializer to serialize()/unserialize(). "Simple enough" means |
no test coverage detected