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.
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
@@ -17,7 +17,7 @@
17
17
 
18
18
  #pragma once
19
19
 
20
- #include <io/key_value_session.hxx>
20
+ #include <io/mcbp_session.hxx>
21
21
  #include <io/http_session.hxx>
22
22
 
23
23
  namespace couchbase::operations
@@ -38,18 +38,18 @@ struct command : public std::enable_shared_from_this> {
38
38
  }
39
39
 
40
40
  template<typename Handler>
41
- void send_to(std::shared_ptr<io::key_value_session> session, Handler&& handler)
41
+ void send_to(std::shared_ptr<io::mcbp_session> session, Handler&& handler)
42
42
  {
43
43
  request.opaque = session->next_opaque();
44
44
  request.encode_to(encoded);
45
- session->write_and_subscribe(request.opaque,
46
- encoded.data(),
47
- [self = this->shared_from_this(),
48
- handler = std::forward<Handler>(handler)](std::error_code ec, io::binary_message&& msg) mutable {
49
- encoded_response_type resp(msg);
50
- self->deadline.cancel();
51
- handler(make_response(ec, self->request, resp));
52
- });
45
+ session->write_and_subscribe(
46
+ request.opaque,
47
+ encoded.data(session->supports_feature(protocol::hello_feature::snappy)),
48
+ [self = this->shared_from_this(), handler = std::forward<Handler>(handler)](std::error_code ec, io::mcbp_message&& msg) mutable {
49
+ encoded_response_type resp(msg);
50
+ self->deadline.cancel();
51
+ handler(make_response(ec, self->request, resp));
52
+ });
53
53
  deadline.expires_after(std::chrono::milliseconds(2500));
54
54
  deadline.async_wait(std::bind(&command<Request>::deadline_handler, this));
55
55
  }
@@ -0,0 +1,80 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_decrement.hxx>
22
+
23
+ namespace couchbase::operations
24
+ {
25
+
26
+ struct decrement_response {
27
+ document_id id;
28
+ std::error_code ec{};
29
+ std::uint64_t content{};
30
+ std::uint64_t cas{};
31
+ mutation_token token{};
32
+ };
33
+
34
+ struct decrement_request {
35
+ using encoded_request_type = protocol::client_request<protocol::decrement_request_body>;
36
+ using encoded_response_type = protocol::client_response<protocol::decrement_response_body>;
37
+
38
+ document_id id;
39
+ std::uint16_t partition{};
40
+ std::uint32_t opaque{};
41
+ std::uint32_t expiration{ 0 };
42
+ std::uint64_t delta{ 1 };
43
+ std::optional<std::uint64_t> initial_value{};
44
+ protocol::durability_level durability_level{ protocol::durability_level::none };
45
+ std::optional<std::uint16_t> durability_timeout{};
46
+
47
+ void encode_to(encoded_request_type& encoded)
48
+ {
49
+ encoded.opaque(opaque);
50
+ encoded.partition(partition);
51
+ encoded.body().id(id);
52
+ encoded.body().delta(delta);
53
+ if (initial_value) {
54
+ encoded.body().initial_value(initial_value.value());
55
+ encoded.body().expiration(expiration);
56
+ } else {
57
+ encoded.body().initial_value(0);
58
+ encoded.body().expiration(0xffff'ffff);
59
+ }
60
+ if (durability_level != protocol::durability_level::none) {
61
+ encoded.body().durability(durability_level, durability_timeout);
62
+ }
63
+ }
64
+ };
65
+
66
+ decrement_response
67
+ make_response(std::error_code ec, decrement_request& request, decrement_request::encoded_response_type encoded)
68
+ {
69
+ decrement_response response{ request.id, ec };
70
+ if (!ec) {
71
+ response.cas = encoded.cas();
72
+ response.content = encoded.body().content();
73
+ response.token = encoded.body().token();
74
+ response.token.partition_id = request.partition;
75
+ response.token.bucket_name = response.id.bucket;
76
+ }
77
+ return response;
78
+ }
79
+
80
+ } // namespace couchbase::operations
@@ -0,0 +1,80 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_exists.hxx>
22
+
23
+ namespace couchbase::operations
24
+ {
25
+
26
+ struct exists_response {
27
+ enum class observe_status { invalid, found, not_found, persisted, logically_deleted };
28
+
29
+ document_id id;
30
+ std::error_code ec{};
31
+ std::uint16_t partition_id{};
32
+ std::uint64_t cas{};
33
+ observe_status status{ observe_status::invalid };
34
+ };
35
+
36
+ struct exists_request {
37
+ using encoded_request_type = protocol::client_request<protocol::exists_request_body>;
38
+ using encoded_response_type = protocol::client_response<protocol::exists_response_body>;
39
+
40
+ document_id id;
41
+ std::uint16_t partition{};
42
+ std::uint32_t opaque{};
43
+
44
+ void encode_to(encoded_request_type& encoded)
45
+ {
46
+ encoded.opaque(opaque);
47
+ encoded.body().id(partition, id);
48
+ }
49
+ };
50
+
51
+ exists_response
52
+ make_response(std::error_code ec, exists_request& request, exists_request::encoded_response_type encoded)
53
+ {
54
+ exists_response response{ request.id, ec, request.partition };
55
+ if (!ec) {
56
+ response.cas = encoded.body().cas();
57
+ response.partition_id = encoded.body().partition_id();
58
+ switch (encoded.body().status()) {
59
+ case 0x00:
60
+ response.status = exists_response::observe_status::found;
61
+ break;
62
+ case 0x01:
63
+ response.status = exists_response::observe_status::persisted;
64
+ break;
65
+ case 0x80:
66
+ response.status = exists_response::observe_status::not_found;
67
+ break;
68
+ case 0x81:
69
+ response.status = exists_response::observe_status::logically_deleted;
70
+ break;
71
+ default:
72
+ spdlog::warn("invalid observe status for \"{}\": {:x}", request.id, encoded.body().status());
73
+ response.status = exists_response::observe_status::invalid;
74
+ break;
75
+ }
76
+ }
77
+ return response;
78
+ }
79
+
80
+ } // namespace couchbase::operations
@@ -17,7 +17,7 @@
17
17
 
18
18
  #pragma once
19
19
 
20
- #include <operations/document_id.hxx>
20
+ #include <document_id.hxx>
21
21
  #include <protocol/cmd_get.hxx>
22
22
 
23
23
  namespace couchbase::operations
@@ -28,6 +28,7 @@ struct get_response {
28
28
  std::error_code ec{};
29
29
  std::string value{};
30
30
  std::uint64_t cas{};
31
+ std::uint32_t flags{};
31
32
  };
32
33
 
33
34
  struct get_request {
@@ -53,8 +54,9 @@ make_response(std::error_code ec, get_request& request, get_request::encoded_res
53
54
  if (!ec) {
54
55
  response.value = std::move(encoded.body().value());
55
56
  response.cas = encoded.cas();
57
+ response.flags = encoded.body().flags();
56
58
  }
57
59
  return response;
58
60
  }
59
61
 
60
- } // namespace couchbase::operations
62
+ } // namespace couchbase::operations
@@ -0,0 +1,64 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_get_and_lock.hxx>
22
+
23
+ namespace couchbase::operations
24
+ {
25
+
26
+ struct get_and_lock_response {
27
+ document_id id;
28
+ std::error_code ec{};
29
+ std::string value{};
30
+ std::uint64_t cas{};
31
+ std::uint32_t flags{};
32
+ };
33
+
34
+ struct get_and_lock_request {
35
+ using encoded_request_type = protocol::client_request<protocol::get_and_lock_request_body>;
36
+ using encoded_response_type = protocol::client_response<protocol::get_and_lock_response_body>;
37
+
38
+ document_id id;
39
+ uint16_t partition{};
40
+ uint32_t opaque{};
41
+ uint32_t lock_time{};
42
+
43
+ void encode_to(encoded_request_type& encoded)
44
+ {
45
+ encoded.opaque(opaque);
46
+ encoded.partition(partition);
47
+ encoded.body().id(id);
48
+ encoded.body().lock_time(lock_time);
49
+ }
50
+ };
51
+
52
+ get_and_lock_response
53
+ make_response(std::error_code ec, get_and_lock_request& request, get_and_lock_request::encoded_response_type encoded)
54
+ {
55
+ get_and_lock_response response{ request.id, ec };
56
+ if (!ec) {
57
+ response.value = std::move(encoded.body().value());
58
+ response.cas = encoded.cas();
59
+ response.flags = encoded.body().flags();
60
+ }
61
+ return response;
62
+ }
63
+
64
+ } // namespace couchbase::operations
@@ -0,0 +1,64 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_get_and_touch.hxx>
22
+
23
+ namespace couchbase::operations
24
+ {
25
+
26
+ struct get_and_touch_response {
27
+ document_id id;
28
+ std::error_code ec{};
29
+ std::string value{};
30
+ std::uint64_t cas{};
31
+ std::uint32_t flags{};
32
+ };
33
+
34
+ struct get_and_touch_request {
35
+ using encoded_request_type = protocol::client_request<protocol::get_and_touch_request_body>;
36
+ using encoded_response_type = protocol::client_response<protocol::get_and_touch_response_body>;
37
+
38
+ document_id id;
39
+ uint16_t partition{};
40
+ uint32_t opaque{};
41
+ uint32_t expiration{};
42
+
43
+ void encode_to(encoded_request_type& encoded)
44
+ {
45
+ encoded.opaque(opaque);
46
+ encoded.partition(partition);
47
+ encoded.body().id(id);
48
+ encoded.body().expiration(expiration);
49
+ }
50
+ };
51
+
52
+ get_and_touch_response
53
+ make_response(std::error_code ec, get_and_touch_request& request, get_and_touch_request::encoded_response_type encoded)
54
+ {
55
+ get_and_touch_response response{ request.id, ec };
56
+ if (!ec) {
57
+ response.value = std::move(encoded.body().value());
58
+ response.cas = encoded.cas();
59
+ response.flags = encoded.body().flags();
60
+ }
61
+ return response;
62
+ }
63
+
64
+ } // namespace couchbase::operations
@@ -0,0 +1,80 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_increment.hxx>
22
+
23
+ namespace couchbase::operations
24
+ {
25
+
26
+ struct increment_response {
27
+ document_id id;
28
+ std::error_code ec{};
29
+ std::uint64_t content{};
30
+ std::uint64_t cas{};
31
+ mutation_token token{};
32
+ };
33
+
34
+ struct increment_request {
35
+ using encoded_request_type = protocol::client_request<protocol::increment_request_body>;
36
+ using encoded_response_type = protocol::client_response<protocol::increment_response_body>;
37
+
38
+ document_id id;
39
+ std::uint16_t partition{};
40
+ std::uint32_t opaque{};
41
+ std::uint32_t expiration{ 0 };
42
+ std::uint64_t delta{ 1 };
43
+ std::optional<std::uint64_t> initial_value{};
44
+ protocol::durability_level durability_level{ protocol::durability_level::none };
45
+ std::optional<std::uint16_t> durability_timeout{};
46
+
47
+ void encode_to(encoded_request_type& encoded)
48
+ {
49
+ encoded.opaque(opaque);
50
+ encoded.partition(partition);
51
+ encoded.body().id(id);
52
+ encoded.body().delta(delta);
53
+ if (initial_value) {
54
+ encoded.body().initial_value(initial_value.value());
55
+ encoded.body().expiration(expiration);
56
+ } else {
57
+ encoded.body().initial_value(0);
58
+ encoded.body().expiration(0xffff'ffff);
59
+ }
60
+ if (durability_level != protocol::durability_level::none) {
61
+ encoded.body().durability(durability_level, durability_timeout);
62
+ }
63
+ }
64
+ };
65
+
66
+ increment_response
67
+ make_response(std::error_code ec, increment_request& request, increment_request::encoded_response_type encoded)
68
+ {
69
+ increment_response response{ request.id, ec };
70
+ if (!ec) {
71
+ response.cas = encoded.cas();
72
+ response.content = encoded.body().content();
73
+ response.token = encoded.body().token();
74
+ response.token.partition_id = request.partition;
75
+ response.token.bucket_name = response.id.bucket;
76
+ }
77
+ return response;
78
+ }
79
+
80
+ } // namespace couchbase::operations
@@ -0,0 +1,74 @@
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 <document_id.hxx>
21
+ #include <protocol/cmd_insert.hxx>
22
+ #include <protocol/durability_level.hxx>
23
+
24
+ namespace couchbase::operations
25
+ {
26
+
27
+ struct insert_response {
28
+ document_id id;
29
+ std::error_code ec{};
30
+ std::uint64_t cas{};
31
+ mutation_token token{};
32
+ };
33
+
34
+ struct insert_request {
35
+ using encoded_request_type = protocol::client_request<protocol::insert_request_body>;
36
+ using encoded_response_type = protocol::client_response<protocol::insert_response_body>;
37
+
38
+ document_id id;
39
+ std::string value;
40
+ uint16_t partition{};
41
+ uint32_t opaque{};
42
+ uint32_t flags{ 0 };
43
+ uint32_t expiration{ 0 };
44
+ protocol::durability_level durability_level{ protocol::durability_level::none };
45
+ std::optional<std::uint16_t> durability_timeout{};
46
+
47
+ void encode_to(encoded_request_type& encoded)
48
+ {
49
+ encoded.opaque(opaque);
50
+ encoded.partition(partition);
51
+ encoded.body().id(id);
52
+ encoded.body().expiration(expiration);
53
+ encoded.body().flags(flags);
54
+ encoded.body().content(value);
55
+ if (durability_level != protocol::durability_level::none) {
56
+ encoded.body().durability(durability_level, durability_timeout);
57
+ }
58
+ }
59
+ };
60
+
61
+ insert_response
62
+ make_response(std::error_code ec, insert_request& request, insert_request::encoded_response_type encoded)
63
+ {
64
+ insert_response response{ request.id, ec };
65
+ if (!ec) {
66
+ response.cas = encoded.cas();
67
+ response.token = encoded.body().token();
68
+ response.token.partition_id = request.partition;
69
+ response.token.bucket_name = response.id.bucket;
70
+ }
71
+ return response;
72
+ }
73
+
74
+ } // namespace couchbase::operations