Cppinecone
A C++ client for the Pinecone vector database
parser.hpp
Go to the documentation of this file.
1 #pragma once
7 #include <cstdint>
8 #include <type_traits>
9 #include <vector>
10 
11 #include <nlohmann/json.hpp>
12 
14 #include "pinecone/util/result.hpp"
15 
16 using json = nlohmann::json;
17 
18 namespace pinecone::types
19 {
26 template <typename T, bool Json = !std::is_same_v<T, accepted>>
27 struct parser {
28  using parsed_type = T;
29 
36  [[nodiscard]] auto parse(std::vector<uint8_t>& data) const -> util::result<T>
37  {
38  if constexpr (Json) {
39  T parsed = json::parse(data);
40  return parsed;
41  } else {
42  return accepted{data};
43  }
44  }
45 };
46 
47 } // namespace pinecone::types
A monostate sentinel type for operations that have no associated response.
Models the possibility of failure for Pinecone operations.
Some Pinecone API operations have no explicitly expected result. Cppinecone models all of these opera...
Definition: accepted.hpp:18
Parses raw data from the Pinecone API into native C++ types.
Definition: parser.hpp:27
auto parse(std::vector< uint8_t > &data) const -> util::result< T >
Attempts to parse a stream of bytes into the provided type.
Definition: parser.hpp:36
Models the possibility of failure for all Cppinecone public API operations.
Definition: result.hpp:157