* This class takes in a data stream of pack() Nibbles followed by pack()'ed * values as produced by the compressor and unpack()'s them one by one. */
| 329 | * values as produced by the compressor and unpack()'s them one by one. |
| 330 | */ |
| 331 | class Nibbler { |
| 332 | PRIVATE: |
| 333 | // Position in the nibble stream |
| 334 | const TwoNibbles *nibblePosition; |
| 335 | |
| 336 | // Indicates whether whether to use the first nibble or second |
| 337 | bool onFirstNibble; |
| 338 | |
| 339 | // Number of nibbles in this stream |
| 340 | int numNibbles; |
| 341 | |
| 342 | // Position in the stream marking the next packed value |
| 343 | const char *currPackedValue; |
| 344 | |
| 345 | // End of the last valid packed value |
| 346 | const char *endOfValues; |
| 347 | |
| 348 | public: |
| 349 | /** |
| 350 | * Nibbler Constructor |
| 351 | * |
| 352 | * \param nibbleStart |
| 353 | * Data stream consisting of the Nibbles followed by pack()ed values. |
| 354 | * \param numNibbles |
| 355 | * Number of nibbles in the data stream |
| 356 | */ |
| 357 | Nibbler(const char *nibbleStart, int numNibbles) |
| 358 | : nibblePosition(reinterpret_cast<const TwoNibbles*>(nibbleStart)) |
| 359 | , onFirstNibble(true) |
| 360 | , numNibbles(numNibbles) |
| 361 | , currPackedValue(nibbleStart + (numNibbles + 1)/2) |
| 362 | , endOfValues(nullptr) |
| 363 | { |
| 364 | endOfValues = nibbleStart |
| 365 | + (numNibbles + 1)/2 |
| 366 | + getSizeOfPackedValues(nibblePosition, numNibbles); |
| 367 | } |
| 368 | |
| 369 | /** |
| 370 | * Returns the next pack()-ed value in the stream |
| 371 | * |
| 372 | * \tparam T |
| 373 | * Type of the value in the stream |
| 374 | * \return |
| 375 | * Next pack()-ed value in the stream |
| 376 | */ |
| 377 | template<typename T> |
| 378 | T getNext() { |
| 379 | assert(currPackedValue < endOfValues); |
| 380 | |
| 381 | uint8_t nibble = (onFirstNibble) ? nibblePosition->first |
| 382 | : nibblePosition->second; |
| 383 | |
| 384 | T ret = unpack<T>(&currPackedValue, nibble); |
| 385 | |
| 386 | if (!onFirstNibble) |
| 387 | ++nibblePosition; |
| 388 |
nothing calls this directly
no outgoing calls
no test coverage detected