| 34 | namespace mmkv { |
| 35 | |
| 36 | NSString *CodedInputData::readNSString() { |
| 37 | int32_t size = this->readRawVarint32(); |
| 38 | if (size < 0) { |
| 39 | throw length_error("InvalidProtocolBuffer negativeSize"); |
| 40 | } |
| 41 | |
| 42 | auto s_size = static_cast<size_t>(size); |
| 43 | if (s_size <= m_size - m_position) { |
| 44 | auto ptr = m_ptr + m_position; |
| 45 | NSString *result = [[NSString alloc] initWithBytes:ptr length:s_size encoding:NSUTF8StringEncoding]; |
| 46 | m_position += s_size; |
| 47 | return [result autorelease]; |
| 48 | } else { |
| 49 | throw out_of_range("InvalidProtocolBuffer truncatedMessage"); |
| 50 | } |
| 51 | } |
| 52 | |
| 53 | NSString *CodedInputData::readNSString(KeyValueHolder &kvHolder) { |
| 54 | kvHolder.offset = static_cast<uint32_t>(m_position); |
no test coverage detected