couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19

Sign up to get free protection for your applications and to get access to all the features.
Files changed (176) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/tests-6.0.3.yml +49 -0
  3. data/.github/workflows/tests.yml +47 -0
  4. data/.gitmodules +3 -0
  5. data/.idea/dictionaries/gem_terms.xml +5 -0
  6. data/.idea/inspectionProfiles/Project_Default.xml +1 -0
  7. data/.idea/vcs.xml +1 -0
  8. data/Gemfile +1 -0
  9. data/README.md +55 -2
  10. data/Rakefile +18 -0
  11. data/bin/init-cluster +62 -0
  12. data/bin/setup +1 -0
  13. data/couchbase.gemspec +3 -2
  14. data/examples/crud.rb +1 -2
  15. data/examples/managing_buckets.rb +47 -0
  16. data/examples/managing_collections.rb +58 -0
  17. data/examples/managing_query_indexes.rb +63 -0
  18. data/examples/query.rb +3 -2
  19. data/examples/query_with_consistency.rb +76 -0
  20. data/examples/subdocument.rb +23 -1
  21. data/ext/.clang-format +1 -1
  22. data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
  23. data/ext/.idea/vcs.xml +1 -0
  24. data/ext/CMakeLists.txt +30 -12
  25. data/ext/build_version.hxx.in +26 -0
  26. data/ext/couchbase/bucket.hxx +69 -8
  27. data/ext/couchbase/cluster.hxx +70 -54
  28. data/ext/couchbase/collections_manifest.hxx +3 -3
  29. data/ext/couchbase/configuration.hxx +14 -0
  30. data/ext/couchbase/couchbase.cxx +2044 -383
  31. data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
  32. data/ext/couchbase/io/http_message.hxx +5 -1
  33. data/ext/couchbase/io/http_parser.hxx +2 -1
  34. data/ext/couchbase/io/http_session.hxx +6 -3
  35. data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
  36. data/ext/couchbase/io/mcbp_parser.hxx +99 -0
  37. data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
  38. data/ext/couchbase/io/session_manager.hxx +37 -22
  39. data/ext/couchbase/mutation_token.hxx +2 -1
  40. data/ext/couchbase/operations.hxx +38 -8
  41. data/ext/couchbase/operations/bucket_create.hxx +138 -0
  42. data/ext/couchbase/operations/bucket_drop.hxx +65 -0
  43. data/ext/couchbase/operations/bucket_flush.hxx +65 -0
  44. data/ext/couchbase/operations/bucket_get.hxx +69 -0
  45. data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
  46. data/ext/couchbase/operations/bucket_settings.hxx +111 -0
  47. data/ext/couchbase/operations/bucket_update.hxx +115 -0
  48. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
  49. data/ext/couchbase/operations/collection_create.hxx +86 -0
  50. data/ext/couchbase/operations/collection_drop.hxx +82 -0
  51. data/ext/couchbase/operations/command.hxx +10 -10
  52. data/ext/couchbase/operations/document_decrement.hxx +80 -0
  53. data/ext/couchbase/operations/document_exists.hxx +80 -0
  54. data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
  55. data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
  56. data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
  57. data/ext/couchbase/operations/document_increment.hxx +80 -0
  58. data/ext/couchbase/operations/document_insert.hxx +74 -0
  59. data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
  60. data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
  61. data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
  62. data/ext/couchbase/operations/document_remove.hxx +67 -0
  63. data/ext/couchbase/operations/document_replace.hxx +76 -0
  64. data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
  65. data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
  66. data/ext/couchbase/operations/document_upsert.hxx +74 -0
  67. data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
  68. data/ext/couchbase/operations/query_index_create.hxx +134 -0
  69. data/ext/couchbase/operations/query_index_drop.hxx +108 -0
  70. data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
  71. data/ext/couchbase/operations/scope_create.hxx +81 -0
  72. data/ext/couchbase/operations/scope_drop.hxx +79 -0
  73. data/ext/couchbase/operations/scope_get_all.hxx +72 -0
  74. data/ext/couchbase/protocol/client_opcode.hxx +35 -0
  75. data/ext/couchbase/protocol/client_request.hxx +56 -9
  76. data/ext/couchbase/protocol/client_response.hxx +52 -15
  77. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
  78. data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
  79. data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
  80. data/ext/couchbase/protocol/cmd_get.hxx +31 -8
  81. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
  82. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
  83. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
  84. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
  85. data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
  86. data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
  87. data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
  88. data/ext/couchbase/protocol/cmd_info.hxx +1 -0
  89. data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
  90. data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
  91. data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
  92. data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
  93. data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
  94. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
  95. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
  96. data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
  97. data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
  98. data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
  99. data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
  100. data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
  101. data/ext/couchbase/protocol/durability_level.hxx +67 -0
  102. data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
  103. data/ext/couchbase/protocol/hello_feature.hxx +137 -0
  104. data/ext/couchbase/protocol/server_opcode.hxx +57 -0
  105. data/ext/couchbase/protocol/server_request.hxx +122 -0
  106. data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
  107. data/ext/couchbase/utils/byteswap.hxx +1 -2
  108. data/ext/couchbase/utils/url_codec.hxx +225 -0
  109. data/ext/couchbase/version.hxx +3 -1
  110. data/ext/extconf.rb +4 -1
  111. data/ext/test/main.cxx +37 -113
  112. data/ext/third_party/snappy/.appveyor.yml +36 -0
  113. data/ext/third_party/snappy/.gitignore +8 -0
  114. data/ext/third_party/snappy/.travis.yml +98 -0
  115. data/ext/third_party/snappy/AUTHORS +1 -0
  116. data/ext/third_party/snappy/CMakeLists.txt +345 -0
  117. data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
  118. data/ext/third_party/snappy/COPYING +54 -0
  119. data/ext/third_party/snappy/NEWS +188 -0
  120. data/ext/third_party/snappy/README.md +148 -0
  121. data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
  122. data/ext/third_party/snappy/cmake/config.h.in +59 -0
  123. data/ext/third_party/snappy/docs/README.md +72 -0
  124. data/ext/third_party/snappy/format_description.txt +110 -0
  125. data/ext/third_party/snappy/framing_format.txt +135 -0
  126. data/ext/third_party/snappy/snappy-c.cc +90 -0
  127. data/ext/third_party/snappy/snappy-c.h +138 -0
  128. data/ext/third_party/snappy/snappy-internal.h +315 -0
  129. data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
  130. data/ext/third_party/snappy/snappy-sinksource.h +182 -0
  131. data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
  132. data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
  133. data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
  134. data/ext/third_party/snappy/snappy-test.cc +613 -0
  135. data/ext/third_party/snappy/snappy-test.h +526 -0
  136. data/ext/third_party/snappy/snappy.cc +1770 -0
  137. data/ext/third_party/snappy/snappy.h +209 -0
  138. data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
  139. data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
  140. data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
  141. data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
  142. data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
  143. data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
  144. data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
  145. data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
  146. data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
  147. data/ext/third_party/snappy/testdata/geo.protodata +0 -0
  148. data/ext/third_party/snappy/testdata/html +1 -0
  149. data/ext/third_party/snappy/testdata/html_x_4 +1 -0
  150. data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
  151. data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
  152. data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
  153. data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
  154. data/ext/third_party/snappy/testdata/urls.10K +10000 -0
  155. data/lib/couchbase/binary_collection.rb +33 -76
  156. data/lib/couchbase/binary_collection_options.rb +94 -0
  157. data/lib/couchbase/bucket.rb +9 -3
  158. data/lib/couchbase/cluster.rb +161 -23
  159. data/lib/couchbase/collection.rb +108 -191
  160. data/lib/couchbase/collection_options.rb +430 -0
  161. data/lib/couchbase/errors.rb +136 -134
  162. data/lib/couchbase/json_transcoder.rb +32 -0
  163. data/lib/couchbase/management/analytics_index_manager.rb +185 -9
  164. data/lib/couchbase/management/bucket_manager.rb +84 -33
  165. data/lib/couchbase/management/collection_manager.rb +166 -1
  166. data/lib/couchbase/management/query_index_manager.rb +261 -0
  167. data/lib/couchbase/management/search_index_manager.rb +291 -0
  168. data/lib/couchbase/management/user_manager.rb +12 -10
  169. data/lib/couchbase/management/view_index_manager.rb +151 -1
  170. data/lib/couchbase/mutation_state.rb +11 -1
  171. data/lib/couchbase/scope.rb +4 -4
  172. data/lib/couchbase/version.rb +1 -1
  173. metadata +113 -18
  174. data/.travis.yml +0 -7
  175. data/ext/couchbase/io/binary_parser.hxx +0 -64
  176. 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 <operations/document_id.hxx>
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
- bool parse(protocol::status status, const header_buffer& header, const std::vector<uint8_t>& body, const cmd_info&)
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 = 0;
48
- uint8_t ext_size = header[4];
49
- if (ext_size == 4) {
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 operations::document_id& id)
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>& extension()
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;