Read into `data' if it is not null; otherwise skip some of the pending.
| 124 | |
| 125 | // Read into `data' if it is not null; otherwise skip some of the pending. |
| 126 | bool PagedInputStream::readOrSkip(const void** data, int32_t* size) { |
| 127 | if (data) { |
| 128 | BOLT_CHECK_EQ(pendingSkip_, 0); |
| 129 | } |
| 130 | // if the user pushed back, return them the partial buffer |
| 131 | if (outputBufferLength_) { |
| 132 | if (data) { |
| 133 | *data = outputBufferPtr_; |
| 134 | } |
| 135 | *size = static_cast<int32_t>(outputBufferLength_); |
| 136 | outputBufferPtr_ += outputBufferLength_; |
| 137 | bytesReturned_ += outputBufferLength_; |
| 138 | outputBufferLength_ = 0; |
| 139 | // This is a rewind of previous output, does not count for |
| 140 | // 'lastWindowSize_'. |
| 141 | return true; |
| 142 | } |
| 143 | |
| 144 | // release previous decryption buffer |
| 145 | decryptionBuffer_ = nullptr; |
| 146 | |
| 147 | if (state_ == State::HEADER || remainingLength_ == 0) { |
| 148 | readHeader(); |
| 149 | } |
| 150 | if (state_ == State::END) { |
| 151 | return false; |
| 152 | } |
| 153 | if (inputBufferPtr_ == inputBufferPtrEnd_) { |
| 154 | readBuffer(true); |
| 155 | } |
| 156 | |
| 157 | size_t availSize = std::min( |
| 158 | static_cast<size_t>(inputBufferPtrEnd_ - inputBufferPtr_), |
| 159 | remainingLength_); |
| 160 | // in the case when decompression or decryption is needed, need to copy data |
| 161 | // to input buffer if the input doesn't contain the entire block |
| 162 | bool original = !decrypter_ && (state_ == State::ORIGINAL); |
| 163 | const char* input = nullptr; |
| 164 | // if no decompression or decryption is needed, simply adjust the output |
| 165 | // pointer. Otherwise, make sure we have continuous block |
| 166 | if (original) { |
| 167 | if (data) { |
| 168 | *data = inputBufferPtr_; |
| 169 | } |
| 170 | *size = static_cast<int32_t>(availSize); |
| 171 | outputBufferPtr_ = inputBufferPtr_ + availSize; |
| 172 | inputBufferPtr_ += availSize; |
| 173 | remainingLength_ -= availSize; |
| 174 | } else { |
| 175 | input = ensureInput(availSize); |
| 176 | } |
| 177 | |
| 178 | // perform decryption |
| 179 | if (decrypter_) { |
| 180 | decryptionBuffer_ = |
| 181 | decrypter_->decrypt(folly::StringPiece{input, remainingLength_}); |
| 182 | input = reinterpret_cast<const char*>(decryptionBuffer_->data()); |
| 183 | remainingLength_ = decryptionBuffer_->length(); |
nothing calls this directly
no test coverage detected