Skip to content

Commit

Permalink
improve pb reader
Browse files Browse the repository at this point in the history
  • Loading branch information
qicosmos committed Sep 18, 2024
1 parent f2f94f3 commit 47b37ae
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions iguana/pb_reader.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,20 +73,23 @@ IGUANA_INLINE void from_pb_impl(T& val, std::string_view& pb_str,
"Invalid fixed int value: too few bytes.");
}
if constexpr (is_fixed_v<item_type>) {
int num = size / sizeof(item_type);
int old_size = val.size();
size_t num = size / sizeof(item_type);
size_t old_size = val.size();
detail::resize(val, old_size + num);
std::memcpy(val.data() + old_size, pb_str.data(), size);
pb_str = pb_str.substr(size);
}
else {
detail::resize(val, size);
size_t index = 0;
size_t start = pb_str.size();

while (!pb_str.empty()) {
item_type item;
from_pb_impl(item, pb_str);
val.push_back(std::move(item));
while (!pb_str.empty() && index < size) {
from_pb_impl(val[index], pb_str);
index++;
if (start - pb_str.size() == size) {
if (index < size) {
detail::resize(val, index);
}
break;
}
}
Expand Down

0 comments on commit 47b37ae

Please sign in to comment.