couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/tests-6.0.3.yml +49 -0
- data/.github/workflows/tests.yml +47 -0
- data/.gitmodules +3 -0
- data/.idea/dictionaries/gem_terms.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +1 -0
- data/.idea/vcs.xml +1 -0
- data/Gemfile +1 -0
- data/README.md +55 -2
- data/Rakefile +18 -0
- data/bin/init-cluster +62 -0
- data/bin/setup +1 -0
- data/couchbase.gemspec +3 -2
- data/examples/crud.rb +1 -2
- data/examples/managing_buckets.rb +47 -0
- data/examples/managing_collections.rb +58 -0
- data/examples/managing_query_indexes.rb +63 -0
- data/examples/query.rb +3 -2
- data/examples/query_with_consistency.rb +76 -0
- data/examples/subdocument.rb +23 -1
- data/ext/.clang-format +1 -1
- data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
- data/ext/.idea/vcs.xml +1 -0
- data/ext/CMakeLists.txt +30 -12
- data/ext/build_version.hxx.in +26 -0
- data/ext/couchbase/bucket.hxx +69 -8
- data/ext/couchbase/cluster.hxx +70 -54
- data/ext/couchbase/collections_manifest.hxx +3 -3
- data/ext/couchbase/configuration.hxx +14 -0
- data/ext/couchbase/couchbase.cxx +2044 -383
- data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
- data/ext/couchbase/io/http_message.hxx +5 -1
- data/ext/couchbase/io/http_parser.hxx +2 -1
- data/ext/couchbase/io/http_session.hxx +6 -3
- data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
- data/ext/couchbase/io/mcbp_parser.hxx +99 -0
- data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
- data/ext/couchbase/io/session_manager.hxx +37 -22
- data/ext/couchbase/mutation_token.hxx +2 -1
- data/ext/couchbase/operations.hxx +38 -8
- data/ext/couchbase/operations/bucket_create.hxx +138 -0
- data/ext/couchbase/operations/bucket_drop.hxx +65 -0
- data/ext/couchbase/operations/bucket_flush.hxx +65 -0
- data/ext/couchbase/operations/bucket_get.hxx +69 -0
- data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
- data/ext/couchbase/operations/bucket_settings.hxx +111 -0
- data/ext/couchbase/operations/bucket_update.hxx +115 -0
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
- data/ext/couchbase/operations/collection_create.hxx +86 -0
- data/ext/couchbase/operations/collection_drop.hxx +82 -0
- data/ext/couchbase/operations/command.hxx +10 -10
- data/ext/couchbase/operations/document_decrement.hxx +80 -0
- data/ext/couchbase/operations/document_exists.hxx +80 -0
- data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
- data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
- data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
- data/ext/couchbase/operations/document_increment.hxx +80 -0
- data/ext/couchbase/operations/document_insert.hxx +74 -0
- data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
- data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
- data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
- data/ext/couchbase/operations/document_remove.hxx +67 -0
- data/ext/couchbase/operations/document_replace.hxx +76 -0
- data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
- data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
- data/ext/couchbase/operations/document_upsert.hxx +74 -0
- data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
- data/ext/couchbase/operations/query_index_create.hxx +134 -0
- data/ext/couchbase/operations/query_index_drop.hxx +108 -0
- data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
- data/ext/couchbase/operations/scope_create.hxx +81 -0
- data/ext/couchbase/operations/scope_drop.hxx +79 -0
- data/ext/couchbase/operations/scope_get_all.hxx +72 -0
- data/ext/couchbase/protocol/client_opcode.hxx +35 -0
- data/ext/couchbase/protocol/client_request.hxx +56 -9
- data/ext/couchbase/protocol/client_response.hxx +52 -15
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
- data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
- data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
- data/ext/couchbase/protocol/cmd_get.hxx +31 -8
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
- data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
- data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
- data/ext/couchbase/protocol/cmd_info.hxx +1 -0
- data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
- data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
- data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
- data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
- data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
- data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
- data/ext/couchbase/protocol/durability_level.hxx +67 -0
- data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
- data/ext/couchbase/protocol/hello_feature.hxx +137 -0
- data/ext/couchbase/protocol/server_opcode.hxx +57 -0
- data/ext/couchbase/protocol/server_request.hxx +122 -0
- data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
- data/ext/couchbase/utils/byteswap.hxx +1 -2
- data/ext/couchbase/utils/url_codec.hxx +225 -0
- data/ext/couchbase/version.hxx +3 -1
- data/ext/extconf.rb +4 -1
- data/ext/test/main.cxx +37 -113
- data/ext/third_party/snappy/.appveyor.yml +36 -0
- data/ext/third_party/snappy/.gitignore +8 -0
- data/ext/third_party/snappy/.travis.yml +98 -0
- data/ext/third_party/snappy/AUTHORS +1 -0
- data/ext/third_party/snappy/CMakeLists.txt +345 -0
- data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
- data/ext/third_party/snappy/COPYING +54 -0
- data/ext/third_party/snappy/NEWS +188 -0
- data/ext/third_party/snappy/README.md +148 -0
- data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
- data/ext/third_party/snappy/cmake/config.h.in +59 -0
- data/ext/third_party/snappy/docs/README.md +72 -0
- data/ext/third_party/snappy/format_description.txt +110 -0
- data/ext/third_party/snappy/framing_format.txt +135 -0
- data/ext/third_party/snappy/snappy-c.cc +90 -0
- data/ext/third_party/snappy/snappy-c.h +138 -0
- data/ext/third_party/snappy/snappy-internal.h +315 -0
- data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
- data/ext/third_party/snappy/snappy-sinksource.h +182 -0
- data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
- data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
- data/ext/third_party/snappy/snappy-test.cc +613 -0
- data/ext/third_party/snappy/snappy-test.h +526 -0
- data/ext/third_party/snappy/snappy.cc +1770 -0
- data/ext/third_party/snappy/snappy.h +209 -0
- data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
- data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
- data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
- data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
- data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
- data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
- data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
- data/ext/third_party/snappy/testdata/geo.protodata +0 -0
- data/ext/third_party/snappy/testdata/html +1 -0
- data/ext/third_party/snappy/testdata/html_x_4 +1 -0
- data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
- data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
- data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
- data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
- data/ext/third_party/snappy/testdata/urls.10K +10000 -0
- data/lib/couchbase/binary_collection.rb +33 -76
- data/lib/couchbase/binary_collection_options.rb +94 -0
- data/lib/couchbase/bucket.rb +9 -3
- data/lib/couchbase/cluster.rb +161 -23
- data/lib/couchbase/collection.rb +108 -191
- data/lib/couchbase/collection_options.rb +430 -0
- data/lib/couchbase/errors.rb +136 -134
- data/lib/couchbase/json_transcoder.rb +32 -0
- data/lib/couchbase/management/analytics_index_manager.rb +185 -9
- data/lib/couchbase/management/bucket_manager.rb +84 -33
- data/lib/couchbase/management/collection_manager.rb +166 -1
- data/lib/couchbase/management/query_index_manager.rb +261 -0
- data/lib/couchbase/management/search_index_manager.rb +291 -0
- data/lib/couchbase/management/user_manager.rb +12 -10
- data/lib/couchbase/management/view_index_manager.rb +151 -1
- data/lib/couchbase/mutation_state.rb +11 -1
- data/lib/couchbase/scope.rb +4 -4
- data/lib/couchbase/version.rb +1 -1
- metadata +113 -18
- data/.travis.yml +0 -7
- data/ext/couchbase/io/binary_parser.hxx +0 -64
- data/lib/couchbase/results.rb +0 -307
@@ -0,0 +1,81 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020 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
|
+
|
20
|
+
#include <gsl/gsl_assert>
|
21
|
+
|
22
|
+
#include <protocol/server_opcode.hxx>
|
23
|
+
#include <protocol/cmd_info.hxx>
|
24
|
+
|
25
|
+
#include <configuration.hxx>
|
26
|
+
|
27
|
+
namespace couchbase::protocol
|
28
|
+
{
|
29
|
+
|
30
|
+
class cluster_map_change_notification_request_body
|
31
|
+
{
|
32
|
+
public:
|
33
|
+
static const inline server_opcode opcode = server_opcode::cluster_map_change_notification;
|
34
|
+
|
35
|
+
private:
|
36
|
+
uint32_t protocol_revision_;
|
37
|
+
std::string bucket_;
|
38
|
+
configuration config_;
|
39
|
+
|
40
|
+
public:
|
41
|
+
[[nodiscard]] uint32_t protocol_revision()
|
42
|
+
{
|
43
|
+
return protocol_revision_;
|
44
|
+
}
|
45
|
+
|
46
|
+
[[nodiscard]] const std::string& bucket()
|
47
|
+
{
|
48
|
+
return bucket_;
|
49
|
+
}
|
50
|
+
|
51
|
+
[[nodiscard]] configuration config()
|
52
|
+
{
|
53
|
+
return config_;
|
54
|
+
}
|
55
|
+
|
56
|
+
bool parse(const header_buffer& header, const std::vector<uint8_t>& body, const cmd_info& info)
|
57
|
+
{
|
58
|
+
Expects(header[1] == static_cast<uint8_t>(opcode));
|
59
|
+
using offset_type = std::vector<uint8_t>::difference_type;
|
60
|
+
uint8_t ext_size = header[4];
|
61
|
+
offset_type offset = ext_size;
|
62
|
+
if (ext_size == 4) {
|
63
|
+
memcpy(&protocol_revision_, body.data(), sizeof(protocol_revision_));
|
64
|
+
protocol_revision_ = ntohl(protocol_revision_);
|
65
|
+
}
|
66
|
+
uint16_t key_size = 0;
|
67
|
+
memcpy(&key_size, header.data() + 2, sizeof(key_size));
|
68
|
+
key_size = ntohs(key_size);
|
69
|
+
bucket_.assign(body.begin() + offset, body.begin() + offset + key_size);
|
70
|
+
offset += key_size;
|
71
|
+
config_ = tao::json::from_string<deduplicate_keys>(std::string(body.begin() + offset, body.end())).as<configuration>();
|
72
|
+
for (auto& node : config_.nodes) {
|
73
|
+
if (node.this_node && node.hostname.empty()) {
|
74
|
+
node.hostname = info.remote_endpoint.address().to_string();
|
75
|
+
}
|
76
|
+
}
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
};
|
80
|
+
|
81
|
+
} // namespace couchbase::protocol
|
@@ -0,0 +1,187 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020 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
|
+
|
20
|
+
#include <protocol/unsigned_leb128.h>
|
21
|
+
|
22
|
+
#include <protocol/client_opcode.hxx>
|
23
|
+
#include <document_id.hxx>
|
24
|
+
|
25
|
+
namespace couchbase::protocol
|
26
|
+
{
|
27
|
+
|
28
|
+
class decrement_response_body
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
static const inline client_opcode opcode = client_opcode::decrement;
|
32
|
+
|
33
|
+
private:
|
34
|
+
mutation_token token_;
|
35
|
+
std::uint64_t content_;
|
36
|
+
|
37
|
+
public:
|
38
|
+
std::uint64_t content()
|
39
|
+
{
|
40
|
+
return content_;
|
41
|
+
}
|
42
|
+
|
43
|
+
mutation_token& token()
|
44
|
+
{
|
45
|
+
return token_;
|
46
|
+
}
|
47
|
+
|
48
|
+
bool parse(protocol::status status,
|
49
|
+
const header_buffer& header,
|
50
|
+
std::uint8_t framing_extras_size,
|
51
|
+
std::uint16_t /* key_size */,
|
52
|
+
std::uint8_t extras_size,
|
53
|
+
const std::vector<uint8_t>& body,
|
54
|
+
const cmd_info&)
|
55
|
+
{
|
56
|
+
Expects(header[1] == static_cast<uint8_t>(opcode));
|
57
|
+
if (status == protocol::status::success) {
|
58
|
+
using offset_type = std::vector<uint8_t>::difference_type;
|
59
|
+
offset_type offset = framing_extras_size;
|
60
|
+
if (extras_size == 16) {
|
61
|
+
memcpy(&token_.partition_uuid, body.data() + offset, sizeof(token_.partition_uuid));
|
62
|
+
token_.partition_uuid = utils::byte_swap_64(token_.partition_uuid);
|
63
|
+
offset += 8;
|
64
|
+
|
65
|
+
memcpy(&token_.sequence_number, body.data() + offset, sizeof(token_.sequence_number));
|
66
|
+
token_.sequence_number = utils::byte_swap_64(token_.sequence_number);
|
67
|
+
offset += 8;
|
68
|
+
}
|
69
|
+
memcpy(&content_, body.data() + offset, sizeof(content_));
|
70
|
+
content_ = utils::byte_swap_64(content_);
|
71
|
+
return true;
|
72
|
+
}
|
73
|
+
return false;
|
74
|
+
}
|
75
|
+
};
|
76
|
+
|
77
|
+
class decrement_request_body
|
78
|
+
{
|
79
|
+
public:
|
80
|
+
using response_body_type = decrement_response_body;
|
81
|
+
static const inline client_opcode opcode = client_opcode::decrement;
|
82
|
+
|
83
|
+
private:
|
84
|
+
std::string key_;
|
85
|
+
std::vector<std::uint8_t> framing_extras_{};
|
86
|
+
std::uint64_t delta_{ 1 };
|
87
|
+
std::uint64_t initial_value_{ 0 };
|
88
|
+
std::uint32_t expiration_{ 0 };
|
89
|
+
std::vector<std::uint8_t> extras_{};
|
90
|
+
|
91
|
+
public:
|
92
|
+
void id(const document_id& id)
|
93
|
+
{
|
94
|
+
key_ = id.key;
|
95
|
+
if (id.collection_uid) {
|
96
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
97
|
+
key_.insert(0, encoded.get());
|
98
|
+
}
|
99
|
+
}
|
100
|
+
|
101
|
+
void delta(std::uint64_t value)
|
102
|
+
{
|
103
|
+
delta_ = value;
|
104
|
+
}
|
105
|
+
|
106
|
+
void initial_value(std::uint64_t value)
|
107
|
+
{
|
108
|
+
initial_value_ = value;
|
109
|
+
}
|
110
|
+
|
111
|
+
void expiration(std::uint32_t value)
|
112
|
+
{
|
113
|
+
expiration_ = value;
|
114
|
+
}
|
115
|
+
|
116
|
+
void durability(protocol::durability_level level, std::optional<std::uint16_t> timeout)
|
117
|
+
{
|
118
|
+
if (level == protocol::durability_level::none) {
|
119
|
+
return;
|
120
|
+
}
|
121
|
+
auto frame_id = static_cast<uint8_t>(protocol::request_frame_info_id::durability_requirement);
|
122
|
+
if (timeout) {
|
123
|
+
framing_extras_.resize(4);
|
124
|
+
framing_extras_[0] = static_cast<std::uint8_t>((static_cast<std::uint32_t>(frame_id) << 4U) | 3U);
|
125
|
+
framing_extras_[1] = static_cast<std::uint8_t>(level);
|
126
|
+
uint16_t val = htons(*timeout);
|
127
|
+
memcpy(framing_extras_.data() + 2, &val, sizeof(val));
|
128
|
+
} else {
|
129
|
+
framing_extras_.resize(2);
|
130
|
+
framing_extras_[0] = static_cast<std::uint8_t>(static_cast<std::uint32_t>(frame_id) << 4U | 1U);
|
131
|
+
framing_extras_[1] = static_cast<std::uint8_t>(level);
|
132
|
+
}
|
133
|
+
}
|
134
|
+
|
135
|
+
const std::string& key()
|
136
|
+
{
|
137
|
+
return key_;
|
138
|
+
}
|
139
|
+
|
140
|
+
const std::vector<std::uint8_t>& framing_extras()
|
141
|
+
{
|
142
|
+
return framing_extras_;
|
143
|
+
}
|
144
|
+
|
145
|
+
const std::vector<std::uint8_t>& extras()
|
146
|
+
{
|
147
|
+
if (extras_.empty()) {
|
148
|
+
fill_extras();
|
149
|
+
}
|
150
|
+
return extras_;
|
151
|
+
}
|
152
|
+
|
153
|
+
const std::vector<std::uint8_t>& value()
|
154
|
+
{
|
155
|
+
static std::vector<std::uint8_t> empty;
|
156
|
+
return empty;
|
157
|
+
}
|
158
|
+
|
159
|
+
[[nodiscard]] std::size_t size()
|
160
|
+
{
|
161
|
+
if (extras_.empty()) {
|
162
|
+
fill_extras();
|
163
|
+
}
|
164
|
+
return extras_.size() + key_.size();
|
165
|
+
}
|
166
|
+
|
167
|
+
private:
|
168
|
+
void fill_extras()
|
169
|
+
{
|
170
|
+
extras_.resize(sizeof(delta_) + sizeof(initial_value_) + sizeof(expiration_));
|
171
|
+
using offset_type = std::vector<uint8_t>::difference_type;
|
172
|
+
offset_type offset = 0;
|
173
|
+
|
174
|
+
std::uint64_t num = utils::byte_swap_64(delta_);
|
175
|
+
memcpy(extras_.data() + offset, &num, sizeof(num));
|
176
|
+
offset += static_cast<offset_type>(sizeof(delta_));
|
177
|
+
|
178
|
+
num = utils::byte_swap_64(initial_value_);
|
179
|
+
memcpy(extras_.data() + offset, &num, sizeof(num));
|
180
|
+
offset += static_cast<offset_type>(sizeof(delta_));
|
181
|
+
|
182
|
+
std::uint32_t ttl = htonl(expiration_);
|
183
|
+
memcpy(extras_.data() + offset, &ttl, sizeof(ttl));
|
184
|
+
}
|
185
|
+
};
|
186
|
+
|
187
|
+
} // namespace couchbase::protocol
|
@@ -0,0 +1,171 @@
|
|
1
|
+
/* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
|
2
|
+
/*
|
3
|
+
* Copyright 2020 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
|
+
|
20
|
+
#include <protocol/unsigned_leb128.h>
|
21
|
+
|
22
|
+
#include <protocol/client_opcode.hxx>
|
23
|
+
#include <document_id.hxx>
|
24
|
+
|
25
|
+
namespace couchbase::protocol
|
26
|
+
{
|
27
|
+
|
28
|
+
class exists_response_body
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
static const inline client_opcode opcode = client_opcode::observe;
|
32
|
+
|
33
|
+
private:
|
34
|
+
std::uint16_t partition_id_;
|
35
|
+
std::string key_;
|
36
|
+
std::uint8_t status_;
|
37
|
+
std::uint64_t cas_;
|
38
|
+
|
39
|
+
public:
|
40
|
+
[[nodiscard]] std::uint16_t partition_id()
|
41
|
+
{
|
42
|
+
return partition_id_;
|
43
|
+
}
|
44
|
+
|
45
|
+
[[nodiscard]] std::uint64_t cas()
|
46
|
+
{
|
47
|
+
return cas_;
|
48
|
+
}
|
49
|
+
|
50
|
+
[[nodiscard]] const std::string& key()
|
51
|
+
{
|
52
|
+
return key_;
|
53
|
+
}
|
54
|
+
|
55
|
+
[[nodiscard]] std::uint8_t status()
|
56
|
+
{
|
57
|
+
return status_;
|
58
|
+
}
|
59
|
+
|
60
|
+
bool parse(protocol::status status,
|
61
|
+
const header_buffer& header,
|
62
|
+
std::uint8_t framing_extras_size,
|
63
|
+
std::uint16_t key_size,
|
64
|
+
std::uint8_t extras_size,
|
65
|
+
const std::vector<uint8_t>& body,
|
66
|
+
const cmd_info& /* info */)
|
67
|
+
{
|
68
|
+
Expects(header[1] == static_cast<uint8_t>(opcode));
|
69
|
+
if (status == protocol::status::success) {
|
70
|
+
using offset_type = std::vector<uint8_t>::difference_type;
|
71
|
+
offset_type offset = framing_extras_size + extras_size + key_size;
|
72
|
+
|
73
|
+
memcpy(&partition_id_, body.data() + offset, sizeof(partition_id_));
|
74
|
+
partition_id_ = ntohs(partition_id_);
|
75
|
+
offset += static_cast<offset_type>(sizeof(partition_id_));
|
76
|
+
|
77
|
+
std::uint16_t key_len{};
|
78
|
+
memcpy(&key_len, body.data() + offset, sizeof(key_len));
|
79
|
+
key_len = ntohs(key_len);
|
80
|
+
offset += static_cast<offset_type>(sizeof(key_len));
|
81
|
+
|
82
|
+
key_.resize(key_len);
|
83
|
+
memcpy(key_.data(), body.data() + offset, key_len);
|
84
|
+
offset += key_len;
|
85
|
+
|
86
|
+
status_ = body[static_cast<std::size_t>(offset)];
|
87
|
+
offset++;
|
88
|
+
|
89
|
+
memcpy(&cas_, body.data() + offset, sizeof(cas_));
|
90
|
+
}
|
91
|
+
return false;
|
92
|
+
}
|
93
|
+
};
|
94
|
+
|
95
|
+
class exists_request_body
|
96
|
+
{
|
97
|
+
public:
|
98
|
+
using response_body_type = exists_response_body;
|
99
|
+
static const inline client_opcode opcode = client_opcode::observe;
|
100
|
+
|
101
|
+
private:
|
102
|
+
std::uint16_t partition_id_;
|
103
|
+
std::string key_;
|
104
|
+
std::vector<std::uint8_t> value_{};
|
105
|
+
|
106
|
+
public:
|
107
|
+
void id(std::uint16_t partition_id, const document_id& id)
|
108
|
+
{
|
109
|
+
partition_id_ = partition_id;
|
110
|
+
key_ = id.key;
|
111
|
+
if (id.collection_uid) {
|
112
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
113
|
+
key_.insert(0, encoded.get());
|
114
|
+
}
|
115
|
+
}
|
116
|
+
|
117
|
+
const std::string& key()
|
118
|
+
{
|
119
|
+
/* for observe key goes in the body */
|
120
|
+
static std::string empty;
|
121
|
+
return empty;
|
122
|
+
}
|
123
|
+
|
124
|
+
const std::vector<std::uint8_t>& framing_extras()
|
125
|
+
{
|
126
|
+
static std::vector<std::uint8_t> empty;
|
127
|
+
return empty;
|
128
|
+
}
|
129
|
+
|
130
|
+
const std::vector<std::uint8_t>& extras()
|
131
|
+
{
|
132
|
+
static std::vector<std::uint8_t> empty;
|
133
|
+
return empty;
|
134
|
+
}
|
135
|
+
|
136
|
+
const std::vector<std::uint8_t>& value()
|
137
|
+
{
|
138
|
+
if (value_.empty()) {
|
139
|
+
fill_body();
|
140
|
+
}
|
141
|
+
return value_;
|
142
|
+
}
|
143
|
+
|
144
|
+
std::size_t size()
|
145
|
+
{
|
146
|
+
if (value_.empty()) {
|
147
|
+
fill_body();
|
148
|
+
}
|
149
|
+
return value_.size();
|
150
|
+
}
|
151
|
+
|
152
|
+
private:
|
153
|
+
void fill_body()
|
154
|
+
{
|
155
|
+
std::vector<std::uint8_t>::size_type offset = 0;
|
156
|
+
|
157
|
+
value_.resize(2 * sizeof(std::uint16_t) + key_.size());
|
158
|
+
|
159
|
+
uint16_t field = htons(partition_id_);
|
160
|
+
memcpy(value_.data() + offset, &field, sizeof(field));
|
161
|
+
offset += sizeof(field);
|
162
|
+
|
163
|
+
field = htons(static_cast<uint16_t>(key_.size()));
|
164
|
+
memcpy(value_.data() + offset, &field, sizeof(field));
|
165
|
+
offset += sizeof(field);
|
166
|
+
|
167
|
+
std::memcpy(value_.data() + offset, key_.data(), key_.size());
|
168
|
+
}
|
169
|
+
};
|
170
|
+
|
171
|
+
} // namespace couchbase::protocol
|
@@ -20,7 +20,7 @@
|
|
20
20
|
#include <protocol/unsigned_leb128.h>
|
21
21
|
|
22
22
|
#include <protocol/client_opcode.hxx>
|
23
|
-
#include <
|
23
|
+
#include <document_id.hxx>
|
24
24
|
|
25
25
|
namespace couchbase::protocol
|
26
26
|
{
|
@@ -40,17 +40,30 @@ class get_response_body
|
|
40
40
|
return value_;
|
41
41
|
}
|
42
42
|
|
43
|
-
|
43
|
+
std::uint32_t flags()
|
44
|
+
{
|
45
|
+
return flags_;
|
46
|
+
}
|
47
|
+
|
48
|
+
bool parse(protocol::status status,
|
49
|
+
const header_buffer& header,
|
50
|
+
std::uint8_t framing_extras_size,
|
51
|
+
std::uint16_t key_size,
|
52
|
+
std::uint8_t extras_size,
|
53
|
+
const std::vector<uint8_t>& body,
|
54
|
+
const cmd_info&)
|
44
55
|
{
|
45
56
|
Expects(header[1] == static_cast<uint8_t>(opcode));
|
46
57
|
if (status == protocol::status::success) {
|
47
|
-
std::vector<uint8_t>::difference_type offset =
|
48
|
-
|
49
|
-
|
50
|
-
memcpy(&flags_, body.data(), sizeof(flags_));
|
58
|
+
std::vector<uint8_t>::difference_type offset = framing_extras_size;
|
59
|
+
if (extras_size == 4) {
|
60
|
+
memcpy(&flags_, body.data() + offset, sizeof(flags_));
|
51
61
|
flags_ = ntohl(flags_);
|
52
62
|
offset += 4;
|
63
|
+
} else {
|
64
|
+
offset += extras_size;
|
53
65
|
}
|
66
|
+
offset += key_size;
|
54
67
|
value_.assign(body.begin() + offset, body.end());
|
55
68
|
return true;
|
56
69
|
}
|
@@ -68,9 +81,13 @@ class get_request_body
|
|
68
81
|
std::string key_;
|
69
82
|
|
70
83
|
public:
|
71
|
-
void id(const
|
84
|
+
void id(const document_id& id)
|
72
85
|
{
|
73
86
|
key_ = id.key;
|
87
|
+
if (id.collection_uid) {
|
88
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
89
|
+
key_.insert(0, encoded.get());
|
90
|
+
}
|
74
91
|
}
|
75
92
|
|
76
93
|
const std::string& key()
|
@@ -78,7 +95,13 @@ class get_request_body
|
|
78
95
|
return key_;
|
79
96
|
}
|
80
97
|
|
81
|
-
const std::vector<std::uint8_t>&
|
98
|
+
const std::vector<std::uint8_t>& framing_extras()
|
99
|
+
{
|
100
|
+
static std::vector<std::uint8_t> empty;
|
101
|
+
return empty;
|
102
|
+
}
|
103
|
+
|
104
|
+
const std::vector<std::uint8_t>& extras()
|
82
105
|
{
|
83
106
|
static std::vector<std::uint8_t> empty;
|
84
107
|
return empty;
|