| 1265 | } |
| 1266 | |
| 1267 | void EncodeLevels(Encoding::type encoding, int16_t max_level, int num_levels, |
| 1268 | const int16_t* input_levels, std::vector<uint8_t>& bytes) { |
| 1269 | LevelEncoder encoder; |
| 1270 | int levels_count = 0; |
| 1271 | bytes.resize(2 * num_levels); |
| 1272 | ASSERT_EQ(2 * num_levels, static_cast<int>(bytes.size())); |
| 1273 | // encode levels |
| 1274 | if (encoding == Encoding::RLE) { |
| 1275 | // leave space to write the rle length value |
| 1276 | encoder.Init(encoding, max_level, num_levels, bytes.data() + sizeof(int32_t), |
| 1277 | static_cast<int>(bytes.size())); |
| 1278 | |
| 1279 | levels_count = encoder.Encode(num_levels, input_levels); |
| 1280 | (reinterpret_cast<int32_t*>(bytes.data()))[0] = encoder.len(); |
| 1281 | } else { |
| 1282 | encoder.Init(encoding, max_level, num_levels, bytes.data(), |
| 1283 | static_cast<int>(bytes.size())); |
| 1284 | levels_count = encoder.Encode(num_levels, input_levels); |
| 1285 | } |
| 1286 | ASSERT_EQ(num_levels, levels_count); |
| 1287 | } |
| 1288 | |
| 1289 | void VerifyDecodingLevels(Encoding::type encoding, int16_t max_level, |
| 1290 | const std::vector<int16_t>& input_levels, |