MCPcopy Create free account
hub / github.com/1a1a11a/libCacheSim / write_bigendian_number

Function write_bigendian_number

libCacheSim/dataStructure/sparsepp/spp.h:282–294  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

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

Callers 1

write_32_or_64Method · 0.85

Calls 1

write_dataFunction · 0.85

Tested by

no test coverage detected