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,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 increment_response_body
|
29
|
+
{
|
30
|
+
public:
|
31
|
+
static const inline client_opcode opcode = client_opcode::increment;
|
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 increment_request_body
|
78
|
+
{
|
79
|
+
public:
|
80
|
+
using response_body_type = increment_response_body;
|
81
|
+
static const inline client_opcode opcode = client_opcode::increment;
|
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,172 @@
|
|
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/status.hxx>
|
21
|
+
#include <protocol/client_opcode.hxx>
|
22
|
+
#include <protocol/frame_info_id.hxx>
|
23
|
+
#include <protocol/unsigned_leb128.h>
|
24
|
+
#include <protocol/durability_level.hxx>
|
25
|
+
#include <mutation_token.hxx>
|
26
|
+
#include <utils/byteswap.hxx>
|
27
|
+
|
28
|
+
namespace couchbase::protocol
|
29
|
+
{
|
30
|
+
|
31
|
+
class insert_response_body
|
32
|
+
{
|
33
|
+
public:
|
34
|
+
static const inline client_opcode opcode = client_opcode::insert;
|
35
|
+
|
36
|
+
private:
|
37
|
+
mutation_token token_;
|
38
|
+
|
39
|
+
public:
|
40
|
+
mutation_token& token()
|
41
|
+
{
|
42
|
+
return token_;
|
43
|
+
}
|
44
|
+
|
45
|
+
bool parse(protocol::status status,
|
46
|
+
const header_buffer& header,
|
47
|
+
std::uint8_t framing_extras_size,
|
48
|
+
std::uint16_t,
|
49
|
+
std::uint8_t extras_size,
|
50
|
+
const std::vector<uint8_t>& body,
|
51
|
+
const cmd_info&)
|
52
|
+
{
|
53
|
+
Expects(header[1] == static_cast<uint8_t>(opcode));
|
54
|
+
if (status == protocol::status::success) {
|
55
|
+
std::vector<uint8_t>::difference_type offset = framing_extras_size;
|
56
|
+
if (extras_size == 16) {
|
57
|
+
memcpy(&token_.partition_uuid, body.data() + offset, sizeof(token_.partition_uuid));
|
58
|
+
token_.partition_uuid = utils::byte_swap_64(token_.partition_uuid);
|
59
|
+
offset += 8;
|
60
|
+
|
61
|
+
memcpy(&token_.sequence_number, body.data() + offset, sizeof(token_.sequence_number));
|
62
|
+
token_.sequence_number = utils::byte_swap_64(token_.sequence_number);
|
63
|
+
return true;
|
64
|
+
}
|
65
|
+
}
|
66
|
+
return false;
|
67
|
+
}
|
68
|
+
};
|
69
|
+
|
70
|
+
class insert_request_body
|
71
|
+
{
|
72
|
+
public:
|
73
|
+
using response_body_type = insert_response_body;
|
74
|
+
static const inline client_opcode opcode = client_opcode::insert;
|
75
|
+
|
76
|
+
private:
|
77
|
+
std::string key_{};
|
78
|
+
std::vector<std::uint8_t> extras_{};
|
79
|
+
std::vector<std::uint8_t> content_{};
|
80
|
+
std::uint32_t flags_{};
|
81
|
+
std::uint32_t expiration_{};
|
82
|
+
std::vector<std::uint8_t> framing_extras_{};
|
83
|
+
|
84
|
+
public:
|
85
|
+
void id(const document_id& id)
|
86
|
+
{
|
87
|
+
key_ = id.key;
|
88
|
+
if (id.collection_uid) {
|
89
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
90
|
+
key_.insert(0, encoded.get());
|
91
|
+
}
|
92
|
+
}
|
93
|
+
|
94
|
+
void durability(protocol::durability_level level, std::optional<std::uint16_t> timeout)
|
95
|
+
{
|
96
|
+
if (level == protocol::durability_level::none) {
|
97
|
+
return;
|
98
|
+
}
|
99
|
+
auto frame_id = static_cast<uint8_t>(protocol::request_frame_info_id::durability_requirement);
|
100
|
+
if (timeout) {
|
101
|
+
framing_extras_.resize(4);
|
102
|
+
framing_extras_[0] = static_cast<std::uint8_t>((static_cast<std::uint32_t>(frame_id) << 4U) | 3U);
|
103
|
+
framing_extras_[1] = static_cast<std::uint8_t>(level);
|
104
|
+
uint16_t val = htons(*timeout);
|
105
|
+
memcpy(framing_extras_.data() + 2, &val, sizeof(val));
|
106
|
+
} else {
|
107
|
+
framing_extras_.resize(2);
|
108
|
+
framing_extras_[0] = static_cast<std::uint8_t>(static_cast<std::uint32_t>(frame_id) << 4U | 1U);
|
109
|
+
framing_extras_[1] = static_cast<std::uint8_t>(level);
|
110
|
+
}
|
111
|
+
}
|
112
|
+
|
113
|
+
void content(const std::string& content)
|
114
|
+
{
|
115
|
+
content_ = { content.begin(), content.end() };
|
116
|
+
}
|
117
|
+
|
118
|
+
void flags(uint32_t flags)
|
119
|
+
{
|
120
|
+
flags_ = flags;
|
121
|
+
}
|
122
|
+
|
123
|
+
void expiration(uint32_t value)
|
124
|
+
{
|
125
|
+
expiration_ = value;
|
126
|
+
}
|
127
|
+
|
128
|
+
const std::string& key()
|
129
|
+
{
|
130
|
+
return key_;
|
131
|
+
}
|
132
|
+
|
133
|
+
const std::vector<std::uint8_t>& framing_extras()
|
134
|
+
{
|
135
|
+
return framing_extras_;
|
136
|
+
}
|
137
|
+
|
138
|
+
const std::vector<std::uint8_t>& extras()
|
139
|
+
{
|
140
|
+
if (extras_.empty()) {
|
141
|
+
fill_extention();
|
142
|
+
}
|
143
|
+
return extras_;
|
144
|
+
}
|
145
|
+
|
146
|
+
const std::vector<std::uint8_t>& value()
|
147
|
+
{
|
148
|
+
return content_;
|
149
|
+
}
|
150
|
+
|
151
|
+
std::size_t size()
|
152
|
+
{
|
153
|
+
if (extras_.empty()) {
|
154
|
+
fill_extention();
|
155
|
+
}
|
156
|
+
return framing_extras_.size() + extras_.size() + key_.size() + content_.size();
|
157
|
+
}
|
158
|
+
|
159
|
+
private:
|
160
|
+
void fill_extention()
|
161
|
+
{
|
162
|
+
extras_.resize(sizeof(flags_) + sizeof(expiration_));
|
163
|
+
|
164
|
+
uint32_t field = htonl(flags_);
|
165
|
+
memcpy(extras_.data(), &field, sizeof(field));
|
166
|
+
|
167
|
+
field = htonl(expiration_);
|
168
|
+
memcpy(extras_.data() + sizeof(flags_), &field, sizeof(field));
|
169
|
+
}
|
170
|
+
};
|
171
|
+
|
172
|
+
} // 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
|
{
|
@@ -44,13 +44,18 @@ class lookup_in_response_body
|
|
44
44
|
return fields_;
|
45
45
|
}
|
46
46
|
|
47
|
-
bool parse(protocol::status status,
|
47
|
+
bool parse(protocol::status status,
|
48
|
+
const header_buffer& header,
|
49
|
+
std::uint8_t framing_extras_size,
|
50
|
+
std::uint16_t key_size,
|
51
|
+
std::uint8_t extras_size,
|
52
|
+
const std::vector<uint8_t>& body,
|
53
|
+
const cmd_info&)
|
48
54
|
{
|
49
55
|
Expects(header[1] == static_cast<uint8_t>(opcode));
|
50
56
|
if (status == protocol::status::success || status == protocol::status::subdoc_multi_path_failure) {
|
51
57
|
using offset_type = std::vector<uint8_t>::difference_type;
|
52
|
-
|
53
|
-
offset_type offset = ext_size;
|
58
|
+
offset_type offset = framing_extras_size + key_size + extras_size;
|
54
59
|
fields_.reserve(16); /* we won't have more than 16 entries anyway */
|
55
60
|
while (static_cast<std::size_t>(offset) < body.size()) {
|
56
61
|
lookup_in_field field;
|
@@ -112,16 +117,20 @@ class lookup_in_request_body
|
|
112
117
|
|
113
118
|
private:
|
114
119
|
std::string key_;
|
115
|
-
std::vector<std::uint8_t>
|
120
|
+
std::vector<std::uint8_t> extras_{};
|
116
121
|
std::vector<std::uint8_t> value_{};
|
117
122
|
|
118
123
|
std::uint8_t flags_{ 0 };
|
119
124
|
lookup_in_specs specs_;
|
120
125
|
|
121
126
|
public:
|
122
|
-
void id(const
|
127
|
+
void id(const document_id& id)
|
123
128
|
{
|
124
129
|
key_ = id.key;
|
130
|
+
if (id.collection_uid) {
|
131
|
+
unsigned_leb128<uint32_t> encoded(*id.collection_uid);
|
132
|
+
key_.insert(0, encoded.get());
|
133
|
+
}
|
125
134
|
}
|
126
135
|
|
127
136
|
void access_deleted(bool value)
|
@@ -143,12 +152,18 @@ class lookup_in_request_body
|
|
143
152
|
return key_;
|
144
153
|
}
|
145
154
|
|
146
|
-
const std::vector<std::uint8_t>&
|
155
|
+
const std::vector<std::uint8_t>& framing_extras()
|
156
|
+
{
|
157
|
+
static std::vector<std::uint8_t> empty;
|
158
|
+
return empty;
|
159
|
+
}
|
160
|
+
|
161
|
+
const std::vector<std::uint8_t>& extras()
|
147
162
|
{
|
148
|
-
if (
|
163
|
+
if (extras_.empty()) {
|
149
164
|
fill_extention();
|
150
165
|
}
|
151
|
-
return
|
166
|
+
return extras_;
|
152
167
|
}
|
153
168
|
|
154
169
|
const std::vector<std::uint8_t>& value()
|
@@ -161,21 +176,21 @@ class lookup_in_request_body
|
|
161
176
|
|
162
177
|
std::size_t size()
|
163
178
|
{
|
164
|
-
if (
|
179
|
+
if (extras_.empty()) {
|
165
180
|
fill_extention();
|
166
181
|
}
|
167
182
|
if (value_.empty()) {
|
168
183
|
fill_value();
|
169
184
|
}
|
170
|
-
return key_.size() +
|
185
|
+
return key_.size() + extras_.size() + value_.size();
|
171
186
|
}
|
172
187
|
|
173
188
|
private:
|
174
189
|
void fill_extention()
|
175
190
|
{
|
176
191
|
if (flags_ != 0) {
|
177
|
-
|
178
|
-
|
192
|
+
extras_.resize(sizeof(flags_));
|
193
|
+
extras_[0] = flags_;
|
179
194
|
}
|
180
195
|
}
|
181
196
|
|