couchbase 3.0.0.alpha.1 → 3.0.0.alpha.2

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
@@ -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
  {
@@ -38,6 +38,7 @@ class mutate_in_response_body
38
38
 
39
39
  private:
40
40
  std::vector<mutate_in_field> fields_;
41
+ mutation_token token_;
41
42
 
42
43
  public:
43
44
  std::vector<mutate_in_field>& fields()
@@ -45,13 +46,35 @@ class mutate_in_response_body
45
46
  return fields_;
46
47
  }
47
48
 
48
- bool parse(protocol::status status, const header_buffer& header, const std::vector<uint8_t>& body, const cmd_info&)
49
+ mutation_token& token()
50
+ {
51
+ return token_;
52
+ }
53
+
54
+ bool parse(protocol::status status,
55
+ const header_buffer& header,
56
+ std::uint8_t framing_extras_size,
57
+ std::uint16_t key_size,
58
+ std::uint8_t extras_size,
59
+ const std::vector<uint8_t>& body,
60
+ const cmd_info&)
49
61
  {
50
62
  Expects(header[1] == static_cast<uint8_t>(opcode));
51
63
  if (status == protocol::status::success || status == protocol::status::subdoc_multi_path_failure) {
52
64
  using offset_type = std::vector<uint8_t>::difference_type;
53
- uint8_t ext_size = header[4];
54
- offset_type offset = ext_size;
65
+ offset_type offset = framing_extras_size;
66
+ if (extras_size == 16) {
67
+ memcpy(&token_.partition_uuid, body.data() + offset, sizeof(token_.partition_uuid));
68
+ token_.partition_uuid = utils::byte_swap_64(token_.partition_uuid);
69
+ offset += 8;
70
+
71
+ memcpy(&token_.sequence_number, body.data() + offset, sizeof(token_.sequence_number));
72
+ token_.sequence_number = utils::byte_swap_64(token_.sequence_number);
73
+ offset += 8;
74
+ } else {
75
+ offset += extras_size;
76
+ }
77
+ offset += key_size;
55
78
  fields_.reserve(16); /* we won't have more than 16 entries anyway */
56
79
  while (static_cast<std::size_t>(offset) < body.size()) {
57
80
  mutate_in_field field;
@@ -162,16 +185,21 @@ class mutate_in_request_body
162
185
 
163
186
  private:
164
187
  std::string key_;
165
- std::vector<std::uint8_t> ext_{};
188
+ std::vector<std::uint8_t> extras_{};
166
189
  std::vector<std::uint8_t> value_{};
167
190
 
168
191
  std::uint8_t flags_{ 0 };
169
192
  mutate_in_specs specs_;
193
+ std::vector<std::uint8_t> framing_extras_{};
170
194
 
171
195
  public:
172
- void id(const operations::document_id& id)
196
+ void id(const document_id& id)
173
197
  {
174
198
  key_ = id.key;
199
+ if (id.collection_uid) {
200
+ unsigned_leb128<uint32_t> encoded(*id.collection_uid);
201
+ key_.insert(0, encoded.get());
202
+ }
175
203
  }
176
204
 
177
205
  void access_deleted(bool value)
@@ -188,17 +216,41 @@ class mutate_in_request_body
188
216
  specs_ = specs;
189
217
  }
190
218
 
219
+ void durability(protocol::durability_level level, std::optional<std::uint16_t> timeout)
220
+ {
221
+ if (level == protocol::durability_level::none) {
222
+ return;
223
+ }
224
+ auto frame_id = static_cast<uint8_t>(protocol::request_frame_info_id::durability_requirement);
225
+ if (timeout) {
226
+ framing_extras_.resize(4);
227
+ framing_extras_[0] = static_cast<std::uint8_t>((static_cast<std::uint32_t>(frame_id) << 4U) | 3U);
228
+ framing_extras_[1] = static_cast<std::uint8_t>(level);
229
+ uint16_t val = htons(*timeout);
230
+ memcpy(framing_extras_.data() + 2, &val, sizeof(val));
231
+ } else {
232
+ framing_extras_.resize(2);
233
+ framing_extras_[0] = static_cast<std::uint8_t>(static_cast<std::uint32_t>(frame_id) << 4U | 1U);
234
+ framing_extras_[1] = static_cast<std::uint8_t>(level);
235
+ }
236
+ }
237
+
191
238
  const std::string& key()
192
239
  {
193
240
  return key_;
194
241
  }
195
242
 
196
- const std::vector<std::uint8_t>& extension()
243
+ const std::vector<std::uint8_t>& framing_extras()
244
+ {
245
+ return framing_extras_;
246
+ }
247
+
248
+ const std::vector<std::uint8_t>& extras()
197
249
  {
198
- if (ext_.empty()) {
250
+ if (extras_.empty()) {
199
251
  fill_extention();
200
252
  }
201
- return ext_;
253
+ return extras_;
202
254
  }
203
255
 
204
256
  const std::vector<std::uint8_t>& value()
@@ -211,21 +263,21 @@ class mutate_in_request_body
211
263
 
212
264
  std::size_t size()
213
265
  {
214
- if (ext_.empty()) {
266
+ if (extras_.empty()) {
215
267
  fill_extention();
216
268
  }
217
269
  if (value_.empty()) {
218
270
  fill_value();
219
271
  }
220
- return key_.size() + ext_.size() + value_.size();
272
+ return framing_extras_.size() + extras_.size() + key_.size() + value_.size();
221
273
  }
222
274
 
223
275
  private:
224
276
  void fill_extention()
225
277
  {
226
278
  if (flags_ != 0) {
227
- ext_.resize(sizeof(flags_));
228
- ext_[0] = flags_;
279
+ extras_.resize(sizeof(flags_));
280
+ extras_[0] = flags_;
229
281
  }
230
282
  }
231
283
 
@@ -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
  {
@@ -30,10 +30,36 @@ class remove_response_body
30
30
  public:
31
31
  static const inline client_opcode opcode = client_opcode::remove;
32
32
 
33
+ mutation_token token_;
34
+
33
35
  public:
34
- bool parse(protocol::status, const header_buffer& header, const std::vector<uint8_t>&, const cmd_info&)
36
+ mutation_token& token()
37
+ {
38
+ return token_;
39
+ }
40
+
41
+ bool parse(protocol::status status,
42
+ const header_buffer& header,
43
+ std::uint8_t framing_extras_size,
44
+ std::uint16_t /* key_size */,
45
+ std::uint8_t extras_size,
46
+ const std::vector<uint8_t>& body,
47
+ const cmd_info&)
35
48
  {
36
49
  Expects(header[1] == static_cast<uint8_t>(opcode));
50
+ if (status == protocol::status::success) {
51
+ using offset_type = std::vector<uint8_t>::difference_type;
52
+ offset_type offset = framing_extras_size;
53
+ if (extras_size == 16) {
54
+ memcpy(&token_.partition_uuid, body.data() + offset, sizeof(token_.partition_uuid));
55
+ token_.partition_uuid = utils::byte_swap_64(token_.partition_uuid);
56
+ offset += 8;
57
+
58
+ memcpy(&token_.sequence_number, body.data() + offset, sizeof(token_.sequence_number));
59
+ token_.sequence_number = utils::byte_swap_64(token_.sequence_number);
60
+ }
61
+ return true;
62
+ }
37
63
  return false;
38
64
  }
39
65
  };
@@ -46,11 +72,35 @@ class remove_request_body
46
72
 
47
73
  private:
48
74
  std::string key_;
75
+ std::vector<std::uint8_t> framing_extras_{};
49
76
 
50
77
  public:
51
- void id(const operations::document_id& id)
78
+ void id(const document_id& id)
52
79
  {
53
80
  key_ = id.key;
81
+ if (id.collection_uid) {
82
+ unsigned_leb128<uint32_t> encoded(*id.collection_uid);
83
+ key_.insert(0, encoded.get());
84
+ }
85
+ }
86
+
87
+ void durability(protocol::durability_level level, std::optional<std::uint16_t> timeout)
88
+ {
89
+ if (level == protocol::durability_level::none) {
90
+ return;
91
+ }
92
+ auto frame_id = static_cast<uint8_t>(protocol::request_frame_info_id::durability_requirement);
93
+ if (timeout) {
94
+ framing_extras_.resize(4);
95
+ framing_extras_[0] = static_cast<std::uint8_t>((static_cast<std::uint32_t>(frame_id) << 4U) | 3U);
96
+ framing_extras_[1] = static_cast<std::uint8_t>(level);
97
+ uint16_t val = htons(*timeout);
98
+ memcpy(framing_extras_.data() + 2, &val, sizeof(val));
99
+ } else {
100
+ framing_extras_.resize(2);
101
+ framing_extras_[0] = static_cast<std::uint8_t>(static_cast<std::uint32_t>(frame_id) << 4U | 1U);
102
+ framing_extras_[1] = static_cast<std::uint8_t>(level);
103
+ }
54
104
  }
55
105
 
56
106
  const std::string& key()
@@ -58,7 +108,12 @@ class remove_request_body
58
108
  return key_;
59
109
  }
60
110
 
61
- const std::vector<std::uint8_t>& extension()
111
+ const std::vector<std::uint8_t>& framing_extras()
112
+ {
113
+ return framing_extras_;
114
+ }
115
+
116
+ const std::vector<std::uint8_t>& extras()
62
117
  {
63
118
  static std::vector<std::uint8_t> empty;
64
119
  return empty;
@@ -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 replace_response_body
32
+ {
33
+ public:
34
+ static const inline client_opcode opcode = client_opcode::replace;
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 replace_request_body
71
+ {
72
+ public:
73
+ using response_body_type = replace_response_body;
74
+ static const inline client_opcode opcode = client_opcode::replace;
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
@@ -32,11 +32,17 @@ class sasl_auth_response_body
32
32
  std::string value_;
33
33
 
34
34
  public:
35
- bool parse(protocol::status status, const header_buffer& header, const std::vector<uint8_t>& body, const cmd_info&)
35
+ bool parse(protocol::status status,
36
+ const header_buffer& header,
37
+ std::uint8_t framing_extras_size,
38
+ std::uint16_t key_size,
39
+ std::uint8_t extras_size,
40
+ const std::vector<uint8_t>& body,
41
+ const cmd_info&)
36
42
  {
37
43
  Expects(header[1] == static_cast<uint8_t>(opcode));
38
44
  if (status == protocol::status::success || status == protocol::status::auth_continue) {
39
- value_ = { body.begin(), body.end() };
45
+ value_.assign(body.begin() + framing_extras_size + extras_size + key_size, body.end());
40
46
  return true;
41
47
  }
42
48
  return false;
@@ -74,7 +80,13 @@ class sasl_auth_request_body
74
80
  return key_;
75
81
  }
76
82
 
77
- const std::vector<std::uint8_t>& extension()
83
+ const std::vector<std::uint8_t>& framing_extras()
84
+ {
85
+ static std::vector<std::uint8_t> empty;
86
+ return empty;
87
+ }
88
+
89
+ const std::vector<std::uint8_t>& extras()
78
90
  {
79
91
  static std::vector<std::uint8_t> empty;
80
92
  return empty;