diff --git a/iguana/dynamic.hpp b/iguana/dynamic.hpp index 74cc2da3..4b479b0c 100644 --- a/iguana/dynamic.hpp +++ b/iguana/dynamic.hpp @@ -17,9 +17,9 @@ constexpr inline uint8_t ENABLE_ALL = 0x0F; template struct base_impl : public base { - void to_pb(std::string& str) override { + void to_pb(std::string& str) const override { if constexpr ((ENABLE_FLAG & ENABLE_PB) != 0) { - to_pb_adl((iguana_adl_t*)nullptr, *(static_cast(this)), str); + to_pb_adl((iguana_adl_t*)nullptr, *(static_cast(this)), str); } else { throw std::runtime_error("Protobuf Disabled"); @@ -160,7 +160,7 @@ struct base_impl : public base { virtual ~base_impl() {} - size_t cache_size = 0; + mutable size_t cache_size = 0; }; IGUANA_INLINE std::shared_ptr create_instance(std::string_view name) { diff --git a/iguana/pb_util.hpp b/iguana/pb_util.hpp index 5fa7365c..9ef8212c 100644 --- a/iguana/pb_util.hpp +++ b/iguana/pb_util.hpp @@ -73,8 +73,8 @@ constexpr inline WireType get_wire_type() { } template -constexpr bool is_lenprefix_v = (get_wire_type() == - WireType::LengthDelimeted); +constexpr bool is_lenprefix_v = + (get_wire_type() == WireType::LengthDelimeted); [[nodiscard]] IGUANA_INLINE uint32_t encode_zigzag(int32_t v) { return (static_cast(v) << 1U) ^ @@ -419,6 +419,7 @@ IGUANA_INLINE size_t pb_oneof_size(Type&& t, Arr& size_arr) { int len = 0; std::visit( [&len, &size_arr](auto&& value) IGUANA__INLINE_LAMBDA { + using raw_value_type = decltype(value); using value_type = std::remove_const_t>; constexpr auto offset = @@ -427,7 +428,7 @@ IGUANA_INLINE size_t pb_oneof_size(Type&& t, Arr& size_arr) { ((field_no + offset) << 3) | static_cast(get_wire_type()); len = pb_key_value_size( - std::forward(value), size_arr); + std::forward(value), size_arr); }, std::forward(t)); return len; @@ -454,7 +455,7 @@ IGUANA_INLINE size_t pb_key_value_size(Type&& t, Arr& size_arr) { std::decay_t>; constexpr auto value = std::get(tuple); using U = typename field_type::value_type; - auto& val = value.value(t); + auto const& val = value.value(t); if constexpr (variant_v) { constexpr auto offset = get_variant_index; std::visit( [&it, &sz_ptr](auto&& value) IGUANA__INLINE_LAMBDA { + using raw_value_type = decltype(value); using value_type = std::remove_const_t>; constexpr auto offset = @@ -90,7 +91,7 @@ IGUANA_INLINE void to_pb_oneof(Type&& t, It&& it, uint32_t*& sz_ptr) { constexpr uint32_t key = ((field_no + offset) << 3) | static_cast(get_wire_type()); - to_pb_impl(std::forward(value), it, sz_ptr); + to_pb_impl(std::forward(value), it, sz_ptr); }, std::forward(t)); } @@ -449,7 +450,7 @@ IGUANA_INLINE void build_sub_proto(Map& map, std::string_view str_type, } // namespace detail template -IGUANA_INLINE void to_pb(T& t, Stream& out) { +IGUANA_INLINE void to_pb(T const& t, Stream& out) { std::vector size_arr; auto byte_len = detail::pb_key_value_size<0>(t, size_arr); detail::resize(out, byte_len); @@ -491,7 +492,7 @@ IGUANA_INLINE void to_proto_file(Stream& stream, std::string_view ns = "") { #endif template -IGUANA_INLINE void to_pb_adl(iguana_adl_t* p, T& t, Stream& out) { +IGUANA_INLINE void to_pb_adl(iguana_adl_t* p, T const& t, Stream& out) { to_pb(t, out); } diff --git a/iguana/reflection.hpp b/iguana/reflection.hpp index df3ea91c..6bad499c 100644 --- a/iguana/reflection.hpp +++ b/iguana/reflection.hpp @@ -562,7 +562,7 @@ struct field_info { }; struct base { - virtual void to_pb(std::string &str) {} + virtual void to_pb(std::string &str) const {} virtual void from_pb(std::string_view str) {} virtual void to_xml(std::string &str) const {} virtual void from_xml(std::string_view str) {} @@ -803,6 +803,7 @@ struct field_t { uint32_t field_no; auto &value(owner_type &value) const { return value.*member_ptr; } + auto const &value(owner_type const &value) const { return value.*member_ptr; } }; template