Couchbase C++ SDK 1.0.1 (rev. 58d46d7)
Loading...
Searching...
No Matches
raw_string_transcoder.hxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2/*
3 * Copyright 2024. Couchbase, Inc.
4 *
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at
8 *
9 * http://www.apache.org/licenses/LICENSE-2.0
10 *
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
16 */
17
18#pragma once
19
24
25#include <cstddef>
26#include <string>
27#include <string_view>
28#include <type_traits>
29#include <vector>
30
31namespace couchbase
32{
33#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
34namespace core::utils
35{
36auto
37to_binary(std::string_view value) noexcept -> std::vector<std::byte>;
38} // namespace core::utils
39#endif
40
41namespace codec
42{
44{
45public:
46 using document_type = std::string;
47
48 static auto encode(document_type document) -> encoded_value
49 {
50 return { core::utils::to_binary(document), codec_flags::string_common_flags };
51 }
52
53 template<typename Document = document_type,
54 std::enable_if_t<std::is_same_v<Document, document_type>, bool> = true>
55 static auto decode(const encoded_value& encoded) -> Document
56 {
58 throw std::system_error(
60 "raw_string_transcoder expects document to have STRING common flags, flags=" +
61 std::to_string(encoded.flags));
62 }
63
64 return std::string{ reinterpret_cast<const char*>(encoded.data.data()), encoded.data.size() };
65 }
66};
67
68#ifndef COUCHBASE_CXX_CLIENT_DOXYGEN
69template<>
70struct is_transcoder<raw_string_transcoder> : public std::true_type {
71};
72#endif
73} // namespace codec
74} // namespace couchbase
Definition raw_string_transcoder.hxx:44
std::string document_type
Definition raw_string_transcoder.hxx:46
static auto encode(document_type document) -> encoded_value
Definition raw_string_transcoder.hxx:48
static auto decode(const encoded_value &encoded) -> Document
Definition raw_string_transcoder.hxx:55
constexpr auto has_common_flags(std::uint32_t flags) -> bool
Checks whether the upper 8 bits are set, indicating common flags presence.
Definition codec_flags.hxx:96
constexpr std::uint32_t string_common_flags
Definition codec_flags.hxx:148
@ decoding_failure
Returned when decoding of the data into the user object failed.
auto to_binary(mutate_in_macro value) -> std::vector< std::byte >
Converts macro into binary array suitable for sending to the server.
Represents a single item from the result of collection::scan()
Definition allow_querying_search_index_options.hxx:28
Definition encoded_value.hxx:27