24#include <tao/json/value.hpp>
28#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
29namespace core::utils::json
32generate_binary(
const tao::json::value&
object) -> std::vector<std::byte>;
35parse_binary(
const std::vector<std::byte>& input) -> tao::json::value;
46 template<
typename Document>
50 if constexpr (std::is_null_pointer_v<std::remove_reference_t<Document>>) {
51 return core::utils::json::generate_binary(tao::json::null);
53 return core::utils::json::generate_binary(tao::json::value(document));
55 }
catch (
const tao::pegtl::parse_error& e) {
56 throw std::system_error(
58 std::string(
"json_transcoder cannot generate document as JSON: ").append(e.message()));
62 template<
typename Document>
66 if constexpr (std::is_same_v<Document, tao::json::value>) {
67 return core::utils::json::parse_binary(data);
69 return core::utils::json::parse_binary(data).as<Document>();
71 }
catch (
const tao::pegtl::parse_error& e) {
72 throw std::system_error(
74 std::string(
"json_transcoder cannot parse document as JSON: ").append(e.message()));
75 }
catch (
const std::out_of_range& e) {
76 throw std::system_error(
78 std::string(
"json_transcoder cannot parse document: ").append(e.what()));
83#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
85struct is_serializer<tao_json_serializer> :
public std::true_type {
Definition tao_json_serializer.hxx:42
tao::json::value document_type
Definition tao_json_serializer.hxx:44
static auto serialize(Document document) -> binary
Definition tao_json_serializer.hxx:47
static auto deserialize(const binary &data) -> Document
Definition tao_json_serializer.hxx:63
std::vector< std::byte > binary
Definition encoded_value.hxx:25
@ encoding_failure
Returned when encoding of a user object failed while trying to write it to the cluster.
@ decoding_failure
Returned when decoding of the data into the user object failed.
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28