| 142 | } |
| 143 | |
| 144 | MMBuffer CodedInputData::readData(bool copy, bool exactly) { |
| 145 | int32_t size = this->readRawVarint32(); |
| 146 | if (size < 0) { |
| 147 | throw length_error("InvalidProtocolBuffer negativeSize"); |
| 148 | } |
| 149 | |
| 150 | auto s_size = static_cast<size_t>(size); |
| 151 | bool isSizeValid = exactly ? (s_size == m_size - m_position) : (s_size <= m_size - m_position); |
| 152 | if (isSizeValid) { |
| 153 | size_t pos = m_position; |
| 154 | m_position += s_size; |
| 155 | auto copyFlag = copy ? MMBufferCopy : MMBufferNoCopy; |
| 156 | return MMBuffer(((int8_t *) m_ptr) + pos, s_size, copyFlag); |
| 157 | } else { |
| 158 | throw out_of_range("InvalidProtocolBuffer truncatedMessage"); |
| 159 | } |
| 160 | } |
| 161 | |
| 162 | void CodedInputData::readData(KeyValueHolder &kvHolder) { |
| 163 | int32_t size = this->readRawVarint32(); |
no test coverage detected