| 97 | } |
| 98 | |
| 99 | boost::shared_array<uint8_t> gen_compressible_buffer(uint32_t buf_len) { |
| 100 | auto* buf = new uint8_t[buf_len]; |
| 101 | |
| 102 | // Generate small runs of alternately increasing and decreasing bytes |
| 103 | boost::uniform_smallint<uint32_t> run_length_distribution(1, 64); |
| 104 | boost::uniform_smallint<uint8_t> byte_distribution(0, UINT8_MAX); |
| 105 | boost::variate_generator<boost::mt19937, boost::uniform_smallint<uint8_t> > |
| 106 | byte_generator(rng, byte_distribution); |
| 107 | boost::variate_generator<boost::mt19937, boost::uniform_smallint<uint32_t> > |
| 108 | run_len_generator(rng, run_length_distribution); |
| 109 | |
| 110 | uint32_t idx = 0; |
| 111 | int8_t step = 1; |
| 112 | while (idx < buf_len) { |
| 113 | uint32_t run_length = run_len_generator(); |
| 114 | if (idx + run_length > buf_len) { |
| 115 | run_length = buf_len - idx; |
| 116 | } |
| 117 | |
| 118 | uint8_t byte = byte_generator(); |
| 119 | for (uint32_t n = 0; n < run_length; ++n) { |
| 120 | buf[idx] = byte; |
| 121 | ++idx; |
| 122 | byte += step; |
| 123 | } |
| 124 | |
| 125 | step *= -1; |
| 126 | } |
| 127 | |
| 128 | return boost::shared_array<uint8_t>(buf); |
| 129 | } |
| 130 | |
| 131 | boost::shared_array<uint8_t> gen_random_buffer(uint32_t buf_len) { |
| 132 | auto* buf = new uint8_t[buf_len]; |
no outgoing calls
no test coverage detected