diff --git a/iguana/pb_reader.hpp b/iguana/pb_reader.hpp index a91a6969..cfa4f6cf 100644 --- a/iguana/pb_reader.hpp +++ b/iguana/pb_reader.hpp @@ -72,15 +72,23 @@ IGUANA_INLINE void from_pb_impl(T& val, std::string_view& pb_str, throw std::invalid_argument( "Invalid fixed int value: too few bytes."); } - using item_type = typename T::value_type; - size_t start = pb_str.size(); + if constexpr (is_fixed_v) { + int num = size / sizeof(item_type); + int 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 { + 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)); - if (start - pb_str.size() == size) { - break; + while (!pb_str.empty()) { + item_type item; + from_pb_impl(item, pb_str); + val.push_back(std::move(item)); + if (start - pb_str.size() == size) { + break; + } } } }