| 44 | } |
| 45 | |
| 46 | bool DecodeStringList(const string& src, tstring* strings, int64 n) { |
| 47 | std::vector<uint32> sizes(n); |
| 48 | StringPiece reader(src); |
| 49 | int64 tot = 0; |
| 50 | for (auto& v : sizes) { |
| 51 | if (!core::GetVarint32(&reader, &v)) return false; |
| 52 | tot += v; |
| 53 | } |
| 54 | if (tot != static_cast<int64>(reader.size())) { |
| 55 | return false; |
| 56 | } |
| 57 | |
| 58 | tstring* data = strings; |
| 59 | for (int64 i = 0; i < n; ++i, ++data) { |
| 60 | auto size = sizes[i]; |
| 61 | if (size > reader.size()) { |
| 62 | return false; |
| 63 | } |
| 64 | data->assign(reader.data(), size); |
| 65 | reader.remove_prefix(size); |
| 66 | } |
| 67 | |
| 68 | return true; |
| 69 | } |
| 70 | |
| 71 | void CopyFromArray(string* s, const char* base, size_t bytes) { |
| 72 | s->assign(base, bytes); |
no test coverage detected