static xdr::msg_ptr duplicateMessage(xdr::msg_ptr const& msg) { xdr::msg_ptr msg2 = xdr::message_t::alloc(msg->size()); memcpy(msg2->raw_data(), msg->raw_data(), msg->raw_size()); return std::move(msg2); }
static bool damageMessage(default_random_engine& gen, xdr::msg_ptr& msg) { size_t bitsFlipped = 0; char* d = msg->raw_data(); char* e = msg->end(); size_t sz = e - d; if (sz > 0) { auto dist = uniform_int_distribution<size_t>(0, sz - 1); auto byteDist = uniform_int_distribution<int>(0, 7); size_t nDamage = dist(gen); while (nDamage != 0) { --nDamage; auto pos = dist(gen); d[pos] ^= 1 << byteDist(gen); bitsFlipped++; } } return bitsFlipped != 0; }