IGUANA_INLINE size_t str_numeric_size()

in include/ylt/standalone/iguana/pb_util.hpp [344:398]


IGUANA_INLINE size_t str_numeric_size(Type&& t) {
  using T = std::remove_const_t<std::remove_reference_t<Type>>;
  if constexpr (std::is_same_v<T, std::string> ||
                std::is_same_v<T, std::string_view>) {
    // string
    if constexpr (omit_default_val) {
      if (t.size() == 0)
        IGUANA_UNLIKELY { return 0; }
    }
    if constexpr (key_size == 0) {
      return t.size();
    }
    else {
      return key_size + variant_uint32_size(static_cast<uint32_t>(t.size())) +
             t.size();
    }
  }
  else {
    // numeric
    if constexpr (omit_default_val) {
      if constexpr (is_fixed_v<T> || is_signed_varint_v<T>) {
        if (t.val == 0)
          IGUANA_UNLIKELY { return 0; }
      }
      else {
        if (t == static_cast<T>(0))
          IGUANA_UNLIKELY { return 0; }
      }
    }
    if constexpr (std::is_integral_v<T>) {
      if constexpr (std::is_same_v<bool, T>) {
        return 1 + key_size;
      }
      else {
        return key_size + variant_intergal_size(t);
      }
    }
    else if constexpr (detail::is_signed_varint_v<T>) {
      return key_size + variant_intergal_size(encode_zigzag(t.val));
    }
    else if constexpr (detail::is_fixed_v<T>) {
      return key_size + sizeof(typename T::value_type);
    }
    else if constexpr (std::is_same_v<T, double> || std::is_same_v<T, float>) {
      return key_size + sizeof(T);
    }
    else if constexpr (std::is_enum_v<T>) {
      using U = std::underlying_type_t<T>;
      return key_size + variant_intergal_size(static_cast<U>(t));
    }
    else {
      static_assert(!sizeof(T), "err");
    }
  }
}