| 217 | } |
| 218 | |
| 219 | size_t BitpackDecoder::inputProcess( const char *source, const size_t availableByteCount ) |
| 220 | { |
| 221 | #ifdef E57_VERBOSE |
| 222 | std::cout << "BitpackDecoder::inputprocess() called, source=" << ( source ? source : "none" ) |
| 223 | << " availableByteCount=" << availableByteCount << std::endl; |
| 224 | #endif |
| 225 | size_t bytesUnsaved = availableByteCount; |
| 226 | size_t bitsEaten = 0; |
| 227 | do |
| 228 | { |
| 229 | size_t byteCount = |
| 230 | std::min( bytesUnsaved, inBuffer_.size() - static_cast<size_t>( inBufferEndByte_ ) ); |
| 231 | |
| 232 | // Copy input bytes from caller, if any |
| 233 | if ( ( byteCount > 0 ) && ( source != nullptr ) ) |
| 234 | { |
| 235 | memcpy( &inBuffer_[inBufferEndByte_], source, byteCount ); |
| 236 | |
| 237 | // Advance tail pointer. |
| 238 | inBufferEndByte_ += byteCount; |
| 239 | |
| 240 | // Update amount available from caller |
| 241 | bytesUnsaved -= byteCount; |
| 242 | source += byteCount; |
| 243 | } |
| 244 | #ifdef E57_VERBOSE |
| 245 | { |
| 246 | unsigned i; |
| 247 | unsigned firstByte = inBufferFirstBit_ / 8; |
| 248 | for ( i = 0; i < byteCount && i < 20; i++ ) |
| 249 | { |
| 250 | std::cout << " inBuffer[" << firstByte + i |
| 251 | << "]=" << (unsigned)(unsigned char)( inBuffer_[firstByte + i] ) << std::endl; |
| 252 | } |
| 253 | if ( i < byteCount ) |
| 254 | { |
| 255 | std::cout << " " << byteCount - i << "source bytes unprinted..." << std::endl; |
| 256 | } |
| 257 | } |
| 258 | #endif |
| 259 | |
| 260 | // ??? fix doc for new bit interface |
| 261 | // Now that we have input stored in an aligned buffer, call derived class |
| 262 | // to try to eat some Note that end of filled buffer may not be at a |
| 263 | // natural boundary. The subclass may transfer this partial word in a |
| 264 | // full word transfer, but it must be careful to only use the defined |
| 265 | // bits. inBuffer_ is a multiple of largest word size, so this full word |
| 266 | // transfer off the end will always be in defined memory. |
| 267 | |
| 268 | size_t firstWord = inBufferFirstBit_ / bitsPerWord_; |
| 269 | size_t firstNaturalBit = firstWord * bitsPerWord_; |
| 270 | size_t endBit = inBufferEndByte_ * 8; |
| 271 | #ifdef E57_VERBOSE |
| 272 | std::cout << " feeding aligned decoder " << endBit - inBufferFirstBit_ << " bits." |
| 273 | << std::endl; |
| 274 | #endif |
| 275 | bitsEaten = |
| 276 | inputProcessAligned( &inBuffer_[firstWord * bytesPerWord_], |
no test coverage detected