30#if defined(__cpp_lib_format)
162 return lhs.m_index == rhs.m_index;
178 SPARROW_API std::string_view extract_string_view();
194 const char* m_current;
195 std::string_view m_key;
196 std::string_view m_value;
289 int32_t m_num_pairs = 0;
291 friend key_value_view_iterator;
303 template <
typename T>
305 && std::same_as<std::ranges::range_value_t<T>,
metadata_pair>;
337 template <input_metadata_container T>
342 const auto number_of_key_values =
static_cast<int32_t
>(metadata.size());
344 const size_t metadata_size = std::accumulate(
348 [](
size_t acc,
const auto& pair)
350 return acc + sizeof(int32_t)
353 + pair.second.size();
356 const size_t total_size =
sizeof(int32_t) + metadata_size;
357 std::string metadata_buf(total_size,
'\0');
360 auto metadata_iter = metadata_buf.begin();
361 std::memcpy(&(*metadata_iter), &number_of_key_values,
sizeof(int32_t));
362 std::advance(metadata_iter,
sizeof(int32_t));
364 for (
const auto& [key, value] : metadata)
369 const auto key_size =
static_cast<int32_t
>(key.size());
370 std::memcpy(&(*metadata_iter), &key_size,
sizeof(int32_t));
371 std::advance(metadata_iter,
sizeof(int32_t));
374 std::advance(metadata_iter, key.size());
376 const auto value_size =
static_cast<int32_t
>(value.size());
377 std::memcpy(&(*metadata_iter), &value_size,
sizeof(int32_t));
378 std::advance(metadata_iter,
sizeof(int32_t));
381 std::advance(metadata_iter, value.size());
387#if defined(__cpp_lib_format)
391struct std::formatter<
sparrow::key_value_view>
393 constexpr auto parse(std::format_parse_context& ctx)
398 auto format(
const sparrow::key_value_view& array, std::format_context& ctx)
const
400 auto out = ctx.out();
404 for (
const auto& elem : array)
411 out = std::format_to(out,
"({}:{})", elem.first, elem.second);
424 os << std::format(
"{}", value);
SPARROW_API key_value_view_iterator operator++(int)
Advances the iterator to the next key-value pair.
std::forward_iterator_tag iterator_concept
std::ptrdiff_t difference_type
SPARROW_API key_value_view_iterator & operator++()
Advances the iterator to the next key-value pair.
metadata_pair_const_reference value_type
friend bool operator==(const key_value_view_iterator &lhs, const key_value_view_iterator &rhs)
Equality comparison operator for iterators.
SPARROW_API key_value_view_iterator(const key_value_view &parent, int32_t index)
Constructs an iterator for the given view at the specified index.
SPARROW_API value_type operator*() const
Dereferences the iterator to get the current key-value pair.
Custom view for lazily extracting key-value pairs from a binary buffer.
SPARROW_API key_value_view_iterator begin() const
Gets iterator to the beginning of the metadata pairs.
SPARROW_API size_t size() const
Gets the number of key-value pairs in the metadata.
SPARROW_API key_value_view_iterator end() const
Gets iterator to the end of the metadata pairs.
SPARROW_API key_value_view_iterator cend() const
Gets const iterator to the end of the metadata pairs.
SPARROW_API key_value_view(const char *ptr)
Constructs a view over the given binary metadata buffer.
SPARROW_API key_value_view_iterator cbegin() const
Gets const iterator to the beginning of the metadata pairs.
#define SPARROW_ASSERT_TRUE(expr__)
constexpr std::ranges::copy_result< std::ranges::borrowed_iterator_t< R >, O > copy(R &&r, O result)
SPARROW_API int32_t extract_int32(const char *&ptr)
Helper function to extract a 32-bit integer from a character buffer.
std::pair< metadata_key_const_reference, metadata_value_const_reference > metadata_pair_const_reference
std::string get_metadata_from_key_values(const T &metadata)
Converts a container of key-value pairs to binary metadata format.
std::string_view metadata_value_const_reference
std::string_view metadata_key_const_reference
std::ostream & operator<<(std::ostream &os, const nullval_t &)
std::pair< metadata_key, metadata_value > metadata_pair
Type alias for metadata key-value pairs.
std::string metadata_key
Type alias for metadata keys.
std::string metadata_value
Type alias for metadata values.