couchbase 3.0.3 → 3.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (220) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +2 -3
  3. data/ext/CMakeLists.txt +4 -2
  4. data/ext/build_config.hxx.in +1 -1
  5. data/ext/build_version.hxx.in +2 -2
  6. data/ext/couchbase/bucket.hxx +1 -1
  7. data/ext/couchbase/capabilities.hxx +1 -1
  8. data/ext/couchbase/cluster.hxx +1 -1
  9. data/ext/couchbase/cluster_options.hxx +3 -1
  10. data/ext/couchbase/collections_manifest.hxx +1 -1
  11. data/ext/couchbase/configuration.hxx +1 -1
  12. data/ext/couchbase/couchbase.cxx +712 -927
  13. data/ext/couchbase/diagnostics.hxx +3 -3
  14. data/ext/couchbase/document_id.hxx +1 -1
  15. data/ext/couchbase/error_context/analytics.hxx +1 -1
  16. data/ext/couchbase/error_context/http.hxx +1 -1
  17. data/ext/couchbase/error_context/key_value.hxx +1 -1
  18. data/ext/couchbase/error_context/query.hxx +1 -1
  19. data/ext/couchbase/error_context/search.hxx +1 -1
  20. data/ext/couchbase/error_context/view.hxx +1 -1
  21. data/ext/couchbase/error_map.hxx +1 -1
  22. data/ext/couchbase/errors.hxx +1 -1
  23. data/ext/couchbase/io/dns_client.hxx +1 -1
  24. data/ext/couchbase/io/dns_codec.hxx +1 -1
  25. data/ext/couchbase/io/dns_config.hxx +1 -1
  26. data/ext/couchbase/io/dns_message.hxx +1 -1
  27. data/ext/couchbase/io/http_command.hxx +1 -1
  28. data/ext/couchbase/io/http_context.hxx +1 -1
  29. data/ext/couchbase/io/http_message.hxx +1 -1
  30. data/ext/couchbase/io/http_parser.hxx +1 -1
  31. data/ext/couchbase/io/http_session.hxx +1 -1
  32. data/ext/couchbase/io/http_session_manager.hxx +1 -1
  33. data/ext/couchbase/io/mcbp_command.hxx +1 -1
  34. data/ext/couchbase/io/mcbp_context.hxx +1 -1
  35. data/ext/couchbase/io/mcbp_message.hxx +1 -1
  36. data/ext/couchbase/io/mcbp_parser.hxx +1 -1
  37. data/ext/couchbase/io/mcbp_session.hxx +7 -1
  38. data/ext/couchbase/io/query_cache.hxx +1 -1
  39. data/ext/couchbase/io/retry_action.hxx +1 -1
  40. data/ext/couchbase/io/retry_context.hxx +1 -1
  41. data/ext/couchbase/io/retry_orchestrator.hxx +1 -1
  42. data/ext/couchbase/io/retry_reason.hxx +1 -1
  43. data/ext/couchbase/io/retry_strategy.hxx +1 -1
  44. data/ext/couchbase/io/streams.hxx +1 -1
  45. data/ext/couchbase/mutation_token.hxx +1 -1
  46. data/ext/couchbase/operations.hxx +1 -1
  47. data/ext/couchbase/operations/analytics_dataset_create.hxx +1 -1
  48. data/ext/couchbase/operations/analytics_dataset_drop.hxx +1 -1
  49. data/ext/couchbase/operations/analytics_dataset_get_all.hxx +1 -1
  50. data/ext/couchbase/operations/analytics_dataverse_create.hxx +1 -1
  51. data/ext/couchbase/operations/analytics_dataverse_drop.hxx +1 -1
  52. data/ext/couchbase/operations/analytics_get_pending_mutations.hxx +1 -1
  53. data/ext/couchbase/operations/analytics_index_create.hxx +1 -1
  54. data/ext/couchbase/operations/analytics_index_drop.hxx +1 -1
  55. data/ext/couchbase/operations/analytics_index_get_all.hxx +1 -1
  56. data/ext/couchbase/operations/analytics_link_connect.hxx +1 -1
  57. data/ext/couchbase/operations/analytics_link_disconnect.hxx +1 -1
  58. data/ext/couchbase/operations/bucket_create.hxx +1 -1
  59. data/ext/couchbase/operations/bucket_drop.hxx +1 -1
  60. data/ext/couchbase/operations/bucket_flush.hxx +1 -1
  61. data/ext/couchbase/operations/bucket_get.hxx +1 -1
  62. data/ext/couchbase/operations/bucket_get_all.hxx +1 -1
  63. data/ext/couchbase/operations/bucket_update.hxx +1 -1
  64. data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +1 -1
  65. data/ext/couchbase/operations/collection_create.hxx +2 -2
  66. data/ext/couchbase/operations/collection_drop.hxx +2 -2
  67. data/ext/couchbase/operations/collections_manifest_get.hxx +1 -1
  68. data/ext/couchbase/operations/design_document.hxx +1 -1
  69. data/ext/couchbase/operations/document_analytics.hxx +1 -1
  70. data/ext/couchbase/operations/document_append.hxx +1 -1
  71. data/ext/couchbase/operations/document_decrement.hxx +1 -1
  72. data/ext/couchbase/operations/document_exists.hxx +1 -1
  73. data/ext/couchbase/operations/document_get.hxx +1 -1
  74. data/ext/couchbase/operations/document_get_and_lock.hxx +1 -1
  75. data/ext/couchbase/operations/document_get_and_touch.hxx +1 -1
  76. data/ext/couchbase/operations/document_get_projected.hxx +1 -1
  77. data/ext/couchbase/operations/document_increment.hxx +1 -1
  78. data/ext/couchbase/operations/document_insert.hxx +1 -1
  79. data/ext/couchbase/operations/document_lookup_in.hxx +1 -1
  80. data/ext/couchbase/operations/document_mutate_in.hxx +1 -1
  81. data/ext/couchbase/operations/document_prepend.hxx +1 -1
  82. data/ext/couchbase/operations/document_query.hxx +1 -1
  83. data/ext/couchbase/operations/document_remove.hxx +1 -1
  84. data/ext/couchbase/operations/document_replace.hxx +1 -1
  85. data/ext/couchbase/operations/document_search.hxx +1 -1
  86. data/ext/couchbase/operations/document_touch.hxx +1 -1
  87. data/ext/couchbase/operations/document_unlock.hxx +1 -1
  88. data/ext/couchbase/operations/document_upsert.hxx +1 -1
  89. data/ext/couchbase/operations/document_view.hxx +1 -1
  90. data/ext/couchbase/operations/group_drop.hxx +1 -1
  91. data/ext/couchbase/operations/group_get.hxx +1 -1
  92. data/ext/couchbase/operations/group_get_all.hxx +1 -1
  93. data/ext/couchbase/operations/group_upsert.hxx +1 -1
  94. data/ext/couchbase/operations/http_noop.hxx +1 -1
  95. data/ext/couchbase/operations/mcbp_noop.hxx +1 -1
  96. data/ext/couchbase/operations/query_index_build_deferred.hxx +1 -1
  97. data/ext/couchbase/operations/query_index_create.hxx +1 -1
  98. data/ext/couchbase/operations/query_index_drop.hxx +1 -1
  99. data/ext/couchbase/operations/query_index_get_all.hxx +1 -1
  100. data/ext/couchbase/operations/rbac.hxx +1 -1
  101. data/ext/couchbase/operations/role_get_all.hxx +1 -1
  102. data/ext/couchbase/operations/scope_create.hxx +2 -2
  103. data/ext/couchbase/operations/scope_drop.hxx +2 -2
  104. data/ext/couchbase/operations/scope_get_all.hxx +2 -2
  105. data/ext/couchbase/operations/search_get_stats.hxx +1 -1
  106. data/ext/couchbase/operations/search_index.hxx +1 -1
  107. data/ext/couchbase/operations/search_index_analyze_document.hxx +1 -1
  108. data/ext/couchbase/operations/search_index_control_ingest.hxx +1 -1
  109. data/ext/couchbase/operations/search_index_control_plan_freeze.hxx +1 -1
  110. data/ext/couchbase/operations/search_index_control_query.hxx +1 -1
  111. data/ext/couchbase/operations/search_index_drop.hxx +1 -1
  112. data/ext/couchbase/operations/search_index_get.hxx +1 -1
  113. data/ext/couchbase/operations/search_index_get_all.hxx +1 -1
  114. data/ext/couchbase/operations/search_index_get_documents_count.hxx +1 -1
  115. data/ext/couchbase/operations/search_index_get_stats.hxx +1 -1
  116. data/ext/couchbase/operations/search_index_upsert.hxx +1 -1
  117. data/ext/couchbase/operations/user_drop.hxx +1 -1
  118. data/ext/couchbase/operations/user_get.hxx +1 -1
  119. data/ext/couchbase/operations/user_get_all.hxx +1 -1
  120. data/ext/couchbase/operations/user_upsert.hxx +1 -1
  121. data/ext/couchbase/operations/view_index_drop.hxx +1 -1
  122. data/ext/couchbase/operations/view_index_get.hxx +1 -1
  123. data/ext/couchbase/operations/view_index_get_all.hxx +1 -1
  124. data/ext/couchbase/operations/view_index_upsert.hxx +1 -1
  125. data/ext/couchbase/origin.hxx +1 -1
  126. data/ext/couchbase/protocol/client_opcode.hxx +1 -1
  127. data/ext/couchbase/protocol/client_request.hxx +1 -1
  128. data/ext/couchbase/protocol/client_response.hxx +1 -1
  129. data/ext/couchbase/protocol/cmd_append.hxx +1 -1
  130. data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +1 -1
  131. data/ext/couchbase/protocol/cmd_decrement.hxx +1 -1
  132. data/ext/couchbase/protocol/cmd_exists.hxx +1 -1
  133. data/ext/couchbase/protocol/cmd_get.hxx +1 -1
  134. data/ext/couchbase/protocol/cmd_get_and_lock.hxx +1 -1
  135. data/ext/couchbase/protocol/cmd_get_and_touch.hxx +1 -1
  136. data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +1 -1
  137. data/ext/couchbase/protocol/cmd_get_collection_id.hxx +7 -7
  138. data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +1 -1
  139. data/ext/couchbase/protocol/cmd_get_error_map.hxx +1 -1
  140. data/ext/couchbase/protocol/cmd_hello.hxx +11 -3
  141. data/ext/couchbase/protocol/cmd_increment.hxx +1 -1
  142. data/ext/couchbase/protocol/cmd_info.hxx +1 -1
  143. data/ext/couchbase/protocol/cmd_insert.hxx +1 -1
  144. data/ext/couchbase/protocol/cmd_lookup_in.hxx +1 -1
  145. data/ext/couchbase/protocol/cmd_mutate_in.hxx +1 -1
  146. data/ext/couchbase/protocol/cmd_noop.hxx +1 -1
  147. data/ext/couchbase/protocol/cmd_prepend.hxx +1 -1
  148. data/ext/couchbase/protocol/cmd_remove.hxx +1 -1
  149. data/ext/couchbase/protocol/cmd_replace.hxx +1 -1
  150. data/ext/couchbase/protocol/cmd_sasl_auth.hxx +1 -1
  151. data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +1 -1
  152. data/ext/couchbase/protocol/cmd_sasl_step.hxx +1 -1
  153. data/ext/couchbase/protocol/cmd_select_bucket.hxx +1 -1
  154. data/ext/couchbase/protocol/cmd_touch.hxx +1 -1
  155. data/ext/couchbase/protocol/cmd_unlock.hxx +1 -1
  156. data/ext/couchbase/protocol/cmd_upsert.hxx +1 -1
  157. data/ext/couchbase/protocol/datatype.hxx +1 -1
  158. data/ext/couchbase/protocol/durability_level.hxx +1 -1
  159. data/ext/couchbase/protocol/enhanced_error_info.hxx +1 -1
  160. data/ext/couchbase/protocol/frame_info_id.hxx +1 -1
  161. data/ext/couchbase/protocol/hello_feature.hxx +1 -1
  162. data/ext/couchbase/protocol/magic.hxx +1 -1
  163. data/ext/couchbase/protocol/server_opcode.hxx +1 -1
  164. data/ext/couchbase/protocol/server_request.hxx +1 -1
  165. data/ext/couchbase/protocol/status.hxx +1 -1
  166. data/ext/couchbase/service_type.hxx +1 -1
  167. data/ext/couchbase/timeout_defaults.hxx +1 -1
  168. data/ext/couchbase/utils/byteswap.hxx +1 -1
  169. data/ext/couchbase/utils/connection_string.hxx +19 -1
  170. data/ext/couchbase/version.hxx +2 -2
  171. data/ext/extconf.rb +1 -1
  172. data/ext/test/test_helper.hxx +1 -1
  173. data/ext/test/test_helper_native.hxx +1 -1
  174. data/ext/test/test_helper_ruby.hxx +1 -1
  175. data/ext/test/test_native_binary_operations.cxx +1 -1
  176. data/ext/test/test_native_diagnostics.cxx +1 -1
  177. data/ext/test/test_native_trivial_crud.cxx +1 -1
  178. data/ext/test/test_ruby_trivial_crud.cxx +1 -1
  179. data/ext/test/test_ruby_trivial_query.cxx +1 -1
  180. data/lib/active_support/cache/couchbase_store.rb +1 -1
  181. data/lib/couchbase.rb +1 -1
  182. data/lib/couchbase/analytics_options.rb +1 -1
  183. data/lib/couchbase/authenticator.rb +1 -1
  184. data/lib/couchbase/binary_collection.rb +1 -1
  185. data/lib/couchbase/binary_collection_options.rb +1 -1
  186. data/lib/couchbase/bucket.rb +1 -1
  187. data/lib/couchbase/cluster.rb +2 -2
  188. data/lib/couchbase/collection.rb +1 -1
  189. data/lib/couchbase/collection_options.rb +25 -19
  190. data/lib/couchbase/configuration.rb +1 -1
  191. data/lib/couchbase/datastructures.rb +1 -1
  192. data/lib/couchbase/datastructures/couchbase_list.rb +1 -1
  193. data/lib/couchbase/datastructures/couchbase_map.rb +1 -1
  194. data/lib/couchbase/datastructures/couchbase_queue.rb +1 -1
  195. data/lib/couchbase/datastructures/couchbase_set.rb +1 -1
  196. data/lib/couchbase/diagnostics.rb +1 -1
  197. data/lib/couchbase/errors.rb +1 -1
  198. data/lib/couchbase/json_transcoder.rb +1 -1
  199. data/lib/couchbase/logger.rb +1 -1
  200. data/lib/couchbase/management.rb +1 -1
  201. data/lib/couchbase/management/analytics_index_manager.rb +1 -1
  202. data/lib/couchbase/management/bucket_manager.rb +1 -1
  203. data/lib/couchbase/management/collection_manager.rb +8 -1
  204. data/lib/couchbase/management/query_index_manager.rb +1 -1
  205. data/lib/couchbase/management/search_index_manager.rb +1 -1
  206. data/lib/couchbase/management/user_manager.rb +1 -1
  207. data/lib/couchbase/management/view_index_manager.rb +1 -1
  208. data/lib/couchbase/mutation_state.rb +1 -1
  209. data/lib/couchbase/options.rb +13 -4
  210. data/lib/couchbase/query_options.rb +1 -1
  211. data/lib/couchbase/railtie.rb +1 -1
  212. data/lib/couchbase/scope.rb +7 -6
  213. data/lib/couchbase/search_options.rb +1 -1
  214. data/lib/couchbase/subdoc.rb +1 -1
  215. data/lib/couchbase/utils.rb +1 -1
  216. data/lib/couchbase/utils/time.rb +1 -1
  217. data/lib/couchbase/version.rb +2 -2
  218. data/lib/couchbase/view_options.rb +1 -1
  219. data/lib/rails/generators/couchbase/config/config_generator.rb +1 -1
  220. metadata +5 -5
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 850654b24f508816010fe6558dc0b5e50bd6a4a54667c17d929988762ea836c6
4
- data.tar.gz: 4e6f334a34c80ec64fa15a8fbf16f22a913bded0e10aed76e5870db6ded5a17b
3
+ metadata.gz: 6610fe0ac9f660835b0bfaf36f53673e35213f29440ceda426bfb6f488195b95
4
+ data.tar.gz: 734c1253fae466f3698046cf37d532f4ec754d2ed35d7d5c37c48539a59ce9ee
5
5
  SHA512:
6
- metadata.gz: d1e7b161fe8fbca8d8ca8d524014f6be1eb0fd7dffb3295f18ee6aa2b20997c2ff0277b90011a3330892e3173038b0667e73e791b945ee7490bda7a9abebe52d
7
- data.tar.gz: b72cb74eb7f1a34fd0ed0421af78d1a322f2dde47f615466cf9aaf80e3a5f7f4420110650b400a515f4b0f4ada98c388b00b0feff5b416e1216e59c58299500f
6
+ metadata.gz: d8ef7b9f1c6f417b4e803f12b64682980dcc9f69c8ebfc462b72dbeb60e306ee6a33176ca320cd85bd9974ff5b457d51e26ebf7dfbe2251bb6bbfd1a92b12077
7
+ data.tar.gz: 8ce0c1aab3a6f48295bf5a312a4bda8bc6668b3de079b60c4549bb8c1e27662eac49284c218928d5ffb60b7af799a01cdab736ae8d484eebc17e1b23b360aa8f
data/README.md CHANGED
@@ -5,7 +5,6 @@
5
5
  [![commits](https://img.shields.io/github/commits-since/couchbase/couchbase-ruby-client/latest?color=brightgreen)](https://github.com/couchbase/couchbase-ruby-client/commits/master)
6
6
  [![tests](https://img.shields.io/github/workflow/status/couchbase/couchbase-ruby-client/tests?label=tests)](https://github.com/couchbase/couchbase-ruby-client/actions?query=workflow%3Atests)
7
7
  [![linters](https://img.shields.io/github/workflow/status/couchbase/couchbase-ruby-client/linters?label=linters)](https://github.com/couchbase/couchbase-ruby-client/actions?query=workflow%3Alinters)
8
- [![jenkins](https://img.shields.io/jenkins/build?jobUrl=http%3A%2F%2Fsdk.jenkins.couchbase.com%2Fjob%2Fruby%2Fjob%2Fruby-nightly%2F&label=jenkins)](http://sdk.jenkins.couchbase.com/job/ruby/job/ruby-nightly/)
9
8
 
10
9
  This repository contains the third generation of the official Couchbase SDK for Ruby (aka. SDKv3)
11
10
 
@@ -25,7 +24,7 @@ The library tested with the MRI 2.5, 2.6, 2.7 and 3.0. Supported platforms are L
25
24
  Add this line to your application's Gemfile:
26
25
 
27
26
  ```ruby
28
- gem "couchbase", "3.0.3"
27
+ gem "couchbase", "3.1.0"
29
28
  ```
30
29
 
31
30
  And then execute:
@@ -116,7 +115,7 @@ Now the API reference is accessible using web browser (where `VERSION` is curren
116
115
 
117
116
  The gem is available as open source under the terms of the [Apache2 License](https://opensource.org/licenses/Apache-2.0).
118
117
 
119
- Copyright 2011-2020 Couchbase, Inc.
118
+ Copyright 2011-2021 Couchbase, Inc.
120
119
 
121
120
  Licensed under the Apache License, Version 2.0 (the "License");
122
121
  you may not use this file except in compliance with the License.
data/ext/CMakeLists.txt CHANGED
@@ -95,9 +95,11 @@ else()
95
95
  message(STATUS "RUBY_VERSION: ${RUBY_VERSION}")
96
96
  message(STATUS "RUBY_EXECUTABLE: ${RUBY_EXECUTABLE}")
97
97
  endif()
98
- message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}")
99
98
  message(STATUS "RUBY_LIBRARY: ${RUBY_LIBRARY}")
100
- include_directories(BEFORE SYSTEM "${RUBY_INCLUDE_DIR}")
99
+ if(RUBY_INCLUDE_DIR)
100
+ message(STATUS "RUBY_INCLUDE_DIR: ${RUBY_INCLUDE_DIR}")
101
+ include_directories(BEFORE SYSTEM "${RUBY_INCLUDE_DIR}")
102
+ endif()
101
103
 
102
104
  add_library(couchbase SHARED couchbase/couchbase.cxx)
103
105
  target_include_directories(couchbase PRIVATE ${PROJECT_BINARY_DIR}/generated)
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -26,5 +26,5 @@ constexpr auto BACKEND_CXX_COMPILER = "@CMAKE_CXX_COMPILER_ID@ @CMAKE_CXX_COMPIL
26
26
  constexpr auto BACKEND_C_COMPILER = "@CMAKE_C_COMPILER_ID@ @CMAKE_C_COMPILER_VERSION@";
27
27
  constexpr auto BACKEND_SYSTEM = "@CMAKE_SYSTEM@";
28
28
  constexpr auto BACKEND_SYSTEM_PROCESSOR = "@CMAKE_SYSTEM_PROCESSOR@";
29
- constexpr auto BACKEND_GIT_REVISION = "bcb5da39fd4dfd3bd7ce917abc89faf1fbcd7d5f";
29
+ constexpr auto BACKEND_GIT_REVISION = "7ba4f7d8b5b0b59b9971ad765876413be3064adb";
30
30
  } // namespace couchbase
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -40,6 +40,8 @@ struct cluster_options {
40
40
  bool force_ipv4{ false };
41
41
  bool enable_dns_srv{ true };
42
42
  bool show_queries{ false };
43
+ bool enable_unordered_execution{ true };
44
+ bool enable_clustermap_notification{ true };
43
45
  std::string network{ "auto" };
44
46
 
45
47
  std::chrono::milliseconds tcp_keep_alive_interval = timeout_defaults::tcp_keep_alive_interval;
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -1,6 +1,6 @@
1
1
  /* -*- Mode: C++; tab-width: 4; c-basic-offset: 4; indent-tabs-mode: nil -*- */
2
2
  /*
3
- * Copyright 2020 Couchbase, Inc.
3
+ * Copyright 2020-2021 Couchbase, Inc.
4
4
  *
5
5
  * Licensed under the Apache License, Version 2.0 (the "License");
6
6
  * you may not use this file except in compliance with the License.
@@ -22,6 +22,7 @@
22
22
  #include <openssl/crypto.h>
23
23
 
24
24
  #include <spdlog/spdlog.h>
25
+
25
26
  #include <spdlog/cfg/env.h>
26
27
 
27
28
  #include <http_parser.h>
@@ -40,15 +41,22 @@
40
41
  #if defined(HAVE_RUBY_VERSION_H)
41
42
  #include <ruby/version.h>
42
43
  #endif
44
+ #include <ruby/thread.h>
43
45
 
44
46
  #if defined(RB_METHOD_DEFINITION_DECL) || RUBY_API_VERSION_MAJOR == 3
45
- #define VALUE_FUNC(f) (f)
46
- #define INT_FUNC(f) (f)
47
+ #define VALUE_FUNC(f) f
48
+ #define INT_FUNC(f) f
47
49
  #else
48
50
  #define VALUE_FUNC(f) reinterpret_cast<VALUE (*)(ANYARGS)>(f)
49
51
  #define INT_FUNC(f) reinterpret_cast<int (*)(ANYARGS)>(f)
50
52
  #endif
51
53
 
54
+ static inline VALUE
55
+ cb_str_new(const std::string& str)
56
+ {
57
+ return rb_external_str_new(str.data(), static_cast<long>(str.size()));
58
+ }
59
+
52
60
  static void
53
61
  init_versions(VALUE mCouchbase)
54
62
  {
@@ -59,12 +67,10 @@ init_versions(VALUE mCouchbase)
59
67
  cb_Version = rb_hash_new();
60
68
  rb_const_set(mCouchbase, rb_intern("VERSION"), cb_Version);
61
69
  }
62
- #define VERSION_SPLIT_(VER) (VER) / 100000, (VER) / 100 % 1000, (VER) % 100
63
70
 
64
71
  std::string ver;
65
72
  ver = fmt::format("{}.{}.{}", couchbase::BACKEND_VERSION_MAJOR, couchbase::BACKEND_VERSION_MINOR, couchbase::BACKEND_VERSION_PATCH);
66
- rb_hash_aset(
67
- cb_Version, rb_id2sym(rb_intern("backend")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
73
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("backend")), rb_str_freeze(cb_str_new(ver)));
68
74
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("build_timestamp")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_BUILD_TIMESTAMP)));
69
75
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("revision")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_GIT_REVISION)));
70
76
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("platform")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_SYSTEM)));
@@ -73,19 +79,16 @@ init_versions(VALUE mCouchbase)
73
79
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("cxx")), rb_str_freeze(rb_str_new_cstr(couchbase::BACKEND_CXX_COMPILER)));
74
80
  #if defined(HAVE_RUBY_VERSION_H)
75
81
  ver = fmt::format("{}.{}.{}", RUBY_API_VERSION_MAJOR, RUBY_API_VERSION_MINOR, RUBY_API_VERSION_TEENY);
76
- rb_hash_aset(cb_Version, rb_id2sym(rb_intern("ruby")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
82
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("ruby")), rb_str_freeze(cb_str_new(ver)));
77
83
  #endif
78
84
  ver = fmt::format("{}.{}.{}", SPDLOG_VER_MAJOR, SPDLOG_VER_MINOR, SPDLOG_VER_PATCH);
79
- rb_hash_aset(
80
- cb_Version, rb_id2sym(rb_intern("spdlog")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
81
- ver = fmt::format("{}.{}.{}", VERSION_SPLIT_(ASIO_VERSION));
82
- rb_hash_aset(cb_Version, rb_id2sym(rb_intern("asio")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
85
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("spdlog")), rb_str_freeze(cb_str_new(ver)));
86
+ ver = fmt::format("{}.{}.{}", ASIO_VERSION / 100'000, ASIO_VERSION / 100 % 1000, ASIO_VERSION % 100);
87
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("asio")), rb_str_freeze(cb_str_new(ver)));
83
88
  ver = fmt::format("{}.{}.{}", SNAPPY_MAJOR, SNAPPY_MINOR, SNAPPY_PATCHLEVEL);
84
- rb_hash_aset(
85
- cb_Version, rb_id2sym(rb_intern("snappy")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
89
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("snappy")), rb_str_freeze(cb_str_new(ver)));
86
90
  ver = fmt::format("{}.{}.{}", HTTP_PARSER_VERSION_MAJOR, HTTP_PARSER_VERSION_MINOR, HTTP_PARSER_VERSION_PATCH);
87
- rb_hash_aset(
88
- cb_Version, rb_id2sym(rb_intern("http_parser")), rb_str_freeze(rb_external_str_new(ver.c_str(), static_cast<long>(ver.size()))));
91
+ rb_hash_aset(cb_Version, rb_id2sym(rb_intern("http_parser")), rb_str_freeze(cb_str_new(ver)));
89
92
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("openssl_headers")), rb_str_freeze(rb_str_new_cstr(OPENSSL_VERSION_TEXT)));
90
93
  #if defined(OPENSSL_VERSION)
91
94
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("openssl_runtime")), rb_str_freeze(rb_str_new_cstr(OpenSSL_version(OPENSSL_VERSION))));
@@ -93,8 +96,6 @@ init_versions(VALUE mCouchbase)
93
96
  rb_hash_aset(cb_Version, rb_id2sym(rb_intern("openssl_runtime")), rb_str_freeze(rb_str_new_cstr(SSLeay_version(SSLEAY_VERSION))));
94
97
  #endif
95
98
 
96
- #undef VERSION_SPLIT_
97
-
98
99
  VALUE version_info = rb_inspect(cb_Version);
99
100
  spdlog::info("couchbase backend has been initialized: {}",
100
101
  std::string_view(RSTRING_PTR(version_info), static_cast<std::size_t>(RSTRING_LEN(version_info))));
@@ -133,7 +134,7 @@ struct cb_backend_data {
133
134
  };
134
135
 
135
136
  static void
136
- cb__backend_close(cb_backend_data* backend)
137
+ cb_backend_close(cb_backend_data* backend)
137
138
  {
138
139
  if (backend->cluster) {
139
140
  auto barrier = std::make_shared<std::promise<void>>();
@@ -156,15 +157,15 @@ cb_Backend_mark(void* /* ptr */)
156
157
  static void
157
158
  cb_Backend_free(void* ptr)
158
159
  {
159
- auto* backend = reinterpret_cast<cb_backend_data*>(ptr);
160
- cb__backend_close(backend);
160
+ auto* backend = static_cast<cb_backend_data*>(ptr);
161
+ cb_backend_close(backend);
161
162
  ruby_xfree(backend);
162
163
  }
163
164
 
164
165
  static size_t
165
166
  cb_Backend_memsize(const void* ptr)
166
167
  {
167
- const auto* backend = reinterpret_cast<const cb_backend_data*>(ptr);
168
+ const auto* backend = static_cast<const cb_backend_data*>(ptr);
168
169
  return sizeof(*backend) + sizeof(*backend->cluster);
169
170
  }
170
171
 
@@ -196,8 +197,6 @@ cb_Backend_allocate(VALUE klass)
196
197
  return obj;
197
198
  }
198
199
 
199
- static VALUE eCouchbaseError;
200
- static VALUE eTimeout;
201
200
  static VALUE eAmbiguousTimeout;
202
201
  static VALUE eAuthenticationFailure;
203
202
  static VALUE eBucketExists;
@@ -276,9 +275,9 @@ static void
276
275
  init_exceptions(VALUE mCouchbase)
277
276
  {
278
277
  VALUE mError = rb_define_module_under(mCouchbase, "Error");
279
- eCouchbaseError = rb_define_class_under(mError, "CouchbaseError", rb_eStandardError);
278
+ VALUE eCouchbaseError = rb_define_class_under(mError, "CouchbaseError", rb_eStandardError);
280
279
 
281
- eTimeout = rb_define_class_under(mError, "Timeout", eCouchbaseError);
280
+ VALUE eTimeout = rb_define_class_under(mError, "Timeout", eCouchbaseError);
282
281
 
283
282
  eAmbiguousTimeout = rb_define_class_under(mError, "AmbiguousTimeout", eTimeout);
284
283
  eAuthenticationFailure = rb_define_class_under(mError, "AuthenticationFailure", eCouchbaseError);
@@ -356,7 +355,7 @@ init_exceptions(VALUE mCouchbase)
356
355
  }
357
356
 
358
357
  static VALUE
359
- cb__map_error_code(std::error_code ec, const std::string& message)
358
+ cb_map_error_code(std::error_code ec, const std::string& message)
360
359
  {
361
360
  if (ec.category() == couchbase::error::detail::get_common_category()) {
362
361
  switch (static_cast<couchbase::error::common_errc>(ec.value())) {
@@ -589,44 +588,30 @@ cb__map_error_code(std::error_code ec, const std::string& message)
589
588
  }
590
589
 
591
590
  static VALUE
592
- cb__map_error_code(const couchbase::error_context::key_value& ctx, const std::string& message)
591
+ cb_map_error_code(const couchbase::error_context::key_value& ctx, const std::string& message)
593
592
  {
594
- VALUE exc = cb__map_error_code(ctx.ec, message);
593
+ VALUE exc = cb_map_error_code(ctx.ec, message);
595
594
  VALUE error_context = rb_hash_new();
596
595
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
597
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
598
- rb_hash_aset(error_context, rb_id2sym(rb_intern("id")), rb_external_str_new(ctx.id.key.data(), static_cast<long>(ctx.id.key.size())));
599
- rb_hash_aset(error_context,
600
- rb_id2sym(rb_intern("collection")),
601
- rb_external_str_new(ctx.id.collection.data(), static_cast<long>(ctx.id.collection.size())));
602
- rb_hash_aset(
603
- error_context, rb_id2sym(rb_intern("bucket")), rb_external_str_new(ctx.id.bucket.data(), static_cast<long>(ctx.id.bucket.size())));
596
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
597
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("id")), cb_str_new(ctx.id.key));
598
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("collection")), cb_str_new(ctx.id.collection));
599
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("bucket")), cb_str_new(ctx.id.bucket));
604
600
  rb_hash_aset(error_context, rb_id2sym(rb_intern("opaque")), ULONG2NUM(ctx.opaque));
605
601
  if (ctx.status_code) {
606
602
  std::string status(fmt::format("{}", ctx.status_code.value()));
607
- rb_hash_aset(error_context, rb_id2sym(rb_intern("status")), rb_external_str_new(status.data(), static_cast<long>(status.size())));
603
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("status")), cb_str_new(status));
608
604
  }
609
605
  if (ctx.error_map_info) {
610
606
  VALUE error_map_info = rb_hash_new();
611
- rb_hash_aset(error_map_info,
612
- rb_id2sym(rb_intern("name")),
613
- rb_external_str_new(ctx.error_map_info->name.data(), static_cast<long>(ctx.error_map_info->name.size())));
614
- rb_hash_aset(
615
- error_map_info,
616
- rb_id2sym(rb_intern("desc")),
617
- rb_external_str_new(ctx.error_map_info->description.data(), static_cast<long>(ctx.error_map_info->description.size())));
607
+ rb_hash_aset(error_map_info, rb_id2sym(rb_intern("name")), cb_str_new(ctx.error_map_info->name));
608
+ rb_hash_aset(error_map_info, rb_id2sym(rb_intern("desc")), cb_str_new(ctx.error_map_info->description));
618
609
  rb_hash_aset(error_context, rb_id2sym(rb_intern("error_map_info")), error_map_info);
619
610
  }
620
611
  if (ctx.enhanced_error_info) {
621
612
  VALUE enhanced_error_info = rb_hash_new();
622
- rb_hash_aset(
623
- enhanced_error_info,
624
- rb_id2sym(rb_intern("reference")),
625
- rb_external_str_new(ctx.enhanced_error_info->reference.data(), static_cast<long>(ctx.enhanced_error_info->reference.size())));
626
- rb_hash_aset(
627
- enhanced_error_info,
628
- rb_id2sym(rb_intern("context")),
629
- rb_external_str_new(ctx.enhanced_error_info->context.data(), static_cast<long>(ctx.enhanced_error_info->context.size())));
613
+ rb_hash_aset(enhanced_error_info, rb_id2sym(rb_intern("reference")), cb_str_new(ctx.enhanced_error_info->reference));
614
+ rb_hash_aset(enhanced_error_info, rb_id2sym(rb_intern("context")), cb_str_new(ctx.enhanced_error_info->context));
630
615
  rb_hash_aset(error_context, rb_id2sym(rb_intern("extended_error_info")), enhanced_error_info);
631
616
  }
632
617
  if (ctx.retry_attempts > 0) {
@@ -641,39 +626,29 @@ cb__map_error_code(const couchbase::error_context::key_value& ctx, const std::st
641
626
  }
642
627
  }
643
628
  if (ctx.last_dispatched_to) {
644
- rb_hash_aset(error_context,
645
- rb_id2sym(rb_intern("last_dispatched_to")),
646
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
629
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
647
630
  }
648
631
  if (ctx.last_dispatched_from) {
649
- rb_hash_aset(error_context,
650
- rb_id2sym(rb_intern("last_dispatched_from")),
651
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
632
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
652
633
  }
653
634
  rb_iv_set(exc, "@context", error_context);
654
635
  return exc;
655
636
  }
656
637
 
657
638
  static VALUE
658
- cb__map_error_code(const couchbase::error_context::query& ctx, const std::string& message)
639
+ cb_map_error_code(const couchbase::error_context::query& ctx, const std::string& message)
659
640
  {
660
- VALUE exc = cb__map_error_code(ctx.ec, message);
641
+ VALUE exc = cb_map_error_code(ctx.ec, message);
661
642
  VALUE error_context = rb_hash_new();
662
643
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
663
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
664
- rb_hash_aset(error_context,
665
- rb_id2sym(rb_intern("client_context_id")),
666
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
667
- rb_hash_aset(
668
- error_context, rb_id2sym(rb_intern("statement")), rb_external_str_new(ctx.statement.data(), static_cast<long>(ctx.statement.size())));
644
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
645
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
646
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("statement")), cb_str_new(ctx.statement));
669
647
  if (ctx.parameters) {
670
- rb_hash_aset(error_context,
671
- rb_id2sym(rb_intern("parameters")),
672
- rb_external_str_new(ctx.parameters->data(), static_cast<long>(ctx.parameters->size())));
648
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), cb_str_new(ctx.parameters.value()));
673
649
  }
674
650
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
675
- rb_hash_aset(
676
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
651
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
677
652
  if (ctx.retry_attempts > 0) {
678
653
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
679
654
  if (!ctx.retry_reasons.empty()) {
@@ -686,39 +661,29 @@ cb__map_error_code(const couchbase::error_context::query& ctx, const std::string
686
661
  }
687
662
  }
688
663
  if (ctx.last_dispatched_to) {
689
- rb_hash_aset(error_context,
690
- rb_id2sym(rb_intern("last_dispatched_to")),
691
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
664
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
692
665
  }
693
666
  if (ctx.last_dispatched_from) {
694
- rb_hash_aset(error_context,
695
- rb_id2sym(rb_intern("last_dispatched_from")),
696
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
667
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
697
668
  }
698
669
  rb_iv_set(exc, "@context", error_context);
699
670
  return exc;
700
671
  }
701
672
 
702
673
  static VALUE
703
- cb__map_error_code(const couchbase::error_context::analytics& ctx, const std::string& message)
674
+ cb_map_error_code(const couchbase::error_context::analytics& ctx, const std::string& message)
704
675
  {
705
- VALUE exc = cb__map_error_code(ctx.ec, message);
676
+ VALUE exc = cb_map_error_code(ctx.ec, message);
706
677
  VALUE error_context = rb_hash_new();
707
678
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
708
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
709
- rb_hash_aset(error_context,
710
- rb_id2sym(rb_intern("client_context_id")),
711
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
712
- rb_hash_aset(
713
- error_context, rb_id2sym(rb_intern("statement")), rb_external_str_new(ctx.statement.data(), static_cast<long>(ctx.statement.size())));
679
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
680
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
681
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("statement")), cb_str_new(ctx.statement));
714
682
  if (ctx.parameters) {
715
- rb_hash_aset(error_context,
716
- rb_id2sym(rb_intern("parameters")),
717
- rb_external_str_new(ctx.parameters->data(), static_cast<long>(ctx.parameters->size())));
683
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), cb_str_new(ctx.parameters.value()));
718
684
  }
719
685
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
720
- rb_hash_aset(
721
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
686
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
722
687
  if (ctx.retry_attempts > 0) {
723
688
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
724
689
  if (!ctx.retry_reasons.empty()) {
@@ -731,44 +696,34 @@ cb__map_error_code(const couchbase::error_context::analytics& ctx, const std::st
731
696
  }
732
697
  }
733
698
  if (ctx.last_dispatched_to) {
734
- rb_hash_aset(error_context,
735
- rb_id2sym(rb_intern("last_dispatched_to")),
736
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
699
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
737
700
  }
738
701
  if (ctx.last_dispatched_from) {
739
- rb_hash_aset(error_context,
740
- rb_id2sym(rb_intern("last_dispatched_from")),
741
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
702
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
742
703
  }
743
704
  rb_iv_set(exc, "@context", error_context);
744
705
  return exc;
745
706
  }
746
707
 
747
708
  static VALUE
748
- cb__map_error_code(const couchbase::error_context::view& ctx, const std::string& message)
709
+ cb_map_error_code(const couchbase::error_context::view& ctx, const std::string& message)
749
710
  {
750
- VALUE exc = cb__map_error_code(ctx.ec, message);
711
+ VALUE exc = cb_map_error_code(ctx.ec, message);
751
712
  VALUE error_context = rb_hash_new();
752
713
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
753
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
754
- rb_hash_aset(error_context,
755
- rb_id2sym(rb_intern("client_context_id")),
756
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
757
- rb_hash_aset(error_context,
758
- rb_id2sym(rb_intern("design_document_name")),
759
- rb_external_str_new(ctx.design_document_name.data(), static_cast<long>(ctx.design_document_name.size())));
760
- rb_hash_aset(
761
- error_context, rb_id2sym(rb_intern("view_name")), rb_external_str_new(ctx.view_name.data(), static_cast<long>(ctx.view_name.size())));
714
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
715
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
716
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("design_document_name")), cb_str_new(ctx.design_document_name));
717
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("view_name")), cb_str_new(ctx.view_name));
762
718
  if (!ctx.query_string.empty()) {
763
719
  VALUE parameters = rb_ary_new_capa(static_cast<long>(ctx.query_string.size()));
764
720
  for (const auto& param : ctx.query_string) {
765
- rb_ary_push(parameters, rb_external_str_new(param.data(), static_cast<long>(param.size())));
721
+ rb_ary_push(parameters, cb_str_new(param));
766
722
  }
767
723
  rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), parameters);
768
724
  }
769
725
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
770
- rb_hash_aset(
771
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
726
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
772
727
  if (ctx.retry_attempts > 0) {
773
728
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
774
729
  if (!ctx.retry_reasons.empty()) {
@@ -781,35 +736,27 @@ cb__map_error_code(const couchbase::error_context::view& ctx, const std::string&
781
736
  }
782
737
  }
783
738
  if (ctx.last_dispatched_to) {
784
- rb_hash_aset(error_context,
785
- rb_id2sym(rb_intern("last_dispatched_to")),
786
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
739
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
787
740
  }
788
741
  if (ctx.last_dispatched_from) {
789
- rb_hash_aset(error_context,
790
- rb_id2sym(rb_intern("last_dispatched_from")),
791
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
742
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
792
743
  }
793
744
  rb_iv_set(exc, "@context", error_context);
794
745
  return exc;
795
746
  }
796
747
 
797
748
  static VALUE
798
- cb__map_error_code(const couchbase::error_context::http& ctx, const std::string& message)
749
+ cb_map_error_code(const couchbase::error_context::http& ctx, const std::string& message)
799
750
  {
800
- VALUE exc = cb__map_error_code(ctx.ec, message);
751
+ VALUE exc = cb_map_error_code(ctx.ec, message);
801
752
  VALUE error_context = rb_hash_new();
802
753
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
803
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
804
- rb_hash_aset(error_context,
805
- rb_id2sym(rb_intern("client_context_id")),
806
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
807
- rb_hash_aset(
808
- error_context, rb_id2sym(rb_intern("method")), rb_external_str_new(ctx.method.data(), static_cast<long>(ctx.method.size())));
809
- rb_hash_aset(error_context, rb_id2sym(rb_intern("path")), rb_external_str_new(ctx.path.data(), static_cast<long>(ctx.path.size())));
754
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
755
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
756
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("method")), cb_str_new(ctx.method));
757
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("path")), cb_str_new(ctx.path));
810
758
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
811
- rb_hash_aset(
812
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
759
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
813
760
  if (ctx.retry_attempts > 0) {
814
761
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
815
762
  if (!ctx.retry_reasons.empty()) {
@@ -822,44 +769,32 @@ cb__map_error_code(const couchbase::error_context::http& ctx, const std::string&
822
769
  }
823
770
  }
824
771
  if (ctx.last_dispatched_to) {
825
- rb_hash_aset(error_context,
826
- rb_id2sym(rb_intern("last_dispatched_to")),
827
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
772
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
828
773
  }
829
774
  if (ctx.last_dispatched_from) {
830
- rb_hash_aset(error_context,
831
- rb_id2sym(rb_intern("last_dispatched_from")),
832
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
775
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
833
776
  }
834
777
  rb_iv_set(exc, "@context", error_context);
835
778
  return exc;
836
779
  }
837
780
 
838
781
  static VALUE
839
- cb__map_error_code(const couchbase::error_context::search& ctx, const std::string& message)
782
+ cb_map_error_code(const couchbase::error_context::search& ctx, const std::string& message)
840
783
  {
841
- VALUE exc = cb__map_error_code(ctx.ec, message);
784
+ VALUE exc = cb_map_error_code(ctx.ec, message);
842
785
  VALUE error_context = rb_hash_new();
843
786
  std::string error(fmt::format("{}, {}", ctx.ec.value(), ctx.ec.message()));
844
- rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), rb_external_str_new(error.data(), static_cast<long>(error.size())));
845
- rb_hash_aset(error_context,
846
- rb_id2sym(rb_intern("client_context_id")),
847
- rb_external_str_new(ctx.client_context_id.data(), static_cast<long>(ctx.client_context_id.size())));
848
- rb_hash_aset(error_context,
849
- rb_id2sym(rb_intern("index_name")),
850
- rb_external_str_new(ctx.index_name.data(), static_cast<long>(ctx.index_name.size())));
787
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("error")), cb_str_new(error));
788
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("client_context_id")), cb_str_new(ctx.client_context_id));
789
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("index_name")), cb_str_new(ctx.index_name));
851
790
  if (ctx.query) {
852
- rb_hash_aset(
853
- error_context, rb_id2sym(rb_intern("query")), rb_external_str_new(ctx.query->data(), static_cast<long>(ctx.query->size())));
791
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("query")), cb_str_new(ctx.query.value()));
854
792
  }
855
793
  if (ctx.parameters) {
856
- rb_hash_aset(error_context,
857
- rb_id2sym(rb_intern("parameters")),
858
- rb_external_str_new(ctx.parameters->data(), static_cast<long>(ctx.parameters->size())));
794
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("parameters")), cb_str_new(ctx.parameters.value()));
859
795
  }
860
796
  rb_hash_aset(error_context, rb_id2sym(rb_intern("http_status")), INT2FIX(ctx.http_status));
861
- rb_hash_aset(
862
- error_context, rb_id2sym(rb_intern("http_body")), rb_external_str_new(ctx.http_body.data(), static_cast<long>(ctx.http_body.size())));
797
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("http_body")), cb_str_new(ctx.http_body));
863
798
  if (ctx.retry_attempts > 0) {
864
799
  rb_hash_aset(error_context, rb_id2sym(rb_intern("retry_attempts")), INT2FIX(ctx.retry_attempts));
865
800
  if (!ctx.retry_reasons.empty()) {
@@ -872,19 +807,35 @@ cb__map_error_code(const couchbase::error_context::search& ctx, const std::strin
872
807
  }
873
808
  }
874
809
  if (ctx.last_dispatched_to) {
875
- rb_hash_aset(error_context,
876
- rb_id2sym(rb_intern("last_dispatched_to")),
877
- rb_external_str_new(ctx.last_dispatched_to->data(), static_cast<long>(ctx.last_dispatched_to->size())));
810
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_to")), cb_str_new(ctx.last_dispatched_to.value()));
878
811
  }
879
812
  if (ctx.last_dispatched_from) {
880
- rb_hash_aset(error_context,
881
- rb_id2sym(rb_intern("last_dispatched_from")),
882
- rb_external_str_new(ctx.last_dispatched_from->data(), static_cast<long>(ctx.last_dispatched_from->size())));
813
+ rb_hash_aset(error_context, rb_id2sym(rb_intern("last_dispatched_from")), cb_str_new(ctx.last_dispatched_from.value()));
883
814
  }
884
815
  rb_iv_set(exc, "@context", error_context);
885
816
  return exc;
886
817
  }
887
818
 
819
+ template<typename Future>
820
+ static auto
821
+ cb_wait_for_future(Future&& f) -> decltype(f.get())
822
+ {
823
+ struct arg_pack {
824
+ Future&& f;
825
+ decltype(f.get()) res{};
826
+ } arg{ f };
827
+ rb_thread_call_without_gvl(
828
+ [](void* param) -> void* {
829
+ auto* pack = static_cast<arg_pack*>(param);
830
+ pack->res = std::move(pack->f.get());
831
+ return nullptr;
832
+ },
833
+ &arg,
834
+ nullptr,
835
+ nullptr);
836
+ return std::move(arg.res);
837
+ }
838
+
888
839
  static VALUE
889
840
  cb_Backend_open(VALUE self, VALUE connection_string, VALUE credentials, VALUE options)
890
841
  {
@@ -961,8 +912,8 @@ cb_Backend_open(VALUE self, VALUE connection_string, VALUE credentials, VALUE op
961
912
  auto barrier = std::make_shared<std::promise<std::error_code>>();
962
913
  auto f = barrier->get_future();
963
914
  backend->cluster->open(origin, [barrier](std::error_code ec) mutable { barrier->set_value(ec); });
964
- if (auto ec = f.get()) {
965
- exc = cb__map_error_code(ec, fmt::format("unable open cluster at {}", origin.next_address().first));
915
+ if (auto ec = cb_wait_for_future(f)) {
916
+ exc = cb_map_error_code(ec, fmt::format("unable open cluster at {}", origin.next_address().first));
966
917
  }
967
918
  } while (false);
968
919
  if (!NIL_P(exc)) {
@@ -977,7 +928,7 @@ cb_Backend_close(VALUE self)
977
928
  {
978
929
  cb_backend_data* backend = nullptr;
979
930
  TypedData_Get_Struct(self, cb_backend_data, &cb_backend_type, backend);
980
- cb__backend_close(backend);
931
+ cb_backend_close(backend);
981
932
  return Qnil;
982
933
  }
983
934
 
@@ -1004,11 +955,11 @@ cb_Backend_diagnostics(VALUE self, VALUE report_id)
1004
955
  auto barrier = std::make_shared<std::promise<couchbase::diag::diagnostics_result>>();
1005
956
  auto f = barrier->get_future();
1006
957
  backend->cluster->diagnostics(id, [barrier](couchbase::diag::diagnostics_result&& resp) mutable { barrier->set_value(resp); });
1007
- auto resp = f.get();
958
+ auto resp = cb_wait_for_future(f);
1008
959
 
1009
960
  VALUE res = rb_hash_new();
1010
- rb_hash_aset(res, rb_id2sym(rb_intern("id")), rb_external_str_new(resp.id.data(), static_cast<long>(resp.id.size())));
1011
- rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), rb_external_str_new(resp.sdk.data(), static_cast<long>(resp.sdk.size())));
961
+ rb_hash_aset(res, rb_id2sym(rb_intern("id")), cb_str_new(resp.id));
962
+ rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), cb_str_new(resp.sdk));
1012
963
  rb_hash_aset(res, rb_id2sym(rb_intern("version")), INT2FIX(resp.version));
1013
964
  VALUE services = rb_hash_new();
1014
965
  rb_hash_aset(res, rb_id2sym(rb_intern("services")), services);
@@ -1041,11 +992,9 @@ cb_Backend_diagnostics(VALUE self, VALUE report_id)
1041
992
  if (svc.last_activity) {
1042
993
  rb_hash_aset(service, rb_id2sym(rb_intern("last_activity_us")), LL2NUM(svc.last_activity->count()));
1043
994
  }
1044
- rb_hash_aset(service, rb_id2sym(rb_intern("id")), rb_external_str_new(svc.id.data(), static_cast<long>(svc.id.size())));
1045
- rb_hash_aset(
1046
- service, rb_id2sym(rb_intern("remote")), rb_external_str_new(svc.remote.data(), static_cast<long>(svc.remote.size())));
1047
- rb_hash_aset(
1048
- service, rb_id2sym(rb_intern("local")), rb_external_str_new(svc.local.data(), static_cast<long>(svc.local.size())));
995
+ rb_hash_aset(service, rb_id2sym(rb_intern("id")), cb_str_new(svc.id));
996
+ rb_hash_aset(service, rb_id2sym(rb_intern("remote")), cb_str_new(svc.remote));
997
+ rb_hash_aset(service, rb_id2sym(rb_intern("local")), cb_str_new(svc.local));
1049
998
  VALUE state = Qnil;
1050
999
  switch (svc.state) {
1051
1000
  case couchbase::diag::endpoint_state::disconnected:
@@ -1062,9 +1011,7 @@ cb_Backend_diagnostics(VALUE self, VALUE report_id)
1062
1011
  break;
1063
1012
  }
1064
1013
  if (svc.details) {
1065
- rb_hash_aset(service,
1066
- rb_id2sym(rb_intern("details")),
1067
- rb_external_str_new(svc.details->data(), static_cast<long>(svc.details->size())));
1014
+ rb_hash_aset(service, rb_id2sym(rb_intern("details")), cb_str_new(svc.details.value()));
1068
1015
  }
1069
1016
  rb_hash_aset(service, rb_id2sym(rb_intern("state")), state);
1070
1017
  rb_ary_push(endpoints, service);
@@ -1098,11 +1045,11 @@ cb_Backend_open_bucket(VALUE self, VALUE bucket, VALUE wait_until_ready)
1098
1045
  auto barrier = std::make_shared<std::promise<std::error_code>>();
1099
1046
  auto f = barrier->get_future();
1100
1047
  backend->cluster->open_bucket(name, [barrier](std::error_code ec) mutable { barrier->set_value(ec); });
1101
- if (auto ec = f.get()) {
1102
- exc = cb__map_error_code(ec, fmt::format("unable open bucket \"{}\"", name));
1048
+ if (auto ec = cb_wait_for_future(f)) {
1049
+ exc = cb_map_error_code(ec, fmt::format("unable open bucket \"{}\"", name));
1103
1050
  }
1104
1051
  } else {
1105
- backend->cluster->open_bucket(name, [](std::error_code) {});
1052
+ backend->cluster->open_bucket(name, [](std::error_code /* ec */) {});
1106
1053
  }
1107
1054
  }
1108
1055
  if (!NIL_P(exc)) {
@@ -1114,12 +1061,12 @@ cb_Backend_open_bucket(VALUE self, VALUE bucket, VALUE wait_until_ready)
1114
1061
 
1115
1062
  template<typename Request>
1116
1063
  [[nodiscard]] VALUE
1117
- cb__extract_timeout(Request& req, VALUE options)
1064
+ cb_extract_timeout(Request& req, VALUE options)
1118
1065
  {
1119
1066
  if (!NIL_P(options)) {
1120
1067
  switch (TYPE(options)) {
1121
1068
  case T_HASH:
1122
- return cb__extract_timeout(req, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1069
+ return cb_extract_timeout(req, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1123
1070
  case T_FIXNUM:
1124
1071
  case T_BIGNUM:
1125
1072
  req.timeout = std::chrono::milliseconds(NUM2ULL(options));
@@ -1132,12 +1079,12 @@ cb__extract_timeout(Request& req, VALUE options)
1132
1079
  }
1133
1080
 
1134
1081
  [[nodiscard]] VALUE
1135
- cb__extract_timeout(std::chrono::milliseconds& timeout, VALUE options)
1082
+ cb_extract_timeout(std::chrono::milliseconds& timeout, VALUE options)
1136
1083
  {
1137
1084
  if (!NIL_P(options)) {
1138
1085
  switch (TYPE(options)) {
1139
1086
  case T_HASH:
1140
- return cb__extract_timeout(timeout, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1087
+ return cb_extract_timeout(timeout, rb_hash_aref(options, rb_id2sym(rb_intern("timeout"))));
1141
1088
  case T_FIXNUM:
1142
1089
  case T_BIGNUM:
1143
1090
  timeout = std::chrono::milliseconds(NUM2ULL(options));
@@ -1150,7 +1097,7 @@ cb__extract_timeout(std::chrono::milliseconds& timeout, VALUE options)
1150
1097
  }
1151
1098
 
1152
1099
  [[nodiscard]] VALUE
1153
- cb__extract_option_bool(bool& field, VALUE options, const char* name)
1100
+ cb_extract_option_bool(bool& field, VALUE options, const char* name)
1154
1101
  {
1155
1102
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1156
1103
  VALUE val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1172,7 +1119,7 @@ cb__extract_option_bool(bool& field, VALUE options, const char* name)
1172
1119
  }
1173
1120
 
1174
1121
  [[nodiscard]] VALUE
1175
- cb__extract_option_array(VALUE& val, VALUE options, const char* name)
1122
+ cb_extract_option_array(VALUE& val, VALUE options, const char* name)
1176
1123
  {
1177
1124
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1178
1125
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1188,7 +1135,7 @@ cb__extract_option_array(VALUE& val, VALUE options, const char* name)
1188
1135
  }
1189
1136
 
1190
1137
  [[nodiscard]] VALUE
1191
- cb__extract_array_of_ids(std::vector<couchbase::document_id>& ids, VALUE arg)
1138
+ cb_extract_array_of_ids(std::vector<couchbase::document_id>& ids, VALUE arg)
1192
1139
  {
1193
1140
  if (TYPE(arg) != T_ARRAY) {
1194
1141
  return rb_exc_new_str(rb_eArgError, rb_sprintf("Type of IDs argument must be an Array, but given %+" PRIsVALUE, arg));
@@ -1227,7 +1174,7 @@ cb__extract_array_of_ids(std::vector<couchbase::document_id>& ids, VALUE arg)
1227
1174
  }
1228
1175
 
1229
1176
  [[nodiscard]] VALUE
1230
- cb__extract_array_of_id_content(std::vector<std::tuple<couchbase::document_id, std::string, std::uint32_t>>& id_content, VALUE arg)
1177
+ cb_extract_array_of_id_content(std::vector<std::tuple<couchbase::document_id, std::string, std::uint32_t>>& id_content, VALUE arg)
1231
1178
  {
1232
1179
  if (TYPE(arg) != T_ARRAY) {
1233
1180
  return rb_exc_new_str(rb_eArgError, rb_sprintf("Type of ID/content tuples must be an Array, but given %+" PRIsVALUE, arg));
@@ -1279,7 +1226,7 @@ cb__extract_array_of_id_content(std::vector<std::tuple<couchbase::document_id, s
1279
1226
  }
1280
1227
 
1281
1228
  [[nodiscard]] VALUE
1282
- cb__extract_array_of_id_cas(std::vector<std::pair<couchbase::document_id, std::uint64_t>>& id_cas, VALUE arg)
1229
+ cb_extract_array_of_id_cas(std::vector<std::pair<couchbase::document_id, std::uint64_t>>& id_cas, VALUE arg)
1283
1230
  {
1284
1231
  if (TYPE(arg) != T_ARRAY) {
1285
1232
  return rb_exc_new_str(rb_eArgError, rb_sprintf("Type of ID/CAS tuples must be an Array, but given %+" PRIsVALUE, arg));
@@ -1334,7 +1281,7 @@ cb__extract_array_of_id_cas(std::vector<std::pair<couchbase::document_id, std::u
1334
1281
  }
1335
1282
 
1336
1283
  [[nodiscard]] VALUE
1337
- cb__extract_option_symbol(VALUE& val, VALUE options, const char* name)
1284
+ cb_extract_option_symbol(VALUE& val, VALUE options, const char* name)
1338
1285
  {
1339
1286
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1340
1287
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1350,7 +1297,7 @@ cb__extract_option_symbol(VALUE& val, VALUE options, const char* name)
1350
1297
  }
1351
1298
 
1352
1299
  [[nodiscard]] VALUE
1353
- cb__extract_option_string(VALUE& val, VALUE options, const char* name)
1300
+ cb_extract_option_string(VALUE& val, VALUE options, const char* name)
1354
1301
  {
1355
1302
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1356
1303
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1366,7 +1313,7 @@ cb__extract_option_string(VALUE& val, VALUE options, const char* name)
1366
1313
  }
1367
1314
 
1368
1315
  [[nodiscard]] VALUE
1369
- cb__extract_option_fixnum(VALUE& val, VALUE options, const char* name)
1316
+ cb_extract_option_fixnum(VALUE& val, VALUE options, const char* name)
1370
1317
  {
1371
1318
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1372
1319
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1382,7 +1329,7 @@ cb__extract_option_fixnum(VALUE& val, VALUE options, const char* name)
1382
1329
  }
1383
1330
 
1384
1331
  [[nodiscard]] VALUE
1385
- cb__extract_option_bignum(VALUE& val, VALUE options, const char* name)
1332
+ cb_extract_option_bignum(VALUE& val, VALUE options, const char* name)
1386
1333
  {
1387
1334
  if (!NIL_P(options) && TYPE(options) == T_HASH) {
1388
1335
  val = rb_hash_aref(options, rb_id2sym(rb_intern(name)));
@@ -1402,10 +1349,10 @@ cb__extract_option_bignum(VALUE& val, VALUE options, const char* name)
1402
1349
  }
1403
1350
 
1404
1351
  [[nodiscard]] VALUE
1405
- cb__extract_durability(couchbase::protocol::durability_level& output_level, std::optional<std::uint16_t>& output_timeout, VALUE options)
1352
+ cb_extract_durability(couchbase::protocol::durability_level& output_level, std::optional<std::uint16_t>& output_timeout, VALUE options)
1406
1353
  {
1407
1354
  VALUE durability_level = Qnil;
1408
- VALUE exc = cb__extract_option_symbol(durability_level, options, "durability_level");
1355
+ VALUE exc = cb_extract_option_symbol(durability_level, options, "durability_level");
1409
1356
  if (!NIL_P(exc)) {
1410
1357
  return exc;
1411
1358
  }
@@ -1423,7 +1370,7 @@ cb__extract_durability(couchbase::protocol::durability_level& output_level, std:
1423
1370
  return rb_exc_new_str(eInvalidArgument, rb_sprintf("unknown durability level: %+" PRIsVALUE, durability_level));
1424
1371
  }
1425
1372
  VALUE durability_timeout = Qnil;
1426
- exc = cb__extract_option_fixnum(durability_timeout, options, "durability_timeout");
1373
+ exc = cb_extract_option_fixnum(durability_timeout, options, "durability_timeout");
1427
1374
  if (!NIL_P(exc)) {
1428
1375
  return exc;
1429
1376
  }
@@ -1436,9 +1383,9 @@ cb__extract_durability(couchbase::protocol::durability_level& output_level, std:
1436
1383
 
1437
1384
  template<typename Request>
1438
1385
  [[nodiscard]] VALUE
1439
- cb__extract_durability(Request& req, VALUE options)
1386
+ cb_extract_durability(Request& req, VALUE options)
1440
1387
  {
1441
- return cb__extract_durability(req.durability_level, req.durability_timeout, options);
1388
+ return cb_extract_durability(req.durability_level, req.durability_timeout, options);
1442
1389
  }
1443
1390
 
1444
1391
  static VALUE
@@ -1462,7 +1409,7 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1462
1409
  VALUE exc = Qnil;
1463
1410
  do {
1464
1411
  VALUE id = Qnil;
1465
- exc = cb__extract_option_string(id, options, "report_id");
1412
+ exc = cb_extract_option_string(id, options, "report_id");
1466
1413
  if (!NIL_P(exc)) {
1467
1414
  break;
1468
1415
  }
@@ -1475,7 +1422,7 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1475
1422
  bucket_name.emplace(std::string(RSTRING_PTR(bucket), static_cast<size_t>(RSTRING_LEN(bucket))));
1476
1423
  }
1477
1424
  VALUE services = Qnil;
1478
- exc = cb__extract_option_array(services, options, "service_types");
1425
+ exc = cb_extract_option_array(services, options, "service_types");
1479
1426
  if (!NIL_P(exc)) {
1480
1427
  break;
1481
1428
  }
@@ -1501,11 +1448,11 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1501
1448
  auto f = barrier->get_future();
1502
1449
  backend->cluster->ping(
1503
1450
  report_id, bucket_name, selected_services, [barrier](couchbase::diag::ping_result&& resp) mutable { barrier->set_value(resp); });
1504
- auto resp = f.get();
1451
+ auto resp = cb_wait_for_future(f);
1505
1452
 
1506
1453
  VALUE res = rb_hash_new();
1507
- rb_hash_aset(res, rb_id2sym(rb_intern("id")), rb_external_str_new(resp.id.data(), static_cast<long>(resp.id.size())));
1508
- rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), rb_external_str_new(resp.sdk.data(), static_cast<long>(resp.sdk.size())));
1454
+ rb_hash_aset(res, rb_id2sym(rb_intern("id")), cb_str_new(resp.id));
1455
+ rb_hash_aset(res, rb_id2sym(rb_intern("sdk")), cb_str_new(resp.sdk));
1509
1456
  rb_hash_aset(res, rb_id2sym(rb_intern("version")), INT2FIX(resp.version));
1510
1457
  services = rb_hash_new();
1511
1458
  rb_hash_aset(res, rb_id2sym(rb_intern("services")), services);
@@ -1536,11 +1483,9 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1536
1483
  for (const auto& svc : svcs.second) {
1537
1484
  VALUE service = rb_hash_new();
1538
1485
  rb_hash_aset(service, rb_id2sym(rb_intern("latency")), LL2NUM(svc.latency.count()));
1539
- rb_hash_aset(service, rb_id2sym(rb_intern("id")), rb_external_str_new(svc.id.data(), static_cast<long>(svc.id.size())));
1540
- rb_hash_aset(
1541
- service, rb_id2sym(rb_intern("remote")), rb_external_str_new(svc.remote.data(), static_cast<long>(svc.remote.size())));
1542
- rb_hash_aset(
1543
- service, rb_id2sym(rb_intern("local")), rb_external_str_new(svc.local.data(), static_cast<long>(svc.local.size())));
1486
+ rb_hash_aset(service, rb_id2sym(rb_intern("id")), cb_str_new(svc.id));
1487
+ rb_hash_aset(service, rb_id2sym(rb_intern("remote")), cb_str_new(svc.remote));
1488
+ rb_hash_aset(service, rb_id2sym(rb_intern("local")), cb_str_new(svc.local));
1544
1489
  VALUE state = Qnil;
1545
1490
  switch (svc.state) {
1546
1491
  case couchbase::diag::ping_state::ok:
@@ -1552,9 +1497,7 @@ cb_Backend_ping(VALUE self, VALUE bucket, VALUE options)
1552
1497
  case couchbase::diag::ping_state::error:
1553
1498
  state = rb_id2sym(rb_intern("error"));
1554
1499
  if (svc.error) {
1555
- rb_hash_aset(service,
1556
- rb_id2sym(rb_intern("error")),
1557
- rb_external_str_new(svc.error->data(), static_cast<long>(svc.error->size())));
1500
+ rb_hash_aset(service, rb_id2sym(rb_intern("error")), cb_str_new(svc.error.value()));
1558
1501
  }
1559
1502
  break;
1560
1503
  }
@@ -1591,21 +1534,21 @@ cb_Backend_document_get(VALUE self, VALUE bucket, VALUE collection, VALUE id, VA
1591
1534
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1592
1535
 
1593
1536
  couchbase::operations::get_request req{ doc_id };
1594
- exc = cb__extract_timeout(req, options);
1537
+ exc = cb_extract_timeout(req, options);
1595
1538
  if (!NIL_P(exc)) {
1596
1539
  break;
1597
1540
  }
1598
1541
  auto barrier = std::make_shared<std::promise<couchbase::operations::get_response>>();
1599
1542
  auto f = barrier->get_future();
1600
1543
  backend->cluster->execute(req, [barrier](couchbase::operations::get_response&& resp) mutable { barrier->set_value(resp); });
1601
- auto resp = f.get();
1544
+ auto resp = cb_wait_for_future(f);
1602
1545
  if (resp.ctx.ec) {
1603
- exc = cb__map_error_code(resp.ctx, "unable to fetch document");
1546
+ exc = cb_map_error_code(resp.ctx, "unable to fetch document");
1604
1547
  break;
1605
1548
  }
1606
1549
 
1607
1550
  VALUE res = rb_hash_new();
1608
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1551
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1609
1552
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1610
1553
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1611
1554
  return res;
@@ -1628,13 +1571,13 @@ cb_Backend_document_get_multi(VALUE self, VALUE keys, VALUE options)
1628
1571
  VALUE exc = Qnil;
1629
1572
  do {
1630
1573
  std::chrono::milliseconds timeout{ 0 };
1631
- exc = cb__extract_timeout(timeout, options);
1574
+ exc = cb_extract_timeout(timeout, options);
1632
1575
  if (!NIL_P(exc)) {
1633
1576
  break;
1634
1577
  }
1635
1578
 
1636
1579
  std::vector<couchbase::document_id> ids{};
1637
- exc = cb__extract_array_of_ids(ids, keys);
1580
+ exc = cb_extract_array_of_ids(ids, keys);
1638
1581
  if (!NIL_P(exc)) {
1639
1582
  break;
1640
1583
  }
@@ -1658,10 +1601,9 @@ cb_Backend_document_get_multi(VALUE self, VALUE keys, VALUE options)
1658
1601
  auto resp = barrier->get_future().get();
1659
1602
  VALUE entry = rb_hash_new();
1660
1603
  if (resp.ctx.ec) {
1661
- rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb__map_error_code(resp.ctx, "unable to (multi)fetch document"));
1604
+ rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb_map_error_code(resp.ctx, "unable to (multi)fetch document"));
1662
1605
  }
1663
- rb_hash_aset(
1664
- entry, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1606
+ rb_hash_aset(entry, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1665
1607
  rb_hash_aset(entry, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1666
1608
  rb_hash_aset(entry, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1667
1609
  rb_ary_push(res, entry);
@@ -1698,20 +1640,20 @@ cb_Backend_document_get_projected(VALUE self, VALUE bucket, VALUE collection, VA
1698
1640
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1699
1641
 
1700
1642
  couchbase::operations::get_projected_request req{ doc_id };
1701
- exc = cb__extract_timeout(req, options);
1643
+ exc = cb_extract_timeout(req, options);
1702
1644
  if (!NIL_P(exc)) {
1703
1645
  break;
1704
1646
  }
1705
- exc = cb__extract_option_bool(req.with_expiry, options, "with_expiry");
1647
+ exc = cb_extract_option_bool(req.with_expiry, options, "with_expiry");
1706
1648
  if (!NIL_P(exc)) {
1707
1649
  break;
1708
1650
  }
1709
- exc = cb__extract_option_bool(req.preserve_array_indexes, options, "preserve_array_indexes");
1651
+ exc = cb_extract_option_bool(req.preserve_array_indexes, options, "preserve_array_indexes");
1710
1652
  if (!NIL_P(exc)) {
1711
1653
  break;
1712
1654
  }
1713
1655
  VALUE projections = Qnil;
1714
- exc = cb__extract_option_array(projections, options, "projections");
1656
+ exc = cb_extract_option_array(projections, options, "projections");
1715
1657
  if (!NIL_P(exc)) {
1716
1658
  break;
1717
1659
  }
@@ -1733,14 +1675,14 @@ cb_Backend_document_get_projected(VALUE self, VALUE bucket, VALUE collection, VA
1733
1675
  auto f = barrier->get_future();
1734
1676
  backend->cluster->execute(req,
1735
1677
  [barrier](couchbase::operations::get_projected_response&& resp) mutable { barrier->set_value(resp); });
1736
- auto resp = f.get();
1678
+ auto resp = cb_wait_for_future(f);
1737
1679
  if (resp.ctx.ec) {
1738
- exc = cb__map_error_code(resp.ctx, "unable fetch with projections");
1680
+ exc = cb_map_error_code(resp.ctx, "unable fetch with projections");
1739
1681
  break;
1740
1682
  }
1741
1683
 
1742
1684
  VALUE res = rb_hash_new();
1743
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1685
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1744
1686
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1745
1687
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1746
1688
  if (resp.expiry) {
@@ -1779,7 +1721,7 @@ cb_Backend_document_get_and_lock(VALUE self, VALUE bucket, VALUE collection, VAL
1779
1721
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1780
1722
 
1781
1723
  couchbase::operations::get_and_lock_request req{ doc_id };
1782
- exc = cb__extract_timeout(req, options);
1724
+ exc = cb_extract_timeout(req, options);
1783
1725
  if (!NIL_P(exc)) {
1784
1726
  break;
1785
1727
  }
@@ -1789,14 +1731,14 @@ cb_Backend_document_get_and_lock(VALUE self, VALUE bucket, VALUE collection, VAL
1789
1731
  auto f = barrier->get_future();
1790
1732
  backend->cluster->execute(req,
1791
1733
  [barrier](couchbase::operations::get_and_lock_response&& resp) mutable { barrier->set_value(resp); });
1792
- auto resp = f.get();
1734
+ auto resp = cb_wait_for_future(f);
1793
1735
  if (resp.ctx.ec) {
1794
- exc = cb__map_error_code(resp.ctx, "unable lock and fetch");
1736
+ exc = cb_map_error_code(resp.ctx, "unable lock and fetch");
1795
1737
  break;
1796
1738
  }
1797
1739
 
1798
1740
  VALUE res = rb_hash_new();
1799
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1741
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1800
1742
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1801
1743
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1802
1744
  return res;
@@ -1832,7 +1774,7 @@ cb_Backend_document_get_and_touch(VALUE self, VALUE bucket, VALUE collection, VA
1832
1774
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1833
1775
 
1834
1776
  couchbase::operations::get_and_touch_request req{ doc_id };
1835
- exc = cb__extract_timeout(req, options);
1777
+ exc = cb_extract_timeout(req, options);
1836
1778
  if (!NIL_P(exc)) {
1837
1779
  break;
1838
1780
  }
@@ -1842,14 +1784,14 @@ cb_Backend_document_get_and_touch(VALUE self, VALUE bucket, VALUE collection, VA
1842
1784
  auto f = barrier->get_future();
1843
1785
  backend->cluster->execute(req,
1844
1786
  [barrier](couchbase::operations::get_and_touch_response&& resp) mutable { barrier->set_value(resp); });
1845
- auto resp = f.get();
1787
+ auto resp = cb_wait_for_future(f);
1846
1788
  if (resp.ctx.ec) {
1847
- exc = cb__map_error_code(resp.ctx, "unable fetch and touch");
1789
+ exc = cb_map_error_code(resp.ctx, "unable fetch and touch");
1848
1790
  break;
1849
1791
  }
1850
1792
 
1851
1793
  VALUE res = rb_hash_new();
1852
- rb_hash_aset(res, rb_id2sym(rb_intern("content")), rb_external_str_new(resp.value.data(), static_cast<long>(resp.value.size())));
1794
+ rb_hash_aset(res, rb_id2sym(rb_intern("content")), cb_str_new(resp.value));
1853
1795
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
1854
1796
  rb_hash_aset(res, rb_id2sym(rb_intern("flags")), UINT2NUM(resp.flags));
1855
1797
  return res;
@@ -1860,7 +1802,7 @@ cb_Backend_document_get_and_touch(VALUE self, VALUE bucket, VALUE collection, VA
1860
1802
 
1861
1803
  template<typename Response>
1862
1804
  static VALUE
1863
- cb__extract_mutation_result(Response resp)
1805
+ cb_extract_mutation_result(Response resp)
1864
1806
  {
1865
1807
  VALUE res = rb_hash_new();
1866
1808
  rb_hash_aset(res, rb_id2sym(rb_intern("cas")), ULL2NUM(resp.cas));
@@ -1868,9 +1810,7 @@ cb__extract_mutation_result(Response resp)
1868
1810
  rb_hash_aset(token, rb_id2sym(rb_intern("partition_uuid")), ULL2NUM(resp.token.partition_uuid));
1869
1811
  rb_hash_aset(token, rb_id2sym(rb_intern("sequence_number")), ULL2NUM(resp.token.sequence_number));
1870
1812
  rb_hash_aset(token, rb_id2sym(rb_intern("partition_id")), UINT2NUM(resp.token.partition_id));
1871
- rb_hash_aset(token,
1872
- rb_id2sym(rb_intern("bucket_name")),
1873
- rb_external_str_new(resp.token.bucket_name.c_str(), static_cast<long>(resp.token.bucket_name.size())));
1813
+ rb_hash_aset(token, rb_id2sym(rb_intern("bucket_name")), cb_str_new(resp.token.bucket_name));
1874
1814
  rb_hash_aset(res, rb_id2sym(rb_intern("mutation_token")), token);
1875
1815
  return res;
1876
1816
  }
@@ -1902,7 +1842,7 @@ cb_Backend_document_touch(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1902
1842
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1903
1843
 
1904
1844
  couchbase::operations::touch_request req{ doc_id };
1905
- exc = cb__extract_timeout(req, options);
1845
+ exc = cb_extract_timeout(req, options);
1906
1846
  if (!NIL_P(exc)) {
1907
1847
  break;
1908
1848
  }
@@ -1911,9 +1851,9 @@ cb_Backend_document_touch(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1911
1851
  auto barrier = std::make_shared<std::promise<couchbase::operations::touch_response>>();
1912
1852
  auto f = barrier->get_future();
1913
1853
  backend->cluster->execute(req, [barrier](couchbase::operations::touch_response&& resp) mutable { barrier->set_value(resp); });
1914
- auto resp = f.get();
1854
+ auto resp = cb_wait_for_future(f);
1915
1855
  if (resp.ctx.ec) {
1916
- exc = cb__map_error_code(resp.ctx, "unable to touch");
1856
+ exc = cb_map_error_code(resp.ctx, "unable to touch");
1917
1857
  break;
1918
1858
  }
1919
1859
 
@@ -1951,7 +1891,7 @@ cb_Backend_document_exists(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1951
1891
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
1952
1892
 
1953
1893
  couchbase::operations::exists_request req{ doc_id };
1954
- exc = cb__extract_timeout(req, options);
1894
+ exc = cb_extract_timeout(req, options);
1955
1895
  if (!NIL_P(exc)) {
1956
1896
  break;
1957
1897
  }
@@ -1959,9 +1899,9 @@ cb_Backend_document_exists(VALUE self, VALUE bucket, VALUE collection, VALUE id,
1959
1899
  auto barrier = std::make_shared<std::promise<couchbase::operations::exists_response>>();
1960
1900
  auto f = barrier->get_future();
1961
1901
  backend->cluster->execute(req, [barrier](couchbase::operations::exists_response&& resp) mutable { barrier->set_value(resp); });
1962
- auto resp = f.get();
1902
+ auto resp = cb_wait_for_future(f);
1963
1903
  if (resp.ctx.ec) {
1964
- exc = cb__map_error_code(resp.ctx, "unable to exists");
1904
+ exc = cb_map_error_code(resp.ctx, "unable to exists");
1965
1905
  break;
1966
1906
  }
1967
1907
 
@@ -2017,7 +1957,7 @@ cb_Backend_document_unlock(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2017
1957
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2018
1958
 
2019
1959
  couchbase::operations::unlock_request req{ doc_id };
2020
- exc = cb__extract_timeout(req, options);
1960
+ exc = cb_extract_timeout(req, options);
2021
1961
  if (!NIL_P(exc)) {
2022
1962
  break;
2023
1963
  }
@@ -2036,9 +1976,9 @@ cb_Backend_document_unlock(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2036
1976
  auto barrier = std::make_shared<std::promise<couchbase::operations::unlock_response>>();
2037
1977
  auto f = barrier->get_future();
2038
1978
  backend->cluster->execute(req, [barrier](couchbase::operations::unlock_response&& resp) mutable { barrier->set_value(resp); });
2039
- auto resp = f.get();
1979
+ auto resp = cb_wait_for_future(f);
2040
1980
  if (resp.ctx.ec) {
2041
- exc = cb__map_error_code(resp.ctx, "unable to unlock");
1981
+ exc = cb_map_error_code(resp.ctx, "unable to unlock");
2042
1982
  break;
2043
1983
  }
2044
1984
 
@@ -2079,18 +2019,18 @@ cb_Backend_document_upsert(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2079
2019
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2080
2020
 
2081
2021
  couchbase::operations::upsert_request req{ doc_id, value };
2082
- exc = cb__extract_timeout(req, options);
2022
+ exc = cb_extract_timeout(req, options);
2083
2023
  if (!NIL_P(exc)) {
2084
2024
  break;
2085
2025
  }
2086
2026
  req.flags = FIX2UINT(flags);
2087
2027
 
2088
- exc = cb__extract_durability(req, options);
2028
+ exc = cb_extract_durability(req, options);
2089
2029
  if (!NIL_P(exc)) {
2090
2030
  break;
2091
2031
  }
2092
2032
  VALUE expiry = Qnil;
2093
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2033
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2094
2034
  if (!NIL_P(exc)) {
2095
2035
  break;
2096
2036
  }
@@ -2101,13 +2041,13 @@ cb_Backend_document_upsert(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2101
2041
  auto barrier = std::make_shared<std::promise<couchbase::operations::upsert_response>>();
2102
2042
  auto f = barrier->get_future();
2103
2043
  backend->cluster->execute(req, [barrier](couchbase::operations::upsert_response&& resp) mutable { barrier->set_value(resp); });
2104
- auto resp = f.get();
2044
+ auto resp = cb_wait_for_future(f);
2105
2045
  if (resp.ctx.ec) {
2106
- exc = cb__map_error_code(resp.ctx, "unable to upsert");
2046
+ exc = cb_map_error_code(resp.ctx, "unable to upsert");
2107
2047
  break;
2108
2048
  }
2109
2049
 
2110
- return cb__extract_mutation_result(resp);
2050
+ return cb_extract_mutation_result(resp);
2111
2051
  } while (false);
2112
2052
  rb_exc_raise(exc);
2113
2053
  return Qnil;
@@ -2127,25 +2067,25 @@ cb_Backend_document_upsert_multi(VALUE self, VALUE id_content, VALUE options)
2127
2067
  VALUE exc = Qnil;
2128
2068
  do {
2129
2069
  std::chrono::milliseconds timeout{ 0 };
2130
- exc = cb__extract_timeout(timeout, options);
2070
+ exc = cb_extract_timeout(timeout, options);
2131
2071
  if (!NIL_P(exc)) {
2132
2072
  break;
2133
2073
  }
2134
2074
 
2135
2075
  couchbase::protocol::durability_level durability_level{ couchbase::protocol::durability_level::none };
2136
2076
  std::optional<std::uint16_t> durability_timeout{ std::nullopt };
2137
- exc = cb__extract_durability(durability_level, durability_timeout, options);
2077
+ exc = cb_extract_durability(durability_level, durability_timeout, options);
2138
2078
  if (!NIL_P(exc)) {
2139
2079
  break;
2140
2080
  }
2141
2081
  VALUE expiry = Qnil;
2142
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2082
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2143
2083
  if (!NIL_P(exc)) {
2144
2084
  break;
2145
2085
  }
2146
2086
 
2147
2087
  std::vector<std::tuple<couchbase::document_id, std::string, std::uint32_t>> tuples{};
2148
- exc = cb__extract_array_of_id_content(tuples, id_content);
2088
+ exc = cb_extract_array_of_id_content(tuples, id_content);
2149
2089
  if (!NIL_P(exc)) {
2150
2090
  break;
2151
2091
  }
@@ -2173,9 +2113,9 @@ cb_Backend_document_upsert_multi(VALUE self, VALUE id_content, VALUE options)
2173
2113
  VALUE res = rb_ary_new_capa(static_cast<long>(num_of_tuples));
2174
2114
  for (auto& barrier : barriers) {
2175
2115
  auto resp = barrier->get_future().get();
2176
- VALUE entry = cb__extract_mutation_result(resp);
2116
+ VALUE entry = cb_extract_mutation_result(resp);
2177
2117
  if (resp.ctx.ec) {
2178
- rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb__map_error_code(resp.ctx, "unable (multi)upsert"));
2118
+ rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb_map_error_code(resp.ctx, "unable (multi)upsert"));
2179
2119
  }
2180
2120
  rb_ary_push(res, entry);
2181
2121
  }
@@ -2213,11 +2153,11 @@ cb_Backend_document_append(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2213
2153
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2214
2154
 
2215
2155
  couchbase::operations::append_request req{ doc_id, value };
2216
- exc = cb__extract_timeout(req, options);
2156
+ exc = cb_extract_timeout(req, options);
2217
2157
  if (!NIL_P(exc)) {
2218
2158
  break;
2219
2159
  }
2220
- exc = cb__extract_durability(req, options);
2160
+ exc = cb_extract_durability(req, options);
2221
2161
  if (!NIL_P(exc)) {
2222
2162
  break;
2223
2163
  }
@@ -2225,13 +2165,13 @@ cb_Backend_document_append(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2225
2165
  auto barrier = std::make_shared<std::promise<couchbase::operations::append_response>>();
2226
2166
  auto f = barrier->get_future();
2227
2167
  backend->cluster->execute(req, [barrier](couchbase::operations::append_response&& resp) mutable { barrier->set_value(resp); });
2228
- auto resp = f.get();
2168
+ auto resp = cb_wait_for_future(f);
2229
2169
  if (resp.ctx.ec) {
2230
- exc = cb__map_error_code(resp.ctx, "unable to append");
2170
+ exc = cb_map_error_code(resp.ctx, "unable to append");
2231
2171
  break;
2232
2172
  }
2233
2173
 
2234
- return cb__extract_mutation_result(resp);
2174
+ return cb_extract_mutation_result(resp);
2235
2175
  } while (false);
2236
2176
  rb_exc_raise(exc);
2237
2177
  return Qnil;
@@ -2265,11 +2205,11 @@ cb_Backend_document_prepend(VALUE self, VALUE bucket, VALUE collection, VALUE id
2265
2205
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2266
2206
 
2267
2207
  couchbase::operations::prepend_request req{ doc_id, value };
2268
- exc = cb__extract_timeout(req, options);
2208
+ exc = cb_extract_timeout(req, options);
2269
2209
  if (!NIL_P(exc)) {
2270
2210
  break;
2271
2211
  }
2272
- exc = cb__extract_durability(req, options);
2212
+ exc = cb_extract_durability(req, options);
2273
2213
  if (!NIL_P(exc)) {
2274
2214
  break;
2275
2215
  }
@@ -2277,13 +2217,13 @@ cb_Backend_document_prepend(VALUE self, VALUE bucket, VALUE collection, VALUE id
2277
2217
  auto barrier = std::make_shared<std::promise<couchbase::operations::prepend_response>>();
2278
2218
  auto f = barrier->get_future();
2279
2219
  backend->cluster->execute(req, [barrier](couchbase::operations::prepend_response&& resp) mutable { barrier->set_value(resp); });
2280
- auto resp = f.get();
2220
+ auto resp = cb_wait_for_future(f);
2281
2221
  if (resp.ctx.ec) {
2282
- exc = cb__map_error_code(resp.ctx, "unable to prepend");
2222
+ exc = cb_map_error_code(resp.ctx, "unable to prepend");
2283
2223
  break;
2284
2224
  }
2285
2225
 
2286
- return cb__extract_mutation_result(resp);
2226
+ return cb_extract_mutation_result(resp);
2287
2227
  } while (false);
2288
2228
  rb_exc_raise(exc);
2289
2229
  return Qnil;
@@ -2318,18 +2258,18 @@ cb_Backend_document_replace(VALUE self, VALUE bucket, VALUE collection, VALUE id
2318
2258
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2319
2259
 
2320
2260
  couchbase::operations::replace_request req{ doc_id, value };
2321
- exc = cb__extract_timeout(req, options);
2261
+ exc = cb_extract_timeout(req, options);
2322
2262
  if (!NIL_P(exc)) {
2323
2263
  break;
2324
2264
  }
2325
2265
  req.flags = FIX2UINT(flags);
2326
2266
 
2327
- exc = cb__extract_durability(req, options);
2267
+ exc = cb_extract_durability(req, options);
2328
2268
  if (!NIL_P(exc)) {
2329
2269
  break;
2330
2270
  }
2331
2271
  VALUE expiry = Qnil;
2332
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2272
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2333
2273
  if (!NIL_P(exc)) {
2334
2274
  break;
2335
2275
  }
@@ -2337,7 +2277,7 @@ cb_Backend_document_replace(VALUE self, VALUE bucket, VALUE collection, VALUE id
2337
2277
  req.expiry = FIX2UINT(expiry);
2338
2278
  }
2339
2279
  VALUE cas = Qnil;
2340
- exc = cb__extract_option_bignum(cas, options, "cas");
2280
+ exc = cb_extract_option_bignum(cas, options, "cas");
2341
2281
  if (!NIL_P(exc)) {
2342
2282
  break;
2343
2283
  }
@@ -2348,13 +2288,13 @@ cb_Backend_document_replace(VALUE self, VALUE bucket, VALUE collection, VALUE id
2348
2288
  auto barrier = std::make_shared<std::promise<couchbase::operations::replace_response>>();
2349
2289
  auto f = barrier->get_future();
2350
2290
  backend->cluster->execute(req, [barrier](couchbase::operations::replace_response&& resp) mutable { barrier->set_value(resp); });
2351
- auto resp = f.get();
2291
+ auto resp = cb_wait_for_future(f);
2352
2292
  if (resp.ctx.ec) {
2353
- exc = cb__map_error_code(resp.ctx, "unable to replace");
2293
+ exc = cb_map_error_code(resp.ctx, "unable to replace");
2354
2294
  break;
2355
2295
  }
2356
2296
 
2357
- return cb__extract_mutation_result(resp);
2297
+ return cb_extract_mutation_result(resp);
2358
2298
  } while (false);
2359
2299
  rb_exc_raise(exc);
2360
2300
  return Qnil;
@@ -2389,18 +2329,18 @@ cb_Backend_document_insert(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2389
2329
  std::string value(RSTRING_PTR(content), static_cast<size_t>(RSTRING_LEN(content)));
2390
2330
 
2391
2331
  couchbase::operations::insert_request req{ doc_id, value };
2392
- exc = cb__extract_timeout(req, options);
2332
+ exc = cb_extract_timeout(req, options);
2393
2333
  if (!NIL_P(exc)) {
2394
2334
  break;
2395
2335
  }
2396
2336
  req.flags = FIX2UINT(flags);
2397
2337
 
2398
- exc = cb__extract_durability(req, options);
2338
+ exc = cb_extract_durability(req, options);
2399
2339
  if (!NIL_P(exc)) {
2400
2340
  break;
2401
2341
  }
2402
2342
  VALUE expiry = Qnil;
2403
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2343
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2404
2344
  if (!NIL_P(exc)) {
2405
2345
  break;
2406
2346
  }
@@ -2411,13 +2351,13 @@ cb_Backend_document_insert(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2411
2351
  auto barrier = std::make_shared<std::promise<couchbase::operations::insert_response>>();
2412
2352
  auto f = barrier->get_future();
2413
2353
  backend->cluster->execute(req, [barrier](couchbase::operations::insert_response&& resp) mutable { barrier->set_value(resp); });
2414
- auto resp = f.get();
2354
+ auto resp = cb_wait_for_future(f);
2415
2355
  if (resp.ctx.ec) {
2416
- exc = cb__map_error_code(resp.ctx, "unable to insert");
2356
+ exc = cb_map_error_code(resp.ctx, "unable to insert");
2417
2357
  break;
2418
2358
  }
2419
2359
 
2420
- return cb__extract_mutation_result(resp);
2360
+ return cb_extract_mutation_result(resp);
2421
2361
  } while (false);
2422
2362
  rb_exc_raise(exc);
2423
2363
  return Qnil;
@@ -2449,16 +2389,16 @@ cb_Backend_document_remove(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2449
2389
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2450
2390
 
2451
2391
  couchbase::operations::remove_request req{ doc_id };
2452
- exc = cb__extract_timeout(req, options);
2392
+ exc = cb_extract_timeout(req, options);
2453
2393
  if (!NIL_P(exc)) {
2454
2394
  break;
2455
2395
  }
2456
- exc = cb__extract_durability(req, options);
2396
+ exc = cb_extract_durability(req, options);
2457
2397
  if (!NIL_P(exc)) {
2458
2398
  break;
2459
2399
  }
2460
2400
  VALUE cas = Qnil;
2461
- exc = cb__extract_option_bignum(cas, options, "cas");
2401
+ exc = cb_extract_option_bignum(cas, options, "cas");
2462
2402
  if (!NIL_P(exc)) {
2463
2403
  break;
2464
2404
  }
@@ -2469,12 +2409,12 @@ cb_Backend_document_remove(VALUE self, VALUE bucket, VALUE collection, VALUE id,
2469
2409
  auto barrier = std::make_shared<std::promise<couchbase::operations::remove_response>>();
2470
2410
  auto f = barrier->get_future();
2471
2411
  backend->cluster->execute(req, [barrier](couchbase::operations::remove_response&& resp) mutable { barrier->set_value(resp); });
2472
- auto resp = f.get();
2412
+ auto resp = cb_wait_for_future(f);
2473
2413
  if (resp.ctx.ec) {
2474
- exc = cb__map_error_code(resp.ctx, "unable to remove");
2414
+ exc = cb_map_error_code(resp.ctx, "unable to remove");
2475
2415
  break;
2476
2416
  }
2477
- return cb__extract_mutation_result(resp);
2417
+ return cb_extract_mutation_result(resp);
2478
2418
  } while (false);
2479
2419
  rb_exc_raise(exc);
2480
2420
  return Qnil;
@@ -2498,20 +2438,20 @@ cb_Backend_document_remove_multi(VALUE self, VALUE id_cas, VALUE options)
2498
2438
  VALUE exc = Qnil;
2499
2439
  do {
2500
2440
  std::chrono::milliseconds timeout{ 0 };
2501
- exc = cb__extract_timeout(timeout, options);
2441
+ exc = cb_extract_timeout(timeout, options);
2502
2442
  if (!NIL_P(exc)) {
2503
2443
  break;
2504
2444
  }
2505
2445
 
2506
2446
  couchbase::protocol::durability_level durability_level{ couchbase::protocol::durability_level::none };
2507
2447
  std::optional<std::uint16_t> durability_timeout{ std::nullopt };
2508
- exc = cb__extract_durability(durability_level, durability_timeout, options);
2448
+ exc = cb_extract_durability(durability_level, durability_timeout, options);
2509
2449
  if (!NIL_P(exc)) {
2510
2450
  break;
2511
2451
  }
2512
2452
 
2513
2453
  std::vector<std::pair<couchbase::document_id, std::uint64_t>> tuples{};
2514
- exc = cb__extract_array_of_id_cas(tuples, id_cas);
2454
+ exc = cb_extract_array_of_id_cas(tuples, id_cas);
2515
2455
  if (!NIL_P(exc)) {
2516
2456
  break;
2517
2457
  }
@@ -2536,9 +2476,9 @@ cb_Backend_document_remove_multi(VALUE self, VALUE id_cas, VALUE options)
2536
2476
  VALUE res = rb_ary_new_capa(static_cast<long>(num_of_tuples));
2537
2477
  for (auto& barrier : barriers) {
2538
2478
  auto resp = barrier->get_future().get();
2539
- VALUE entry = cb__extract_mutation_result(resp);
2479
+ VALUE entry = cb_extract_mutation_result(resp);
2540
2480
  if (resp.ctx.ec) {
2541
- rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb__map_error_code(resp.ctx, "unable (multi)remove"));
2481
+ rb_hash_aset(entry, rb_id2sym(rb_intern("error")), cb_map_error_code(resp.ctx, "unable (multi)remove"));
2542
2482
  }
2543
2483
  rb_ary_push(res, entry);
2544
2484
  }
@@ -2575,16 +2515,16 @@ cb_Backend_document_increment(VALUE self, VALUE bucket, VALUE collection, VALUE
2575
2515
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2576
2516
 
2577
2517
  couchbase::operations::increment_request req{ doc_id };
2578
- exc = cb__extract_timeout(req, options);
2518
+ exc = cb_extract_timeout(req, options);
2579
2519
  if (!NIL_P(exc)) {
2580
2520
  break;
2581
2521
  }
2582
- exc = cb__extract_durability(req, options);
2522
+ exc = cb_extract_durability(req, options);
2583
2523
  if (!NIL_P(exc)) {
2584
2524
  break;
2585
2525
  }
2586
2526
  VALUE delta = Qnil;
2587
- exc = cb__extract_option_bignum(delta, options, "delta");
2527
+ exc = cb_extract_option_bignum(delta, options, "delta");
2588
2528
  if (!NIL_P(exc)) {
2589
2529
  break;
2590
2530
  }
@@ -2592,7 +2532,7 @@ cb_Backend_document_increment(VALUE self, VALUE bucket, VALUE collection, VALUE
2592
2532
  req.delta = NUM2ULL(delta);
2593
2533
  }
2594
2534
  VALUE initial_value = Qnil;
2595
- exc = cb__extract_option_bignum(initial_value, options, "initial_value");
2535
+ exc = cb_extract_option_bignum(initial_value, options, "initial_value");
2596
2536
  if (!NIL_P(exc)) {
2597
2537
  break;
2598
2538
  }
@@ -2600,7 +2540,7 @@ cb_Backend_document_increment(VALUE self, VALUE bucket, VALUE collection, VALUE
2600
2540
  req.initial_value = NUM2ULL(initial_value);
2601
2541
  }
2602
2542
  VALUE expiry = Qnil;
2603
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2543
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2604
2544
  if (!NIL_P(exc)) {
2605
2545
  break;
2606
2546
  }
@@ -2611,12 +2551,12 @@ cb_Backend_document_increment(VALUE self, VALUE bucket, VALUE collection, VALUE
2611
2551
  auto barrier = std::make_shared<std::promise<couchbase::operations::increment_response>>();
2612
2552
  auto f = barrier->get_future();
2613
2553
  backend->cluster->execute(req, [barrier](couchbase::operations::increment_response&& resp) mutable { barrier->set_value(resp); });
2614
- auto resp = f.get();
2554
+ auto resp = cb_wait_for_future(f);
2615
2555
  if (resp.ctx.ec) {
2616
- exc = cb__map_error_code(resp.ctx.ec, fmt::format(R"(unable to increment by {})", req.delta));
2556
+ exc = cb_map_error_code(resp.ctx.ec, fmt::format(R"(unable to increment by {})", req.delta));
2617
2557
  break;
2618
2558
  }
2619
- VALUE res = cb__extract_mutation_result(resp);
2559
+ VALUE res = cb_extract_mutation_result(resp);
2620
2560
  rb_hash_aset(res, rb_id2sym(rb_intern("content")), ULL2NUM(resp.content));
2621
2561
  return res;
2622
2562
  } while (false);
@@ -2650,16 +2590,16 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2650
2590
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2651
2591
 
2652
2592
  couchbase::operations::decrement_request req{ doc_id };
2653
- exc = cb__extract_timeout(req, options);
2593
+ exc = cb_extract_timeout(req, options);
2654
2594
  if (!NIL_P(exc)) {
2655
2595
  break;
2656
2596
  }
2657
- exc = cb__extract_durability(req, options);
2597
+ exc = cb_extract_durability(req, options);
2658
2598
  if (!NIL_P(exc)) {
2659
2599
  break;
2660
2600
  }
2661
2601
  VALUE delta = Qnil;
2662
- exc = cb__extract_option_bignum(delta, options, "delta");
2602
+ exc = cb_extract_option_bignum(delta, options, "delta");
2663
2603
  if (!NIL_P(exc)) {
2664
2604
  break;
2665
2605
  }
@@ -2667,7 +2607,7 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2667
2607
  req.delta = NUM2ULL(delta);
2668
2608
  }
2669
2609
  VALUE initial_value = Qnil;
2670
- exc = cb__extract_option_bignum(initial_value, options, "initial_value");
2610
+ exc = cb_extract_option_bignum(initial_value, options, "initial_value");
2671
2611
  if (!NIL_P(exc)) {
2672
2612
  break;
2673
2613
  }
@@ -2675,7 +2615,7 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2675
2615
  req.initial_value = NUM2ULL(initial_value);
2676
2616
  }
2677
2617
  VALUE expiry = Qnil;
2678
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2618
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
2679
2619
  if (!NIL_P(exc)) {
2680
2620
  break;
2681
2621
  }
@@ -2686,12 +2626,12 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2686
2626
  auto barrier = std::make_shared<std::promise<couchbase::operations::decrement_response>>();
2687
2627
  auto f = barrier->get_future();
2688
2628
  backend->cluster->execute(req, [barrier](couchbase::operations::decrement_response&& resp) mutable { barrier->set_value(resp); });
2689
- auto resp = f.get();
2629
+ auto resp = cb_wait_for_future(f);
2690
2630
  if (resp.ctx.ec) {
2691
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to decrement by {})", req.delta));
2631
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to decrement by {})", req.delta));
2692
2632
  break;
2693
2633
  }
2694
- VALUE res = cb__extract_mutation_result(resp);
2634
+ VALUE res = cb_extract_mutation_result(resp);
2695
2635
  rb_hash_aset(res, rb_id2sym(rb_intern("content")), ULL2NUM(resp.content));
2696
2636
  return res;
2697
2637
  } while (false);
@@ -2700,7 +2640,7 @@ cb_Backend_document_decrement(VALUE self, VALUE bucket, VALUE collection, VALUE
2700
2640
  }
2701
2641
 
2702
2642
  static VALUE
2703
- cb__map_subdoc_opcode(couchbase::protocol::subdoc_opcode opcode)
2643
+ cb_map_subdoc_opcode(couchbase::protocol::subdoc_opcode opcode)
2704
2644
  {
2705
2645
  switch (opcode) {
2706
2646
  case couchbase::protocol::subdoc_opcode::get:
@@ -2752,7 +2692,7 @@ cb__map_subdoc_opcode(couchbase::protocol::subdoc_opcode opcode)
2752
2692
  }
2753
2693
 
2754
2694
  static void
2755
- cb__map_subdoc_status(couchbase::protocol::status status, std::size_t index, const std::string& path, VALUE entry)
2695
+ cb_map_subdoc_status(couchbase::protocol::status status, std::size_t index, const std::string& path, VALUE entry)
2756
2696
  {
2757
2697
  switch (status) {
2758
2698
  case couchbase::protocol::status::success:
@@ -2867,7 +2807,7 @@ cb__map_subdoc_status(couchbase::protocol::status status, std::size_t index, con
2867
2807
  rb_hash_aset(
2868
2808
  entry,
2869
2809
  rb_id2sym(rb_intern("error")),
2870
- rb_exc_new_cstr(eCouchbaseError,
2810
+ rb_exc_new_cstr(eBackendError,
2871
2811
  fmt::format("unknown subdocument error status={}, index={}, path={}", status, index, path).c_str()));
2872
2812
  return;
2873
2813
  }
@@ -2904,11 +2844,11 @@ cb_Backend_document_lookup_in(VALUE self, VALUE bucket, VALUE collection, VALUE
2904
2844
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
2905
2845
 
2906
2846
  couchbase::operations::lookup_in_request req{ doc_id };
2907
- exc = cb__extract_timeout(req, options);
2847
+ exc = cb_extract_timeout(req, options);
2908
2848
  if (!NIL_P(exc)) {
2909
2849
  break;
2910
2850
  }
2911
- exc = cb__extract_option_bool(req.access_deleted, options, "access_deleted");
2851
+ exc = cb_extract_option_bool(req.access_deleted, options, "access_deleted");
2912
2852
  if (!NIL_P(exc)) {
2913
2853
  break;
2914
2854
  }
@@ -2945,9 +2885,9 @@ cb_Backend_document_lookup_in(VALUE self, VALUE bucket, VALUE collection, VALUE
2945
2885
  auto barrier = std::make_shared<std::promise<couchbase::operations::lookup_in_response>>();
2946
2886
  auto f = barrier->get_future();
2947
2887
  backend->cluster->execute(req, [barrier](couchbase::operations::lookup_in_response&& resp) mutable { barrier->set_value(resp); });
2948
- auto resp = f.get();
2888
+ auto resp = cb_wait_for_future(f);
2949
2889
  if (resp.ctx.ec) {
2950
- exc = cb__map_error_code(resp.ctx, "unable fetch");
2890
+ exc = cb_map_error_code(resp.ctx, "unable fetch");
2951
2891
  break;
2952
2892
  }
2953
2893
 
@@ -2962,17 +2902,13 @@ cb_Backend_document_lookup_in(VALUE self, VALUE bucket, VALUE collection, VALUE
2962
2902
  VALUE entry = rb_hash_new();
2963
2903
  rb_hash_aset(entry, rb_id2sym(rb_intern("index")), ULL2NUM(i));
2964
2904
  rb_hash_aset(entry, rb_id2sym(rb_intern("exists")), resp.fields[i].exists ? Qtrue : Qfalse);
2965
- rb_hash_aset(entry,
2966
- rb_id2sym(rb_intern("path")),
2967
- rb_external_str_new(resp.fields[i].path.data(), static_cast<long>(resp.fields[i].path.size())));
2968
- rb_hash_aset(entry,
2969
- rb_id2sym(rb_intern("value")),
2970
- rb_external_str_new(resp.fields[i].value.data(), static_cast<long>(resp.fields[i].value.size())));
2971
- cb__map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
2905
+ rb_hash_aset(entry, rb_id2sym(rb_intern("path")), cb_str_new(resp.fields[i].path));
2906
+ rb_hash_aset(entry, rb_id2sym(rb_intern("value")), cb_str_new(resp.fields[i].value));
2907
+ cb_map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
2972
2908
  if (resp.fields[i].opcode == couchbase::protocol::subdoc_opcode::get && resp.fields[i].path.empty()) {
2973
2909
  rb_hash_aset(entry, rb_id2sym(rb_intern("type")), rb_id2sym(rb_intern("get_doc")));
2974
2910
  } else {
2975
- rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb__map_subdoc_opcode(resp.fields[i].opcode));
2911
+ rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb_map_subdoc_opcode(resp.fields[i].opcode));
2976
2912
  }
2977
2913
  rb_ary_store(fields, static_cast<long>(i), entry);
2978
2914
  }
@@ -3013,16 +2949,16 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3013
2949
  doc_id.key.assign(RSTRING_PTR(id), static_cast<size_t>(RSTRING_LEN(id)));
3014
2950
 
3015
2951
  couchbase::operations::mutate_in_request req{ doc_id };
3016
- exc = cb__extract_timeout(req, options);
2952
+ exc = cb_extract_timeout(req, options);
3017
2953
  if (!NIL_P(exc)) {
3018
2954
  break;
3019
2955
  }
3020
- exc = cb__extract_durability(req, options);
2956
+ exc = cb_extract_durability(req, options);
3021
2957
  if (!NIL_P(exc)) {
3022
2958
  break;
3023
2959
  }
3024
2960
  VALUE cas = Qnil;
3025
- exc = cb__extract_option_bignum(cas, options, "cas");
2961
+ exc = cb_extract_option_bignum(cas, options, "cas");
3026
2962
  if (!NIL_P(exc)) {
3027
2963
  break;
3028
2964
  }
@@ -3030,23 +2966,23 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3030
2966
  req.cas = NUM2ULL(cas);
3031
2967
  }
3032
2968
  VALUE expiry = Qnil;
3033
- exc = cb__extract_option_fixnum(expiry, options, "expiry");
2969
+ exc = cb_extract_option_fixnum(expiry, options, "expiry");
3034
2970
  if (!NIL_P(exc)) {
3035
2971
  break;
3036
2972
  }
3037
2973
  if (!NIL_P(expiry)) {
3038
2974
  req.expiry = FIX2UINT(expiry);
3039
2975
  }
3040
- exc = cb__extract_option_bool(req.access_deleted, options, "access_deleted");
2976
+ exc = cb_extract_option_bool(req.access_deleted, options, "access_deleted");
3041
2977
  if (!NIL_P(exc)) {
3042
2978
  break;
3043
2979
  }
3044
- exc = cb__extract_option_bool(req.create_as_deleted, options, "create_as_deleted");
2980
+ exc = cb_extract_option_bool(req.create_as_deleted, options, "create_as_deleted");
3045
2981
  if (!NIL_P(exc)) {
3046
2982
  break;
3047
2983
  }
3048
2984
  VALUE store_semantics = Qnil;
3049
- exc = cb__extract_option_symbol(store_semantics, options, "store_semantics");
2985
+ exc = cb_extract_option_symbol(store_semantics, options, "store_semantics");
3050
2986
  if (!NIL_P(exc)) {
3051
2987
  break;
3052
2988
  }
@@ -3125,13 +3061,13 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3125
3061
  auto barrier = std::make_shared<std::promise<couchbase::operations::mutate_in_response>>();
3126
3062
  auto f = barrier->get_future();
3127
3063
  backend->cluster->execute(req, [barrier](couchbase::operations::mutate_in_response&& resp) mutable { barrier->set_value(resp); });
3128
- auto resp = f.get();
3064
+ auto resp = cb_wait_for_future(f);
3129
3065
  if (resp.ctx.ec) {
3130
- exc = cb__map_error_code(resp.ctx, "unable to mutate");
3066
+ exc = cb_map_error_code(resp.ctx, "unable to mutate");
3131
3067
  break;
3132
3068
  }
3133
3069
 
3134
- VALUE res = cb__extract_mutation_result(resp);
3070
+ VALUE res = cb_extract_mutation_result(resp);
3135
3071
  if (resp.first_error_index) {
3136
3072
  rb_hash_aset(res, rb_id2sym(rb_intern("first_error_index")), ULL2NUM(resp.first_error_index.value()));
3137
3073
  }
@@ -3143,9 +3079,7 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3143
3079
  for (size_t i = 0; i < resp.fields.size(); ++i) {
3144
3080
  VALUE entry = rb_hash_new();
3145
3081
  rb_hash_aset(entry, rb_id2sym(rb_intern("index")), ULL2NUM(i));
3146
- rb_hash_aset(entry,
3147
- rb_id2sym(rb_intern("path")),
3148
- rb_external_str_new(resp.fields[i].path.data(), static_cast<long>(resp.fields[i].path.size())));
3082
+ rb_hash_aset(entry, rb_id2sym(rb_intern("path")), cb_str_new(resp.fields[i].path));
3149
3083
  if (resp.fields[i].status == couchbase::protocol::status::success ||
3150
3084
  resp.fields[i].status == couchbase::protocol::status::subdoc_success_deleted) {
3151
3085
  if (resp.fields[i].opcode == couchbase::protocol::subdoc_opcode::counter) {
@@ -3153,13 +3087,11 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3153
3087
  rb_hash_aset(entry, rb_id2sym(rb_intern("value")), LL2NUM(std::stoll(resp.fields[i].value)));
3154
3088
  }
3155
3089
  } else {
3156
- rb_hash_aset(entry,
3157
- rb_id2sym(rb_intern("value")),
3158
- rb_external_str_new(resp.fields[i].value.data(), static_cast<long>(resp.fields[i].value.size())));
3090
+ rb_hash_aset(entry, rb_id2sym(rb_intern("value")), cb_str_new(resp.fields[i].value));
3159
3091
  }
3160
3092
  }
3161
- cb__map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
3162
- rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb__map_subdoc_opcode(resp.fields[i].opcode));
3093
+ cb_map_subdoc_status(resp.fields[i].status, i, resp.fields[i].path, entry);
3094
+ rb_hash_aset(entry, rb_id2sym(rb_intern("type")), cb_map_subdoc_opcode(resp.fields[i].opcode));
3163
3095
  rb_ary_store(fields, static_cast<long>(i), entry);
3164
3096
  }
3165
3097
  return res;
@@ -3169,7 +3101,7 @@ cb_Backend_document_mutate_in(VALUE self, VALUE bucket, VALUE collection, VALUE
3169
3101
  }
3170
3102
 
3171
3103
  static int
3172
- cb__for_each_named_param(VALUE key, VALUE value, VALUE arg)
3104
+ cb_for_each_named_param(VALUE key, VALUE value, VALUE arg)
3173
3105
  {
3174
3106
  auto* preq = reinterpret_cast<couchbase::operations::query_request*>(arg);
3175
3107
  Check_Type(key, T_STRING);
@@ -3203,7 +3135,7 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3203
3135
  Check_Type(client_context_id, T_STRING);
3204
3136
  req.client_context_id.assign(RSTRING_PTR(client_context_id), static_cast<size_t>(RSTRING_LEN(client_context_id)));
3205
3137
  }
3206
- exc = cb__extract_timeout(req, options);
3138
+ exc = cb_extract_timeout(req, options);
3207
3139
  if (!NIL_P(exc)) {
3208
3140
  break;
3209
3141
  }
@@ -3286,7 +3218,7 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3286
3218
  VALUE named_params = rb_hash_aref(options, rb_id2sym(rb_intern("named_parameters")));
3287
3219
  if (!NIL_P(named_params)) {
3288
3220
  Check_Type(named_params, T_HASH);
3289
- rb_hash_foreach(named_params, INT_FUNC(cb__for_each_named_param), reinterpret_cast<VALUE>(&req));
3221
+ rb_hash_foreach(named_params, INT_FUNC(cb_for_each_named_param), reinterpret_cast<VALUE>(&req));
3290
3222
  }
3291
3223
  VALUE scan_consistency = rb_hash_aref(options, rb_id2sym(rb_intern("scan_consistency")));
3292
3224
  if (!NIL_P(scan_consistency)) {
@@ -3337,19 +3269,19 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3337
3269
  VALUE raw_params = rb_hash_aref(options, rb_id2sym(rb_intern("raw_parameters")));
3338
3270
  if (!NIL_P(raw_params)) {
3339
3271
  Check_Type(raw_params, T_HASH);
3340
- rb_hash_foreach(raw_params, INT_FUNC(cb__for_each_named_param), reinterpret_cast<VALUE>(&req));
3272
+ rb_hash_foreach(raw_params, INT_FUNC(cb_for_each_named_param), reinterpret_cast<VALUE>(&req));
3341
3273
  }
3342
3274
 
3343
3275
  auto barrier = std::make_shared<std::promise<couchbase::operations::query_response>>();
3344
3276
  auto f = barrier->get_future();
3345
3277
  backend->cluster->execute_http(req, [barrier](couchbase::operations::query_response&& resp) mutable { barrier->set_value(resp); });
3346
- auto resp = f.get();
3278
+ auto resp = cb_wait_for_future(f);
3347
3279
  if (resp.ctx.ec) {
3348
3280
  if (resp.payload.meta_data.errors && !resp.payload.meta_data.errors->empty()) {
3349
3281
  const auto& first_error = resp.payload.meta_data.errors->front();
3350
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to query ({}: {}))", first_error.code, first_error.message));
3282
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to query ({}: {}))", first_error.code, first_error.message));
3351
3283
  } else {
3352
- exc = cb__map_error_code(resp.ctx, "unable to query");
3284
+ exc = cb_map_error_code(resp.ctx, "unable to query");
3353
3285
  }
3354
3286
  break;
3355
3287
  }
@@ -3357,46 +3289,28 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3357
3289
  VALUE rows = rb_ary_new_capa(static_cast<long>(resp.payload.rows.size()));
3358
3290
  rb_hash_aset(res, rb_id2sym(rb_intern("rows")), rows);
3359
3291
  for (auto& row : resp.payload.rows) {
3360
- rb_ary_push(rows, rb_external_str_new(row.data(), static_cast<long>(row.size())));
3292
+ rb_ary_push(rows, cb_str_new(row));
3361
3293
  }
3362
3294
  VALUE meta = rb_hash_new();
3363
3295
  rb_hash_aset(res, rb_id2sym(rb_intern("meta")), meta);
3364
3296
  rb_hash_aset(meta,
3365
3297
  rb_id2sym(rb_intern("status")),
3366
3298
  rb_id2sym(rb_intern2(resp.payload.meta_data.status.data(), static_cast<long>(resp.payload.meta_data.status.size()))));
3367
- rb_hash_aset(
3368
- meta,
3369
- rb_id2sym(rb_intern("request_id")),
3370
- rb_external_str_new(resp.payload.meta_data.request_id.data(), static_cast<long>(resp.payload.meta_data.request_id.size())));
3371
- rb_hash_aset(meta,
3372
- rb_id2sym(rb_intern("client_context_id")),
3373
- rb_external_str_new(resp.payload.meta_data.client_context_id.data(),
3374
- static_cast<long>(resp.payload.meta_data.client_context_id.size())));
3299
+ rb_hash_aset(meta, rb_id2sym(rb_intern("request_id")), cb_str_new(resp.payload.meta_data.request_id));
3300
+ rb_hash_aset(meta, rb_id2sym(rb_intern("client_context_id")), cb_str_new(resp.payload.meta_data.client_context_id));
3375
3301
  if (resp.payload.meta_data.signature) {
3376
- rb_hash_aset(
3377
- meta,
3378
- rb_id2sym(rb_intern("signature")),
3379
- rb_external_str_new(resp.payload.meta_data.signature->data(), static_cast<long>(resp.payload.meta_data.signature->size())));
3302
+ rb_hash_aset(meta, rb_id2sym(rb_intern("signature")), cb_str_new(resp.payload.meta_data.signature.value()));
3380
3303
  }
3381
3304
  if (resp.payload.meta_data.profile) {
3382
- rb_hash_aset(
3383
- meta,
3384
- rb_id2sym(rb_intern("profile")),
3385
- rb_external_str_new(resp.payload.meta_data.profile->data(), static_cast<long>(resp.payload.meta_data.profile->size())));
3305
+ rb_hash_aset(meta, rb_id2sym(rb_intern("profile")), cb_str_new(resp.payload.meta_data.profile.value()));
3386
3306
  }
3387
3307
  metrics = rb_hash_new();
3388
3308
  rb_hash_aset(meta, rb_id2sym(rb_intern("metrics")), metrics);
3389
3309
  if (!resp.payload.meta_data.metrics.elapsed_time.empty()) {
3390
- rb_hash_aset(metrics,
3391
- rb_id2sym(rb_intern("elapsed_time")),
3392
- rb_external_str_new(resp.payload.meta_data.metrics.elapsed_time.data(),
3393
- static_cast<long>(resp.payload.meta_data.metrics.elapsed_time.size())));
3310
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("elapsed_time")), cb_str_new(resp.payload.meta_data.metrics.elapsed_time));
3394
3311
  }
3395
3312
  if (!resp.payload.meta_data.metrics.execution_time.empty()) {
3396
- rb_hash_aset(metrics,
3397
- rb_id2sym(rb_intern("execution_time")),
3398
- rb_external_str_new(resp.payload.meta_data.metrics.execution_time.data(),
3399
- static_cast<long>(resp.payload.meta_data.metrics.execution_time.size())));
3313
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("execution_time")), cb_str_new(resp.payload.meta_data.metrics.execution_time));
3400
3314
  }
3401
3315
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_count")), ULL2NUM(resp.payload.meta_data.metrics.result_count));
3402
3316
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_size")), ULL2NUM(resp.payload.meta_data.metrics.result_size));
@@ -3420,7 +3334,7 @@ cb_Backend_document_query(VALUE self, VALUE statement, VALUE options)
3420
3334
  }
3421
3335
 
3422
3336
  static VALUE
3423
- cb__generate_bucket_settings(VALUE bucket, couchbase::operations::bucket_settings& entry, bool is_create)
3337
+ cb_generate_bucket_settings(VALUE bucket, couchbase::operations::bucket_settings& entry, bool is_create)
3424
3338
  {
3425
3339
  {
3426
3340
  VALUE bucket_type = rb_hash_aref(bucket, rb_id2sym(rb_intern("bucket_type")));
@@ -3586,11 +3500,11 @@ cb_Backend_bucket_create(VALUE self, VALUE bucket_settings, VALUE timeout)
3586
3500
  VALUE exc = Qnil;
3587
3501
  do {
3588
3502
  couchbase::operations::bucket_create_request req{};
3589
- exc = cb__extract_timeout(req, timeout);
3503
+ exc = cb_extract_timeout(req, timeout);
3590
3504
  if (!NIL_P(exc)) {
3591
3505
  break;
3592
3506
  }
3593
- exc = cb__generate_bucket_settings(bucket_settings, req.bucket, true);
3507
+ exc = cb_generate_bucket_settings(bucket_settings, req.bucket, true);
3594
3508
  if (!NIL_P(exc)) {
3595
3509
  break;
3596
3510
  }
@@ -3598,10 +3512,10 @@ cb_Backend_bucket_create(VALUE self, VALUE bucket_settings, VALUE timeout)
3598
3512
  auto f = barrier->get_future();
3599
3513
  backend->cluster->execute_http(
3600
3514
  req, [barrier](couchbase::operations::bucket_create_response&& resp) mutable { barrier->set_value(resp); });
3601
- auto resp = f.get();
3515
+ auto resp = cb_wait_for_future(f);
3602
3516
  if (resp.ctx.ec) {
3603
- exc = cb__map_error_code(
3604
- resp.ctx, fmt::format("unable to create bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3517
+ exc = cb_map_error_code(resp.ctx,
3518
+ fmt::format("unable to create bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3605
3519
  break;
3606
3520
  }
3607
3521
 
@@ -3626,11 +3540,11 @@ cb_Backend_bucket_update(VALUE self, VALUE bucket_settings, VALUE timeout)
3626
3540
  VALUE exc = Qnil;
3627
3541
  do {
3628
3542
  couchbase::operations::bucket_update_request req{};
3629
- exc = cb__extract_timeout(req, timeout);
3543
+ exc = cb_extract_timeout(req, timeout);
3630
3544
  if (!NIL_P(exc)) {
3631
3545
  break;
3632
3546
  }
3633
- exc = cb__generate_bucket_settings(bucket_settings, req.bucket, false);
3547
+ exc = cb_generate_bucket_settings(bucket_settings, req.bucket, false);
3634
3548
  if (!NIL_P(exc)) {
3635
3549
  break;
3636
3550
  }
@@ -3638,10 +3552,10 @@ cb_Backend_bucket_update(VALUE self, VALUE bucket_settings, VALUE timeout)
3638
3552
  auto f = barrier->get_future();
3639
3553
  backend->cluster->execute_http(
3640
3554
  req, [barrier](couchbase::operations::bucket_update_response&& resp) mutable { barrier->set_value(resp); });
3641
- auto resp = f.get();
3555
+ auto resp = cb_wait_for_future(f);
3642
3556
  if (resp.ctx.ec) {
3643
- exc = cb__map_error_code(
3644
- resp.ctx, fmt::format("unable to update bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3557
+ exc = cb_map_error_code(resp.ctx,
3558
+ fmt::format("unable to update bucket \"{}\" on the cluster ({})", req.bucket.name, resp.error_message));
3645
3559
  break;
3646
3560
  }
3647
3561
  return Qtrue;
@@ -3666,7 +3580,7 @@ cb_Backend_bucket_drop(VALUE self, VALUE bucket_name, VALUE timeout)
3666
3580
  VALUE exc = Qnil;
3667
3581
  do {
3668
3582
  couchbase::operations::bucket_drop_request req{};
3669
- exc = cb__extract_timeout(req, timeout);
3583
+ exc = cb_extract_timeout(req, timeout);
3670
3584
  if (!NIL_P(exc)) {
3671
3585
  break;
3672
3586
  }
@@ -3675,9 +3589,9 @@ cb_Backend_bucket_drop(VALUE self, VALUE bucket_name, VALUE timeout)
3675
3589
  auto f = barrier->get_future();
3676
3590
  backend->cluster->execute_http(req,
3677
3591
  [barrier](couchbase::operations::bucket_drop_response&& resp) mutable { barrier->set_value(resp); });
3678
- auto resp = f.get();
3592
+ auto resp = cb_wait_for_future(f);
3679
3593
  if (resp.ctx.ec) {
3680
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to remove bucket \"{}\" on the cluster", req.name));
3594
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to remove bucket \"{}\" on the cluster", req.name));
3681
3595
  break;
3682
3596
  }
3683
3597
  return Qtrue;
@@ -3702,7 +3616,7 @@ cb_Backend_bucket_flush(VALUE self, VALUE bucket_name, VALUE timeout)
3702
3616
  VALUE exc = Qnil;
3703
3617
  do {
3704
3618
  couchbase::operations::bucket_flush_request req{};
3705
- exc = cb__extract_timeout(req, timeout);
3619
+ exc = cb_extract_timeout(req, timeout);
3706
3620
  if (!NIL_P(exc)) {
3707
3621
  break;
3708
3622
  }
@@ -3711,9 +3625,9 @@ cb_Backend_bucket_flush(VALUE self, VALUE bucket_name, VALUE timeout)
3711
3625
  auto f = barrier->get_future();
3712
3626
  backend->cluster->execute_http(
3713
3627
  req, [barrier](couchbase::operations::bucket_flush_response&& resp) mutable { barrier->set_value(resp); });
3714
- auto resp = f.get();
3628
+ auto resp = cb_wait_for_future(f);
3715
3629
  if (resp.ctx.ec) {
3716
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to flush bucket \"{}\" on the cluster", req.name));
3630
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to flush bucket \"{}\" on the cluster", req.name));
3717
3631
  break;
3718
3632
  }
3719
3633
 
@@ -3724,7 +3638,7 @@ cb_Backend_bucket_flush(VALUE self, VALUE bucket_name, VALUE timeout)
3724
3638
  }
3725
3639
 
3726
3640
  static void
3727
- cb__extract_bucket_settings(const couchbase::operations::bucket_settings& entry, VALUE bucket)
3641
+ cb_extract_bucket_settings(const couchbase::operations::bucket_settings& entry, VALUE bucket)
3728
3642
  {
3729
3643
  switch (entry.bucket_type) {
3730
3644
  case couchbase::operations::bucket_settings::bucket_type::couchbase:
@@ -3740,8 +3654,8 @@ cb__extract_bucket_settings(const couchbase::operations::bucket_settings& entry,
3740
3654
  rb_hash_aset(bucket, rb_id2sym(rb_intern("bucket_type")), Qnil);
3741
3655
  break;
3742
3656
  }
3743
- rb_hash_aset(bucket, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
3744
- rb_hash_aset(bucket, rb_id2sym(rb_intern("uuid")), rb_external_str_new(entry.uuid.data(), static_cast<long>(entry.uuid.size())));
3657
+ rb_hash_aset(bucket, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
3658
+ rb_hash_aset(bucket, rb_id2sym(rb_intern("uuid")), cb_str_new(entry.uuid));
3745
3659
  rb_hash_aset(bucket, rb_id2sym(rb_intern("ram_quota_mb")), ULL2NUM(entry.ram_quota_mb));
3746
3660
  rb_hash_aset(bucket, rb_id2sym(rb_intern("max_expiry")), ULONG2NUM(entry.max_expiry));
3747
3661
  switch (entry.compression_mode) {
@@ -3808,15 +3722,15 @@ cb__extract_bucket_settings(const couchbase::operations::bucket_settings& entry,
3808
3722
  }
3809
3723
  VALUE capabilities = rb_ary_new_capa(static_cast<long>(entry.capabilities.size()));
3810
3724
  for (const auto& capa : entry.capabilities) {
3811
- rb_ary_push(capabilities, rb_external_str_new(capa.data(), static_cast<long>(capa.size())));
3725
+ rb_ary_push(capabilities, cb_str_new(capa));
3812
3726
  }
3813
3727
  rb_hash_aset(bucket, rb_id2sym(rb_intern("capabilities")), capabilities);
3814
3728
  VALUE nodes = rb_ary_new_capa(static_cast<long>(entry.nodes.size()));
3815
3729
  for (const auto& n : entry.nodes) {
3816
3730
  VALUE node = rb_hash_new();
3817
- rb_hash_aset(node, rb_id2sym(rb_intern("status")), rb_external_str_new(n.status.data(), static_cast<long>(n.status.size())));
3818
- rb_hash_aset(node, rb_id2sym(rb_intern("hostname")), rb_external_str_new(n.hostname.data(), static_cast<long>(n.hostname.size())));
3819
- rb_hash_aset(node, rb_id2sym(rb_intern("version")), rb_external_str_new(n.version.data(), static_cast<long>(n.version.size())));
3731
+ rb_hash_aset(node, rb_id2sym(rb_intern("status")), cb_str_new(n.status));
3732
+ rb_hash_aset(node, rb_id2sym(rb_intern("hostname")), cb_str_new(n.hostname));
3733
+ rb_hash_aset(node, rb_id2sym(rb_intern("version")), cb_str_new(n.version));
3820
3734
  rb_ary_push(nodes, node);
3821
3735
  }
3822
3736
  rb_hash_aset(bucket, rb_id2sym(rb_intern("nodes")), nodes);
@@ -3836,7 +3750,7 @@ cb_Backend_bucket_get_all(VALUE self, VALUE timeout)
3836
3750
  VALUE exc = Qnil;
3837
3751
  do {
3838
3752
  couchbase::operations::bucket_get_all_request req{};
3839
- exc = cb__extract_timeout(req, timeout);
3753
+ exc = cb_extract_timeout(req, timeout);
3840
3754
  if (!NIL_P(exc)) {
3841
3755
  break;
3842
3756
  }
@@ -3844,16 +3758,16 @@ cb_Backend_bucket_get_all(VALUE self, VALUE timeout)
3844
3758
  auto f = barrier->get_future();
3845
3759
  backend->cluster->execute_http(
3846
3760
  req, [barrier](couchbase::operations::bucket_get_all_response&& resp) mutable { barrier->set_value(resp); });
3847
- auto resp = f.get();
3761
+ auto resp = cb_wait_for_future(f);
3848
3762
  if (resp.ctx.ec) {
3849
- exc = cb__map_error_code(resp.ctx, "unable to get list of the buckets of the cluster");
3763
+ exc = cb_map_error_code(resp.ctx, "unable to get list of the buckets of the cluster");
3850
3764
  break;
3851
3765
  }
3852
3766
 
3853
3767
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.buckets.size()));
3854
3768
  for (const auto& entry : resp.buckets) {
3855
3769
  VALUE bucket = rb_hash_new();
3856
- cb__extract_bucket_settings(entry, bucket);
3770
+ cb_extract_bucket_settings(entry, bucket);
3857
3771
  rb_ary_push(res, bucket);
3858
3772
  }
3859
3773
 
@@ -3879,7 +3793,7 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE timeout)
3879
3793
  VALUE exc = Qnil;
3880
3794
  do {
3881
3795
  couchbase::operations::bucket_get_request req{};
3882
- exc = cb__extract_timeout(req, timeout);
3796
+ exc = cb_extract_timeout(req, timeout);
3883
3797
  if (!NIL_P(exc)) {
3884
3798
  break;
3885
3799
  }
@@ -3888,14 +3802,14 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE timeout)
3888
3802
  auto f = barrier->get_future();
3889
3803
  backend->cluster->execute_http(req,
3890
3804
  [barrier](couchbase::operations::bucket_get_response&& resp) mutable { barrier->set_value(resp); });
3891
- auto resp = f.get();
3805
+ auto resp = cb_wait_for_future(f);
3892
3806
  if (resp.ctx.ec) {
3893
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to locate bucket \"{}\" on the cluster", req.name));
3807
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to locate bucket \"{}\" on the cluster", req.name));
3894
3808
  break;
3895
3809
  }
3896
3810
 
3897
3811
  VALUE res = rb_hash_new();
3898
- cb__extract_bucket_settings(resp.bucket, res);
3812
+ cb_extract_bucket_settings(resp.bucket, res);
3899
3813
 
3900
3814
  return res;
3901
3815
  } while (false);
@@ -3904,26 +3818,19 @@ cb_Backend_bucket_get(VALUE self, VALUE bucket_name, VALUE timeout)
3904
3818
  }
3905
3819
 
3906
3820
  static void
3907
- cb__extract_role(const couchbase::operations::rbac::role_and_description& entry, VALUE role)
3908
- {
3909
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
3910
- rb_hash_aset(role,
3911
- rb_id2sym(rb_intern("display_name")),
3912
- rb_external_str_new(entry.display_name.data(), static_cast<long>(entry.display_name.size())));
3913
- rb_hash_aset(role,
3914
- rb_id2sym(rb_intern("description")),
3915
- rb_external_str_new(entry.description.data(), static_cast<long>(entry.description.size())));
3821
+ cb_extract_role(const couchbase::operations::rbac::role_and_description& entry, VALUE role)
3822
+ {
3823
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
3824
+ rb_hash_aset(role, rb_id2sym(rb_intern("display_name")), cb_str_new(entry.display_name));
3825
+ rb_hash_aset(role, rb_id2sym(rb_intern("description")), cb_str_new(entry.description));
3916
3826
  if (entry.bucket) {
3917
- rb_hash_aset(
3918
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(entry.bucket->data(), static_cast<long>(entry.bucket->size())));
3827
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(entry.bucket.value()));
3919
3828
  }
3920
3829
  if (entry.scope) {
3921
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(entry.scope->data(), static_cast<long>(entry.scope->size())));
3830
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(entry.scope.value()));
3922
3831
  }
3923
3832
  if (entry.collection) {
3924
- rb_hash_aset(role,
3925
- rb_id2sym(rb_intern("collection")),
3926
- rb_external_str_new(entry.collection->data(), static_cast<long>(entry.collection->size())));
3833
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(entry.collection.value()));
3927
3834
  }
3928
3835
  }
3929
3836
 
@@ -3941,7 +3848,7 @@ cb_Backend_role_get_all(VALUE self, VALUE timeout)
3941
3848
  VALUE exc = Qnil;
3942
3849
  do {
3943
3850
  couchbase::operations::role_get_all_request req{};
3944
- exc = cb__extract_timeout(req, timeout);
3851
+ exc = cb_extract_timeout(req, timeout);
3945
3852
  if (!NIL_P(exc)) {
3946
3853
  break;
3947
3854
  }
@@ -3949,16 +3856,16 @@ cb_Backend_role_get_all(VALUE self, VALUE timeout)
3949
3856
  auto f = barrier->get_future();
3950
3857
  backend->cluster->execute_http(
3951
3858
  req, [barrier](couchbase::operations::role_get_all_response&& resp) mutable { barrier->set_value(resp); });
3952
- auto resp = f.get();
3859
+ auto resp = cb_wait_for_future(f);
3953
3860
  if (resp.ctx.ec) {
3954
- exc = cb__map_error_code(resp.ctx, "unable to fetch roles");
3861
+ exc = cb_map_error_code(resp.ctx, "unable to fetch roles");
3955
3862
  break;
3956
3863
  }
3957
3864
 
3958
3865
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.roles.size()));
3959
3866
  for (const auto& entry : resp.roles) {
3960
3867
  VALUE role = rb_hash_new();
3961
- cb__extract_role(entry, role);
3868
+ cb_extract_role(entry, role);
3962
3869
  rb_ary_push(res, role);
3963
3870
  }
3964
3871
  return res;
@@ -3968,10 +3875,9 @@ cb_Backend_role_get_all(VALUE self, VALUE timeout)
3968
3875
  }
3969
3876
 
3970
3877
  static void
3971
- cb__extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VALUE user)
3878
+ cb_extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VALUE user)
3972
3879
  {
3973
- rb_hash_aset(
3974
- user, rb_id2sym(rb_intern("username")), rb_external_str_new(entry.username.data(), static_cast<long>(entry.username.size())));
3880
+ rb_hash_aset(user, rb_id2sym(rb_intern("username")), cb_str_new(entry.username));
3975
3881
  switch (entry.domain) {
3976
3882
  case couchbase::operations::rbac::auth_domain::local:
3977
3883
  rb_hash_aset(user, rb_id2sym(rb_intern("domain")), rb_id2sym(rb_intern("local")));
@@ -3984,47 +3890,39 @@ cb__extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VA
3984
3890
  }
3985
3891
  VALUE external_groups = rb_ary_new_capa(static_cast<long>(entry.external_groups.size()));
3986
3892
  for (const auto& group : entry.external_groups) {
3987
- rb_ary_push(external_groups, rb_external_str_new(group.data(), static_cast<long>(group.size())));
3893
+ rb_ary_push(external_groups, cb_str_new(group));
3988
3894
  }
3989
3895
  rb_hash_aset(user, rb_id2sym(rb_intern("external_groups")), external_groups);
3990
3896
  VALUE groups = rb_ary_new_capa(static_cast<long>(entry.groups.size()));
3991
3897
  for (const auto& group : entry.groups) {
3992
- rb_ary_push(groups, rb_external_str_new(group.data(), static_cast<long>(group.size())));
3898
+ rb_ary_push(groups, cb_str_new(group));
3993
3899
  }
3994
3900
  rb_hash_aset(user, rb_id2sym(rb_intern("groups")), groups);
3995
3901
  if (entry.display_name) {
3996
- rb_hash_aset(user,
3997
- rb_id2sym(rb_intern("display_name")),
3998
- rb_external_str_new(entry.display_name->data(), static_cast<long>(entry.display_name->size())));
3902
+ rb_hash_aset(user, rb_id2sym(rb_intern("display_name")), cb_str_new(entry.display_name.value()));
3999
3903
  }
4000
3904
  if (entry.password_changed) {
4001
- rb_hash_aset(user,
4002
- rb_id2sym(rb_intern("password_changed")),
4003
- rb_external_str_new(entry.password_changed->data(), static_cast<long>(entry.password_changed->size())));
3905
+ rb_hash_aset(user, rb_id2sym(rb_intern("password_changed")), cb_str_new(entry.password_changed.value()));
4004
3906
  }
4005
3907
  VALUE effective_roles = rb_ary_new_capa(static_cast<long>(entry.effective_roles.size()));
4006
3908
  for (const auto& er : entry.effective_roles) {
4007
3909
  VALUE role = rb_hash_new();
4008
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(er.name.data(), static_cast<long>(er.name.size())));
3910
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(er.name));
4009
3911
  if (er.bucket) {
4010
- rb_hash_aset(
4011
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(er.bucket->data(), static_cast<long>(er.bucket->size())));
3912
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(er.bucket.value()));
4012
3913
  }
4013
3914
  if (er.scope) {
4014
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(er.scope->data(), static_cast<long>(er.scope->size())));
3915
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(er.scope.value()));
4015
3916
  }
4016
3917
  if (er.collection) {
4017
- rb_hash_aset(role,
4018
- rb_id2sym(rb_intern("collection")),
4019
- rb_external_str_new(er.collection->data(), static_cast<long>(er.collection->size())));
3918
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(er.collection.value()));
4020
3919
  }
4021
3920
  VALUE origins = rb_ary_new_capa(static_cast<long>(er.origins.size()));
4022
3921
  for (const auto& orig : er.origins) {
4023
3922
  VALUE origin = rb_hash_new();
4024
- rb_hash_aset(origin, rb_id2sym(rb_intern("type")), rb_external_str_new(orig.type.data(), static_cast<long>(orig.type.size())));
3923
+ rb_hash_aset(origin, rb_id2sym(rb_intern("type")), cb_str_new(orig.type));
4025
3924
  if (orig.name) {
4026
- rb_hash_aset(
4027
- origin, rb_id2sym(rb_intern("name")), rb_external_str_new(orig.name->data(), static_cast<long>(orig.name->size())));
3925
+ rb_hash_aset(origin, rb_id2sym(rb_intern("name")), cb_str_new(orig.name.value()));
4028
3926
  }
4029
3927
  rb_ary_push(origins, origin);
4030
3928
  }
@@ -4036,18 +3934,15 @@ cb__extract_user(const couchbase::operations::rbac::user_and_metadata& entry, VA
4036
3934
  VALUE roles = rb_ary_new_capa(static_cast<long>(entry.roles.size()));
4037
3935
  for (const auto& er : entry.roles) {
4038
3936
  VALUE role = rb_hash_new();
4039
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(er.name.data(), static_cast<long>(er.name.size())));
3937
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(er.name));
4040
3938
  if (er.bucket) {
4041
- rb_hash_aset(
4042
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(er.bucket->data(), static_cast<long>(er.bucket->size())));
3939
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(er.bucket.value()));
4043
3940
  }
4044
3941
  if (er.scope) {
4045
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(er.scope->data(), static_cast<long>(er.scope->size())));
3942
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(er.scope.value()));
4046
3943
  }
4047
3944
  if (er.collection) {
4048
- rb_hash_aset(role,
4049
- rb_id2sym(rb_intern("collection")),
4050
- rb_external_str_new(er.collection->data(), static_cast<long>(er.collection->size())));
3945
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(er.collection.value()));
4051
3946
  }
4052
3947
  rb_ary_push(roles, role);
4053
3948
  }
@@ -4070,7 +3965,7 @@ cb_Backend_user_get_all(VALUE self, VALUE domain, VALUE timeout)
4070
3965
  VALUE exc = Qnil;
4071
3966
  do {
4072
3967
  couchbase::operations::user_get_all_request req{};
4073
- exc = cb__extract_timeout(req, timeout);
3968
+ exc = cb_extract_timeout(req, timeout);
4074
3969
  if (!NIL_P(exc)) {
4075
3970
  break;
4076
3971
  }
@@ -4086,16 +3981,16 @@ cb_Backend_user_get_all(VALUE self, VALUE domain, VALUE timeout)
4086
3981
  auto f = barrier->get_future();
4087
3982
  backend->cluster->execute_http(
4088
3983
  req, [barrier](couchbase::operations::user_get_all_response&& resp) mutable { barrier->set_value(resp); });
4089
- auto resp = f.get();
3984
+ auto resp = cb_wait_for_future(f);
4090
3985
  if (resp.ctx.ec) {
4091
- exc = cb__map_error_code(resp.ctx, "unable to fetch users");
3986
+ exc = cb_map_error_code(resp.ctx, "unable to fetch users");
4092
3987
  break;
4093
3988
  }
4094
3989
 
4095
3990
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.users.size()));
4096
3991
  for (const auto& entry : resp.users) {
4097
3992
  VALUE user = rb_hash_new();
4098
- cb__extract_user(entry, user);
3993
+ cb_extract_user(entry, user);
4099
3994
  rb_ary_push(res, user);
4100
3995
  }
4101
3996
  return res;
@@ -4121,7 +4016,7 @@ cb_Backend_user_get(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4121
4016
  VALUE exc = Qnil;
4122
4017
  do {
4123
4018
  couchbase::operations::user_get_request req{};
4124
- exc = cb__extract_timeout(req, timeout);
4019
+ exc = cb_extract_timeout(req, timeout);
4125
4020
  if (!NIL_P(exc)) {
4126
4021
  break;
4127
4022
  }
@@ -4138,14 +4033,14 @@ cb_Backend_user_get(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4138
4033
  auto f = barrier->get_future();
4139
4034
  backend->cluster->execute_http(req,
4140
4035
  [barrier](couchbase::operations::user_get_response&& resp) mutable { barrier->set_value(resp); });
4141
- auto resp = f.get();
4036
+ auto resp = cb_wait_for_future(f);
4142
4037
  if (resp.ctx.ec) {
4143
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4038
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4144
4039
  break;
4145
4040
  }
4146
4041
 
4147
4042
  VALUE res = rb_hash_new();
4148
- cb__extract_user(resp.user, res);
4043
+ cb_extract_user(resp.user, res);
4149
4044
  return res;
4150
4045
  } while (false);
4151
4046
  rb_exc_raise(exc);
@@ -4169,7 +4064,7 @@ cb_Backend_user_drop(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4169
4064
  VALUE exc = Qnil;
4170
4065
  do {
4171
4066
  couchbase::operations::user_drop_request req{};
4172
- exc = cb__extract_timeout(req, timeout);
4067
+ exc = cb_extract_timeout(req, timeout);
4173
4068
  if (!NIL_P(exc)) {
4174
4069
  break;
4175
4070
  }
@@ -4186,9 +4081,9 @@ cb_Backend_user_drop(VALUE self, VALUE domain, VALUE username, VALUE timeout)
4186
4081
  auto f = barrier->get_future();
4187
4082
  backend->cluster->execute_http(req,
4188
4083
  [barrier](couchbase::operations::user_drop_response&& resp) mutable { barrier->set_value(resp); });
4189
- auto resp = f.get();
4084
+ auto resp = cb_wait_for_future(f);
4190
4085
  if (resp.ctx.ec) {
4191
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4086
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to fetch user "{}")", req.username));
4192
4087
  break;
4193
4088
  }
4194
4089
 
@@ -4215,7 +4110,7 @@ cb_Backend_user_upsert(VALUE self, VALUE domain, VALUE user, VALUE timeout)
4215
4110
  VALUE exc = Qnil;
4216
4111
  do {
4217
4112
  couchbase::operations::user_upsert_request req{};
4218
- exc = cb__extract_timeout(req, timeout);
4113
+ exc = cb_extract_timeout(req, timeout);
4219
4114
  if (!NIL_P(exc)) {
4220
4115
  break;
4221
4116
  }
@@ -4282,10 +4177,10 @@ cb_Backend_user_upsert(VALUE self, VALUE domain, VALUE user, VALUE timeout)
4282
4177
  auto f = barrier->get_future();
4283
4178
  backend->cluster->execute_http(req,
4284
4179
  [barrier](couchbase::operations::user_upsert_response&& resp) mutable { barrier->set_value(resp); });
4285
- auto resp = f.get();
4180
+ auto resp = cb_wait_for_future(f);
4286
4181
  if (resp.ctx.ec) {
4287
- exc = cb__map_error_code(resp.ctx,
4288
- fmt::format(R"(unable to upsert user "{}" ({}))", req.user.username, fmt::join(resp.errors, ", ")));
4182
+ exc = cb_map_error_code(resp.ctx,
4183
+ fmt::format(R"(unable to upsert user "{}" ({}))", req.user.username, fmt::join(resp.errors, ", ")));
4289
4184
  break;
4290
4185
  }
4291
4186
 
@@ -4296,34 +4191,27 @@ cb_Backend_user_upsert(VALUE self, VALUE domain, VALUE user, VALUE timeout)
4296
4191
  }
4297
4192
 
4298
4193
  static void
4299
- cb__extract_group(const couchbase::operations::rbac::group& entry, VALUE group)
4194
+ cb_extract_group(const couchbase::operations::rbac::group& entry, VALUE group)
4300
4195
  {
4301
- rb_hash_aset(group, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
4196
+ rb_hash_aset(group, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
4302
4197
  if (entry.description) {
4303
- rb_hash_aset(group,
4304
- rb_id2sym(rb_intern("description")),
4305
- rb_external_str_new(entry.description->data(), static_cast<long>(entry.description->size())));
4198
+ rb_hash_aset(group, rb_id2sym(rb_intern("description")), cb_str_new(entry.description.value()));
4306
4199
  }
4307
4200
  if (entry.ldap_group_reference) {
4308
- rb_hash_aset(group,
4309
- rb_id2sym(rb_intern("ldap_group_reference")),
4310
- rb_external_str_new(entry.ldap_group_reference->data(), static_cast<long>(entry.ldap_group_reference->size())));
4201
+ rb_hash_aset(group, rb_id2sym(rb_intern("ldap_group_reference")), cb_str_new(entry.ldap_group_reference.value()));
4311
4202
  }
4312
4203
  VALUE roles = rb_ary_new_capa(static_cast<long>(entry.roles.size()));
4313
4204
  for (const auto& er : entry.roles) {
4314
4205
  VALUE role = rb_hash_new();
4315
- rb_hash_aset(role, rb_id2sym(rb_intern("name")), rb_external_str_new(er.name.data(), static_cast<long>(er.name.size())));
4206
+ rb_hash_aset(role, rb_id2sym(rb_intern("name")), cb_str_new(er.name));
4316
4207
  if (er.bucket) {
4317
- rb_hash_aset(
4318
- role, rb_id2sym(rb_intern("bucket")), rb_external_str_new(er.bucket->data(), static_cast<long>(er.bucket->size())));
4208
+ rb_hash_aset(role, rb_id2sym(rb_intern("bucket")), cb_str_new(er.bucket.value()));
4319
4209
  }
4320
4210
  if (er.scope) {
4321
- rb_hash_aset(role, rb_id2sym(rb_intern("scope")), rb_external_str_new(er.scope->data(), static_cast<long>(er.scope->size())));
4211
+ rb_hash_aset(role, rb_id2sym(rb_intern("scope")), cb_str_new(er.scope.value()));
4322
4212
  }
4323
4213
  if (er.collection) {
4324
- rb_hash_aset(role,
4325
- rb_id2sym(rb_intern("collection")),
4326
- rb_external_str_new(er.collection->data(), static_cast<long>(er.collection->size())));
4214
+ rb_hash_aset(role, rb_id2sym(rb_intern("collection")), cb_str_new(er.collection.value()));
4327
4215
  }
4328
4216
  rb_ary_push(roles, role);
4329
4217
  }
@@ -4344,7 +4232,7 @@ cb_Backend_group_get_all(VALUE self, VALUE timeout)
4344
4232
  VALUE exc = Qnil;
4345
4233
  do {
4346
4234
  couchbase::operations::group_get_all_request req{};
4347
- exc = cb__extract_timeout(req, timeout);
4235
+ exc = cb_extract_timeout(req, timeout);
4348
4236
  if (!NIL_P(exc)) {
4349
4237
  break;
4350
4238
  }
@@ -4352,16 +4240,16 @@ cb_Backend_group_get_all(VALUE self, VALUE timeout)
4352
4240
  auto f = barrier->get_future();
4353
4241
  backend->cluster->execute_http(
4354
4242
  req, [barrier](couchbase::operations::group_get_all_response&& resp) mutable { barrier->set_value(resp); });
4355
- auto resp = f.get();
4243
+ auto resp = cb_wait_for_future(f);
4356
4244
  if (resp.ctx.ec) {
4357
- exc = cb__map_error_code(resp.ctx, "unable to fetch groups");
4245
+ exc = cb_map_error_code(resp.ctx, "unable to fetch groups");
4358
4246
  break;
4359
4247
  }
4360
4248
 
4361
4249
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.groups.size()));
4362
4250
  for (const auto& entry : resp.groups) {
4363
4251
  VALUE group = rb_hash_new();
4364
- cb__extract_group(entry, group);
4252
+ cb_extract_group(entry, group);
4365
4253
  rb_ary_push(res, group);
4366
4254
  }
4367
4255
  return res;
@@ -4386,7 +4274,7 @@ cb_Backend_group_get(VALUE self, VALUE name, VALUE timeout)
4386
4274
  VALUE exc = Qnil;
4387
4275
  do {
4388
4276
  couchbase::operations::group_get_request req{};
4389
- exc = cb__extract_timeout(req, timeout);
4277
+ exc = cb_extract_timeout(req, timeout);
4390
4278
  if (!NIL_P(exc)) {
4391
4279
  break;
4392
4280
  }
@@ -4395,14 +4283,14 @@ cb_Backend_group_get(VALUE self, VALUE name, VALUE timeout)
4395
4283
  auto f = barrier->get_future();
4396
4284
  backend->cluster->execute_http(req,
4397
4285
  [barrier](couchbase::operations::group_get_response&& resp) mutable { barrier->set_value(resp); });
4398
- auto resp = f.get();
4286
+ auto resp = cb_wait_for_future(f);
4399
4287
  if (resp.ctx.ec) {
4400
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to fetch group "{}")", req.name));
4288
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to fetch group "{}")", req.name));
4401
4289
  break;
4402
4290
  }
4403
4291
 
4404
4292
  VALUE res = rb_hash_new();
4405
- cb__extract_group(resp.group, res);
4293
+ cb_extract_group(resp.group, res);
4406
4294
  return res;
4407
4295
  } while (false);
4408
4296
  rb_exc_raise(exc);
@@ -4425,7 +4313,7 @@ cb_Backend_group_drop(VALUE self, VALUE name, VALUE timeout)
4425
4313
  VALUE exc = Qnil;
4426
4314
  do {
4427
4315
  couchbase::operations::group_drop_request req{};
4428
- exc = cb__extract_timeout(req, timeout);
4316
+ exc = cb_extract_timeout(req, timeout);
4429
4317
  if (!NIL_P(exc)) {
4430
4318
  break;
4431
4319
  }
@@ -4434,9 +4322,9 @@ cb_Backend_group_drop(VALUE self, VALUE name, VALUE timeout)
4434
4322
  auto f = barrier->get_future();
4435
4323
  backend->cluster->execute_http(req,
4436
4324
  [barrier](couchbase::operations::group_drop_response&& resp) mutable { barrier->set_value(resp); });
4437
- auto resp = f.get();
4325
+ auto resp = cb_wait_for_future(f);
4438
4326
  if (resp.ctx.ec) {
4439
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to drop group "{}")", req.name));
4327
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to drop group "{}")", req.name));
4440
4328
  break;
4441
4329
  }
4442
4330
 
@@ -4462,7 +4350,7 @@ cb_Backend_group_upsert(VALUE self, VALUE group, VALUE timeout)
4462
4350
  VALUE exc = Qnil;
4463
4351
  do {
4464
4352
  couchbase::operations::group_upsert_request req{};
4465
- exc = cb__extract_timeout(req, timeout);
4353
+ exc = cb_extract_timeout(req, timeout);
4466
4354
  if (!NIL_P(exc)) {
4467
4355
  break;
4468
4356
  }
@@ -4510,10 +4398,10 @@ cb_Backend_group_upsert(VALUE self, VALUE group, VALUE timeout)
4510
4398
  auto f = barrier->get_future();
4511
4399
  backend->cluster->execute_http(
4512
4400
  req, [barrier](couchbase::operations::group_upsert_response&& resp) mutable { barrier->set_value(resp); });
4513
- auto resp = f.get();
4401
+ auto resp = cb_wait_for_future(f);
4514
4402
  if (resp.ctx.ec) {
4515
- exc = cb__map_error_code(resp.ctx,
4516
- fmt::format(R"(unable to upsert group "{}" ({}))", req.group.name, fmt::join(resp.errors, ", ")));
4403
+ exc =
4404
+ cb_map_error_code(resp.ctx, fmt::format(R"(unable to upsert group "{}" ({}))", req.group.name, fmt::join(resp.errors, ", ")));
4517
4405
  break;
4518
4406
  }
4519
4407
 
@@ -4541,9 +4429,9 @@ cb_Backend_cluster_enable_developer_preview(VALUE self)
4541
4429
  auto f = barrier->get_future();
4542
4430
  backend->cluster->execute_http(
4543
4431
  req, [barrier](couchbase::operations::cluster_developer_preview_enable_response&& resp) mutable { barrier->set_value(resp); });
4544
- auto resp = f.get();
4432
+ auto resp = cb_wait_for_future(f);
4545
4433
  if (resp.ctx.ec) {
4546
- exc = cb__map_error_code(resp.ctx, "unable to enable developer preview for this cluster");
4434
+ exc = cb_map_error_code(resp.ctx, "unable to enable developer preview for this cluster");
4547
4435
  break;
4548
4436
  }
4549
4437
  spdlog::critical(
@@ -4571,7 +4459,7 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4571
4459
  VALUE exc = Qnil;
4572
4460
  do {
4573
4461
  couchbase::operations::scope_get_all_request req{};
4574
- exc = cb__extract_timeout(req, timeout);
4462
+ exc = cb_extract_timeout(req, timeout);
4575
4463
  if (!NIL_P(exc)) {
4576
4464
  break;
4577
4465
  }
@@ -4580,9 +4468,9 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4580
4468
  auto f = barrier->get_future();
4581
4469
  backend->cluster->execute_http(
4582
4470
  req, [barrier](couchbase::operations::scope_get_all_response&& resp) mutable { barrier->set_value(resp); });
4583
- auto resp = f.get();
4471
+ auto resp = cb_wait_for_future(f);
4584
4472
  if (resp.ctx.ec) {
4585
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get list of the scopes of the bucket \"{}\"", req.bucket_name));
4473
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get list of the scopes of the bucket \"{}\"", req.bucket_name));
4586
4474
  break;
4587
4475
  }
4588
4476
 
@@ -4592,13 +4480,12 @@ cb_Backend_scope_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4592
4480
  for (const auto& s : resp.manifest.scopes) {
4593
4481
  VALUE scope = rb_hash_new();
4594
4482
  rb_hash_aset(scope, rb_id2sym(rb_intern("uid")), ULL2NUM(s.uid));
4595
- rb_hash_aset(scope, rb_id2sym(rb_intern("name")), rb_external_str_new(s.name.data(), static_cast<long>(s.name.size())));
4483
+ rb_hash_aset(scope, rb_id2sym(rb_intern("name")), cb_str_new(s.name));
4596
4484
  VALUE collections = rb_ary_new_capa(static_cast<long>(s.collections.size()));
4597
4485
  for (const auto& c : s.collections) {
4598
4486
  VALUE collection = rb_hash_new();
4599
4487
  rb_hash_aset(collection, rb_id2sym(rb_intern("uid")), ULL2NUM(c.uid));
4600
- rb_hash_aset(
4601
- collection, rb_id2sym(rb_intern("name")), rb_external_str_new(c.name.data(), static_cast<long>(c.name.size())));
4488
+ rb_hash_aset(collection, rb_id2sym(rb_intern("name")), cb_str_new(c.name));
4602
4489
  rb_ary_push(collections, collection);
4603
4490
  }
4604
4491
  rb_hash_aset(scope, rb_id2sym(rb_intern("collections")), collections);
@@ -4628,7 +4515,7 @@ cb_Backend_collections_manifest_get(VALUE self, VALUE bucket_name, VALUE timeout
4628
4515
  VALUE exc = Qnil;
4629
4516
  do {
4630
4517
  couchbase::operations::collections_manifest_get_request req{};
4631
- exc = cb__extract_timeout(req, timeout);
4518
+ exc = cb_extract_timeout(req, timeout);
4632
4519
  if (!NIL_P(exc)) {
4633
4520
  break;
4634
4521
  }
@@ -4637,9 +4524,9 @@ cb_Backend_collections_manifest_get(VALUE self, VALUE bucket_name, VALUE timeout
4637
4524
  auto f = barrier->get_future();
4638
4525
  backend->cluster->execute(
4639
4526
  req, [barrier](couchbase::operations::collections_manifest_get_response&& resp) mutable { barrier->set_value(resp); });
4640
- auto resp = f.get();
4527
+ auto resp = cb_wait_for_future(f);
4641
4528
  if (resp.ctx.ec) {
4642
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get collections manifest of the bucket \"{}\"", req.id.bucket));
4529
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get collections manifest of the bucket \"{}\"", req.id.bucket));
4643
4530
  break;
4644
4531
  }
4645
4532
 
@@ -4649,13 +4536,12 @@ cb_Backend_collections_manifest_get(VALUE self, VALUE bucket_name, VALUE timeout
4649
4536
  for (const auto& s : resp.manifest.scopes) {
4650
4537
  VALUE scope = rb_hash_new();
4651
4538
  rb_hash_aset(scope, rb_id2sym(rb_intern("uid")), ULL2NUM(s.uid));
4652
- rb_hash_aset(scope, rb_id2sym(rb_intern("name")), rb_external_str_new(s.name.data(), static_cast<long>(s.name.size())));
4539
+ rb_hash_aset(scope, rb_id2sym(rb_intern("name")), cb_str_new(s.name));
4653
4540
  VALUE collections = rb_ary_new_capa(static_cast<long>(s.collections.size()));
4654
4541
  for (const auto& c : s.collections) {
4655
4542
  VALUE collection = rb_hash_new();
4656
4543
  rb_hash_aset(collection, rb_id2sym(rb_intern("uid")), ULL2NUM(c.uid));
4657
- rb_hash_aset(
4658
- collection, rb_id2sym(rb_intern("name")), rb_external_str_new(c.name.data(), static_cast<long>(c.name.size())));
4544
+ rb_hash_aset(collection, rb_id2sym(rb_intern("name")), cb_str_new(c.name));
4659
4545
  rb_ary_push(collections, collection);
4660
4546
  }
4661
4547
  rb_hash_aset(scope, rb_id2sym(rb_intern("collections")), collections);
@@ -4686,7 +4572,7 @@ cb_Backend_scope_create(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE t
4686
4572
  VALUE exc = Qnil;
4687
4573
  do {
4688
4574
  couchbase::operations::scope_create_request req{};
4689
- exc = cb__extract_timeout(req, timeout);
4575
+ exc = cb_extract_timeout(req, timeout);
4690
4576
  if (!NIL_P(exc)) {
4691
4577
  break;
4692
4578
  }
@@ -4696,10 +4582,10 @@ cb_Backend_scope_create(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE t
4696
4582
  auto f = barrier->get_future();
4697
4583
  backend->cluster->execute_http(
4698
4584
  req, [barrier](couchbase::operations::scope_create_response&& resp) mutable { barrier->set_value(resp); });
4699
- auto resp = f.get();
4585
+ auto resp = cb_wait_for_future(f);
4700
4586
  if (resp.ctx.ec) {
4701
- exc = cb__map_error_code(resp.ctx,
4702
- fmt::format(R"(unable to create the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4587
+ exc = cb_map_error_code(resp.ctx,
4588
+ fmt::format(R"(unable to create the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4703
4589
  break;
4704
4590
  }
4705
4591
  return ULL2NUM(resp.uid);
@@ -4725,7 +4611,7 @@ cb_Backend_scope_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE tim
4725
4611
  VALUE exc = Qnil;
4726
4612
  do {
4727
4613
  couchbase::operations::scope_drop_request req{};
4728
- exc = cb__extract_timeout(req, timeout);
4614
+ exc = cb_extract_timeout(req, timeout);
4729
4615
  if (!NIL_P(exc)) {
4730
4616
  break;
4731
4617
  }
@@ -4735,10 +4621,10 @@ cb_Backend_scope_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALUE tim
4735
4621
  auto f = barrier->get_future();
4736
4622
  backend->cluster->execute_http(req,
4737
4623
  [barrier](couchbase::operations::scope_drop_response&& resp) mutable { barrier->set_value(resp); });
4738
- auto resp = f.get();
4624
+ auto resp = cb_wait_for_future(f);
4739
4625
  if (resp.ctx.ec) {
4740
- exc = cb__map_error_code(resp.ctx,
4741
- fmt::format(R"(unable to drop the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4626
+ exc = cb_map_error_code(resp.ctx,
4627
+ fmt::format(R"(unable to drop the scope "{}" on the bucket "{}")", req.scope_name, req.bucket_name));
4742
4628
  break;
4743
4629
  }
4744
4630
  return ULL2NUM(resp.uid);
@@ -4765,7 +4651,7 @@ cb_Backend_collection_create(VALUE self, VALUE bucket_name, VALUE scope_name, VA
4765
4651
  VALUE exc = Qnil;
4766
4652
  do {
4767
4653
  couchbase::operations::collection_create_request req{};
4768
- exc = cb__extract_timeout(req, timeout);
4654
+ exc = cb_extract_timeout(req, timeout);
4769
4655
  if (!NIL_P(exc)) {
4770
4656
  break;
4771
4657
  }
@@ -4781,9 +4667,9 @@ cb_Backend_collection_create(VALUE self, VALUE bucket_name, VALUE scope_name, VA
4781
4667
  auto f = barrier->get_future();
4782
4668
  backend->cluster->execute_http(
4783
4669
  req, [barrier](couchbase::operations::collection_create_response&& resp) mutable { barrier->set_value(resp); });
4784
- auto resp = f.get();
4670
+ auto resp = cb_wait_for_future(f);
4785
4671
  if (resp.ctx.ec) {
4786
- exc = cb__map_error_code(
4672
+ exc = cb_map_error_code(
4787
4673
  resp.ctx,
4788
4674
  fmt::format(
4789
4675
  R"(unable create the collection "{}.{}" on the bucket "{}")", req.scope_name, req.collection_name, req.bucket_name));
@@ -4813,7 +4699,7 @@ cb_Backend_collection_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALU
4813
4699
  VALUE exc = Qnil;
4814
4700
  do {
4815
4701
  couchbase::operations::collection_drop_request req{};
4816
- exc = cb__extract_timeout(req, timeout);
4702
+ exc = cb_extract_timeout(req, timeout);
4817
4703
  if (!NIL_P(exc)) {
4818
4704
  break;
4819
4705
  }
@@ -4825,9 +4711,9 @@ cb_Backend_collection_drop(VALUE self, VALUE bucket_name, VALUE scope_name, VALU
4825
4711
  auto f = barrier->get_future();
4826
4712
  backend->cluster->execute_http(
4827
4713
  req, [barrier](couchbase::operations::collection_drop_response&& resp) mutable { barrier->set_value(resp); });
4828
- auto resp = f.get();
4714
+ auto resp = cb_wait_for_future(f);
4829
4715
  if (resp.ctx.ec) {
4830
- exc = cb__map_error_code(
4716
+ exc = cb_map_error_code(
4831
4717
  resp.ctx,
4832
4718
  fmt::format(
4833
4719
  R"(unable to drop the collection "{}.{}" on the bucket "{}")", req.scope_name, req.collection_name, req.bucket_name));
@@ -4855,7 +4741,7 @@ cb_Backend_query_index_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4855
4741
  VALUE exc = Qnil;
4856
4742
  do {
4857
4743
  couchbase::operations::query_index_get_all_request req{};
4858
- exc = cb__extract_timeout(req, timeout);
4744
+ exc = cb_extract_timeout(req, timeout);
4859
4745
  if (!NIL_P(exc)) {
4860
4746
  break;
4861
4747
  }
@@ -4864,50 +4750,38 @@ cb_Backend_query_index_get_all(VALUE self, VALUE bucket_name, VALUE timeout)
4864
4750
  auto f = barrier->get_future();
4865
4751
  backend->cluster->execute_http(
4866
4752
  req, [barrier](couchbase::operations::query_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
4867
- auto resp = f.get();
4753
+ auto resp = cb_wait_for_future(f);
4868
4754
  if (resp.ctx.ec) {
4869
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get list of the indexes of the bucket \"{}\"", req.bucket_name));
4755
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get list of the indexes of the bucket \"{}\"", req.bucket_name));
4870
4756
  break;
4871
4757
  }
4872
4758
 
4873
4759
  VALUE res = rb_hash_new();
4874
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
4760
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
4875
4761
  VALUE indexes = rb_ary_new_capa(static_cast<long>(resp.indexes.size()));
4876
4762
  for (const auto& idx : resp.indexes) {
4877
4763
  VALUE index = rb_hash_new();
4878
- rb_hash_aset(index, rb_id2sym(rb_intern("id")), rb_external_str_new(idx.id.data(), static_cast<long>(idx.id.size())));
4879
- rb_hash_aset(index, rb_id2sym(rb_intern("state")), rb_external_str_new(idx.state.data(), static_cast<long>(idx.state.size())));
4880
- rb_hash_aset(index, rb_id2sym(rb_intern("name")), rb_external_str_new(idx.name.data(), static_cast<long>(idx.name.size())));
4881
- rb_hash_aset(index,
4882
- rb_id2sym(rb_intern("datastore_id")),
4883
- rb_external_str_new(idx.datastore_id.data(), static_cast<long>(idx.datastore_id.size())));
4884
- rb_hash_aset(index,
4885
- rb_id2sym(rb_intern("keyspace_id")),
4886
- rb_external_str_new(idx.keyspace_id.data(), static_cast<long>(idx.keyspace_id.size())));
4887
- rb_hash_aset(index,
4888
- rb_id2sym(rb_intern("namespace_id")),
4889
- rb_external_str_new(idx.namespace_id.data(), static_cast<long>(idx.namespace_id.size())));
4890
- rb_hash_aset(index, rb_id2sym(rb_intern("type")), rb_external_str_new(idx.type.data(), static_cast<long>(idx.type.size())));
4764
+ rb_hash_aset(index, rb_id2sym(rb_intern("id")), cb_str_new(idx.id));
4765
+ rb_hash_aset(index, rb_id2sym(rb_intern("state")), cb_str_new(idx.state));
4766
+ rb_hash_aset(index, rb_id2sym(rb_intern("name")), cb_str_new(idx.name));
4767
+ rb_hash_aset(index, rb_id2sym(rb_intern("datastore_id")), cb_str_new(idx.datastore_id));
4768
+ rb_hash_aset(index, rb_id2sym(rb_intern("keyspace_id")), cb_str_new(idx.keyspace_id));
4769
+ rb_hash_aset(index, rb_id2sym(rb_intern("namespace_id")), cb_str_new(idx.namespace_id));
4770
+ rb_hash_aset(index, rb_id2sym(rb_intern("type")), cb_str_new(idx.type));
4891
4771
  rb_hash_aset(index, rb_id2sym(rb_intern("is_primary")), idx.is_primary ? Qtrue : Qfalse);
4892
4772
  VALUE index_key = rb_ary_new_capa(static_cast<long>(idx.index_key.size()));
4893
4773
  for (const auto& key : idx.index_key) {
4894
- rb_ary_push(index_key, rb_external_str_new(key.data(), static_cast<long>(key.size())));
4774
+ rb_ary_push(index_key, cb_str_new(key));
4895
4775
  }
4896
4776
  rb_hash_aset(index, rb_id2sym(rb_intern("index_key")), index_key);
4897
4777
  if (idx.scope_id) {
4898
- rb_hash_aset(index,
4899
- rb_id2sym(rb_intern("scope_id")),
4900
- rb_external_str_new(idx.scope_id->data(), static_cast<long>(idx.scope_id->size())));
4778
+ rb_hash_aset(index, rb_id2sym(rb_intern("scope_id")), cb_str_new(idx.scope_id.value()));
4901
4779
  }
4902
4780
  if (idx.bucket_id) {
4903
- rb_hash_aset(index,
4904
- rb_id2sym(rb_intern("bucket_id")),
4905
- rb_external_str_new(idx.bucket_id->data(), static_cast<long>(idx.bucket_id->size())));
4781
+ rb_hash_aset(index, rb_id2sym(rb_intern("bucket_id")), cb_str_new(idx.bucket_id.value()));
4906
4782
  }
4907
4783
  if (idx.condition) {
4908
- rb_hash_aset(index,
4909
- rb_id2sym(rb_intern("condition")),
4910
- rb_external_str_new(idx.condition->data(), static_cast<long>(idx.condition->size())));
4784
+ rb_hash_aset(index, rb_id2sym(rb_intern("condition")), cb_str_new(idx.condition.value()));
4911
4785
  }
4912
4786
  rb_ary_push(indexes, index);
4913
4787
  }
@@ -4938,7 +4812,7 @@ cb_Backend_query_index_create(VALUE self, VALUE bucket_name, VALUE index_name, V
4938
4812
  VALUE exc = Qnil;
4939
4813
  do {
4940
4814
  couchbase::operations::query_index_create_request req{};
4941
- exc = cb__extract_timeout(req, timeout);
4815
+ exc = cb_extract_timeout(req, timeout);
4942
4816
  if (!NIL_P(exc)) {
4943
4817
  break;
4944
4818
  }
@@ -4987,31 +4861,30 @@ cb_Backend_query_index_create(VALUE self, VALUE bucket_name, VALUE index_name, V
4987
4861
  auto f = barrier->get_future();
4988
4862
  backend->cluster->execute_http(
4989
4863
  req, [barrier](couchbase::operations::query_index_create_response&& resp) mutable { barrier->set_value(resp); });
4990
- auto resp = f.get();
4864
+ auto resp = cb_wait_for_future(f);
4991
4865
  if (resp.ctx.ec) {
4992
4866
  if (!resp.errors.empty()) {
4993
4867
  const auto& first_error = resp.errors.front();
4994
- exc = cb__map_error_code(resp.ctx,
4995
- fmt::format(R"(unable to create index "{}" on the bucket "{}" ({}: {}))",
4996
- req.index_name,
4997
- req.bucket_name,
4998
- first_error.code,
4999
- first_error.message));
4868
+ exc = cb_map_error_code(resp.ctx,
4869
+ fmt::format(R"(unable to create index "{}" on the bucket "{}" ({}: {}))",
4870
+ req.index_name,
4871
+ req.bucket_name,
4872
+ first_error.code,
4873
+ first_error.message));
5000
4874
  } else {
5001
- exc = cb__map_error_code(resp.ctx,
5002
- fmt::format(R"(unable to create index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
4875
+ exc = cb_map_error_code(resp.ctx,
4876
+ fmt::format(R"(unable to create index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
5003
4877
  }
5004
4878
  break;
5005
4879
  }
5006
4880
  VALUE res = rb_hash_new();
5007
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
4881
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5008
4882
  if (!resp.errors.empty()) {
5009
4883
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5010
4884
  for (const auto& err : resp.errors) {
5011
4885
  VALUE error = rb_hash_new();
5012
4886
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5013
- rb_hash_aset(
5014
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
4887
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5015
4888
  rb_ary_push(errors, error);
5016
4889
  }
5017
4890
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5039,7 +4912,7 @@ cb_Backend_query_index_drop(VALUE self, VALUE bucket_name, VALUE index_name, VAL
5039
4912
  VALUE exc = Qnil;
5040
4913
  do {
5041
4914
  couchbase::operations::query_index_drop_request req{};
5042
- exc = cb__extract_timeout(req, timeout);
4915
+ exc = cb_extract_timeout(req, timeout);
5043
4916
  if (!NIL_P(exc)) {
5044
4917
  break;
5045
4918
  }
@@ -5067,31 +4940,30 @@ cb_Backend_query_index_drop(VALUE self, VALUE bucket_name, VALUE index_name, VAL
5067
4940
  auto f = barrier->get_future();
5068
4941
  backend->cluster->execute_http(
5069
4942
  req, [barrier](couchbase::operations::query_index_drop_response&& resp) mutable { barrier->set_value(resp); });
5070
- auto resp = f.get();
4943
+ auto resp = cb_wait_for_future(f);
5071
4944
  if (resp.ctx.ec) {
5072
4945
  if (!resp.errors.empty()) {
5073
4946
  const auto& first_error = resp.errors.front();
5074
- exc = cb__map_error_code(resp.ctx,
5075
- fmt::format(R"(unable to drop index "{}" on the bucket "{}" ({}: {}))",
5076
- req.index_name,
5077
- req.bucket_name,
5078
- first_error.code,
5079
- first_error.message));
4947
+ exc = cb_map_error_code(resp.ctx,
4948
+ fmt::format(R"(unable to drop index "{}" on the bucket "{}" ({}: {}))",
4949
+ req.index_name,
4950
+ req.bucket_name,
4951
+ first_error.code,
4952
+ first_error.message));
5080
4953
  } else {
5081
- exc = cb__map_error_code(resp.ctx,
5082
- fmt::format(R"(unable to drop index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
4954
+ exc = cb_map_error_code(resp.ctx,
4955
+ fmt::format(R"(unable to drop index "{}" on the bucket "{}")", req.index_name, req.bucket_name));
5083
4956
  }
5084
4957
  break;
5085
4958
  }
5086
4959
  VALUE res = rb_hash_new();
5087
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
4960
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5088
4961
  if (!resp.errors.empty()) {
5089
4962
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5090
4963
  for (const auto& err : resp.errors) {
5091
4964
  VALUE error = rb_hash_new();
5092
4965
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5093
- rb_hash_aset(
5094
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
4966
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5095
4967
  rb_ary_push(errors, error);
5096
4968
  }
5097
4969
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5121,7 +4993,7 @@ cb_Backend_query_index_create_primary(VALUE self, VALUE bucket_name, VALUE optio
5121
4993
  VALUE exc = Qnil;
5122
4994
  do {
5123
4995
  couchbase::operations::query_index_create_request req{};
5124
- exc = cb__extract_timeout(req, timeout);
4996
+ exc = cb_extract_timeout(req, timeout);
5125
4997
  if (!NIL_P(exc)) {
5126
4998
  break;
5127
4999
  }
@@ -5163,30 +5035,29 @@ cb_Backend_query_index_create_primary(VALUE self, VALUE bucket_name, VALUE optio
5163
5035
  auto f = barrier->get_future();
5164
5036
  backend->cluster->execute_http(
5165
5037
  req, [barrier](couchbase::operations::query_index_create_response&& resp) mutable { barrier->set_value(resp); });
5166
- auto resp = f.get();
5038
+ auto resp = cb_wait_for_future(f);
5167
5039
  if (resp.ctx.ec) {
5168
5040
  if (!resp.errors.empty()) {
5169
5041
  const auto& first_error = resp.errors.front();
5170
- exc = cb__map_error_code(resp.ctx,
5171
- fmt::format(R"(unable to create primary index on the bucket "{}" ({}: {}))",
5172
- req.bucket_name,
5173
- first_error.code,
5174
- first_error.message));
5042
+ exc = cb_map_error_code(resp.ctx,
5043
+ fmt::format(R"(unable to create primary index on the bucket "{}" ({}: {}))",
5044
+ req.bucket_name,
5045
+ first_error.code,
5046
+ first_error.message));
5175
5047
  } else {
5176
- exc = cb__map_error_code(
5048
+ exc = cb_map_error_code(
5177
5049
  resp.ctx, fmt::format(R"(unable to create primary index on the bucket "{}")", req.index_name, req.bucket_name));
5178
5050
  }
5179
5051
  break;
5180
5052
  }
5181
5053
  VALUE res = rb_hash_new();
5182
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5054
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5183
5055
  if (!resp.errors.empty()) {
5184
5056
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5185
5057
  for (const auto& err : resp.errors) {
5186
5058
  VALUE error = rb_hash_new();
5187
5059
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5188
- rb_hash_aset(
5189
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
5060
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5190
5061
  rb_ary_push(errors, error);
5191
5062
  }
5192
5063
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5213,7 +5084,7 @@ cb_Backend_query_index_drop_primary(VALUE self, VALUE bucket_name, VALUE options
5213
5084
  VALUE exc = Qnil;
5214
5085
  do {
5215
5086
  couchbase::operations::query_index_drop_request req{};
5216
- exc = cb__extract_timeout(req, timeout);
5087
+ exc = cb_extract_timeout(req, timeout);
5217
5088
  if (!NIL_P(exc)) {
5218
5089
  break;
5219
5090
  }
@@ -5247,28 +5118,27 @@ cb_Backend_query_index_drop_primary(VALUE self, VALUE bucket_name, VALUE options
5247
5118
  auto f = barrier->get_future();
5248
5119
  backend->cluster->execute_http(
5249
5120
  req, [barrier](couchbase::operations::query_index_drop_response&& resp) mutable { barrier->set_value(resp); });
5250
- auto resp = f.get();
5121
+ auto resp = cb_wait_for_future(f);
5251
5122
  if (resp.ctx.ec) {
5252
5123
  if (!resp.errors.empty()) {
5253
5124
  const auto& first_error = resp.errors.front();
5254
- exc = cb__map_error_code(
5125
+ exc = cb_map_error_code(
5255
5126
  resp.ctx,
5256
5127
  fmt::format(
5257
5128
  R"(unable to drop primary index on the bucket "{}" ({}: {}))", req.bucket_name, first_error.code, first_error.message));
5258
5129
  } else {
5259
- exc = cb__map_error_code(resp.ctx, fmt::format(R"(unable to drop primary index on the bucket "{}")", req.bucket_name));
5130
+ exc = cb_map_error_code(resp.ctx, fmt::format(R"(unable to drop primary index on the bucket "{}")", req.bucket_name));
5260
5131
  }
5261
5132
  break;
5262
5133
  }
5263
5134
  VALUE res = rb_hash_new();
5264
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5135
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5265
5136
  if (!resp.errors.empty()) {
5266
5137
  VALUE errors = rb_ary_new_capa(static_cast<long>(resp.errors.size()));
5267
5138
  for (const auto& err : resp.errors) {
5268
5139
  VALUE error = rb_hash_new();
5269
5140
  rb_hash_aset(error, rb_id2sym(rb_intern("code")), ULL2NUM(err.code));
5270
- rb_hash_aset(
5271
- error, rb_id2sym(rb_intern("message")), rb_external_str_new(err.message.data(), static_cast<long>(err.message.size())));
5141
+ rb_hash_aset(error, rb_id2sym(rb_intern("message")), cb_str_new(err.message));
5272
5142
  rb_ary_push(errors, error);
5273
5143
  }
5274
5144
  rb_hash_aset(res, rb_id2sym(rb_intern("errors")), errors);
@@ -5295,7 +5165,7 @@ cb_Backend_query_index_build_deferred(VALUE self, VALUE bucket_name, VALUE timeo
5295
5165
  VALUE exc = Qnil;
5296
5166
  do {
5297
5167
  couchbase::operations::query_index_build_deferred_request req{};
5298
- exc = cb__extract_timeout(req, timeout);
5168
+ exc = cb_extract_timeout(req, timeout);
5299
5169
  if (!NIL_P(exc)) {
5300
5170
  break;
5301
5171
  }
@@ -5304,18 +5174,18 @@ cb_Backend_query_index_build_deferred(VALUE self, VALUE bucket_name, VALUE timeo
5304
5174
  auto f = barrier->get_future();
5305
5175
  backend->cluster->execute_http(
5306
5176
  req, [barrier](couchbase::operations::query_index_build_deferred_response&& resp) mutable { barrier->set_value(resp); });
5307
- auto resp = f.get();
5177
+ auto resp = cb_wait_for_future(f);
5308
5178
  if (resp.ctx.ec) {
5309
5179
  if (!resp.errors.empty()) {
5310
5180
  const auto& first_error = resp.errors.front();
5311
- exc = cb__map_error_code(
5181
+ exc = cb_map_error_code(
5312
5182
  resp.ctx,
5313
5183
  fmt::format(
5314
5184
  R"(unable to drop primary index on the bucket "{}" ({}: {}))", req.bucket_name, first_error.code, first_error.message));
5315
5185
 
5316
5186
  } else {
5317
- exc = cb__map_error_code(
5318
- resp.ctx, fmt::format("unable to trigger build for deferred indexes for the bucket \"{}\"", req.bucket_name));
5187
+ exc = cb_map_error_code(resp.ctx,
5188
+ fmt::format("unable to trigger build for deferred indexes for the bucket \"{}\"", req.bucket_name));
5319
5189
  }
5320
5190
  break;
5321
5191
  }
@@ -5347,37 +5217,27 @@ cb_Backend_query_index_watch(VALUE self, VALUE bucket_name, VALUE index_names, V
5347
5217
  }
5348
5218
 
5349
5219
  static void
5350
- cb__extract_search_index(VALUE index, const couchbase::operations::search_index& idx)
5220
+ cb_extract_search_index(VALUE index, const couchbase::operations::search_index& idx)
5351
5221
  {
5352
- rb_hash_aset(index, rb_id2sym(rb_intern("uuid")), rb_external_str_new(idx.uuid.data(), static_cast<long>(idx.uuid.size())));
5353
- rb_hash_aset(index, rb_id2sym(rb_intern("name")), rb_external_str_new(idx.name.data(), static_cast<long>(idx.name.size())));
5354
- rb_hash_aset(index, rb_id2sym(rb_intern("type")), rb_external_str_new(idx.type.data(), static_cast<long>(idx.type.size())));
5222
+ rb_hash_aset(index, rb_id2sym(rb_intern("uuid")), cb_str_new(idx.uuid));
5223
+ rb_hash_aset(index, rb_id2sym(rb_intern("name")), cb_str_new(idx.name));
5224
+ rb_hash_aset(index, rb_id2sym(rb_intern("type")), cb_str_new(idx.type));
5355
5225
  if (!idx.params_json.empty()) {
5356
- rb_hash_aset(
5357
- index, rb_id2sym(rb_intern("params")), rb_external_str_new(idx.params_json.data(), static_cast<long>(idx.params_json.size())));
5226
+ rb_hash_aset(index, rb_id2sym(rb_intern("params")), cb_str_new(idx.params_json));
5358
5227
  }
5359
5228
 
5360
5229
  if (!idx.source_uuid.empty()) {
5361
- rb_hash_aset(index,
5362
- rb_id2sym(rb_intern("source_uuid")),
5363
- rb_external_str_new(idx.source_uuid.data(), static_cast<long>(idx.source_uuid.size())));
5230
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_uuid")), cb_str_new(idx.source_uuid));
5364
5231
  }
5365
5232
  if (!idx.source_name.empty()) {
5366
- rb_hash_aset(index,
5367
- rb_id2sym(rb_intern("source_name")),
5368
- rb_external_str_new(idx.source_name.data(), static_cast<long>(idx.source_name.size())));
5233
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_name")), cb_str_new(idx.source_name));
5369
5234
  }
5370
- rb_hash_aset(
5371
- index, rb_id2sym(rb_intern("source_type")), rb_external_str_new(idx.source_type.data(), static_cast<long>(idx.source_type.size())));
5235
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_type")), cb_str_new(idx.source_type));
5372
5236
  if (!idx.source_params_json.empty()) {
5373
- rb_hash_aset(index,
5374
- rb_id2sym(rb_intern("source_params")),
5375
- rb_external_str_new(idx.source_params_json.data(), static_cast<long>(idx.source_params_json.size())));
5237
+ rb_hash_aset(index, rb_id2sym(rb_intern("source_params")), cb_str_new(idx.source_params_json));
5376
5238
  }
5377
5239
  if (!idx.plan_params_json.empty()) {
5378
- rb_hash_aset(index,
5379
- rb_id2sym(rb_intern("plan_params")),
5380
- rb_external_str_new(idx.plan_params_json.data(), static_cast<long>(idx.plan_params_json.size())));
5240
+ rb_hash_aset(index, rb_id2sym(rb_intern("plan_params")), cb_str_new(idx.plan_params_json));
5381
5241
  }
5382
5242
  }
5383
5243
 
@@ -5395,7 +5255,7 @@ cb_Backend_search_index_get_all(VALUE self, VALUE timeout)
5395
5255
  VALUE exc = Qnil;
5396
5256
  do {
5397
5257
  couchbase::operations::search_index_get_all_request req{};
5398
- exc = cb__extract_timeout(req, timeout);
5258
+ exc = cb_extract_timeout(req, timeout);
5399
5259
  if (!NIL_P(exc)) {
5400
5260
  break;
5401
5261
  }
@@ -5403,20 +5263,18 @@ cb_Backend_search_index_get_all(VALUE self, VALUE timeout)
5403
5263
  auto f = barrier->get_future();
5404
5264
  backend->cluster->execute_http(
5405
5265
  req, [barrier](couchbase::operations::search_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
5406
- auto resp = f.get();
5266
+ auto resp = cb_wait_for_future(f);
5407
5267
  if (resp.ctx.ec) {
5408
- exc = cb__map_error_code(resp.ctx, "unable to get list of the search indexes");
5268
+ exc = cb_map_error_code(resp.ctx, "unable to get list of the search indexes");
5409
5269
  break;
5410
5270
  }
5411
5271
  VALUE res = rb_hash_new();
5412
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5413
- rb_hash_aset(res,
5414
- rb_id2sym(rb_intern("impl_version")),
5415
- rb_external_str_new(resp.impl_version.data(), static_cast<long>(resp.impl_version.size())));
5272
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5273
+ rb_hash_aset(res, rb_id2sym(rb_intern("impl_version")), cb_str_new(resp.impl_version));
5416
5274
  VALUE indexes = rb_ary_new_capa(static_cast<long>(resp.indexes.size()));
5417
5275
  for (const auto& idx : resp.indexes) {
5418
5276
  VALUE index = rb_hash_new();
5419
- cb__extract_search_index(index, idx);
5277
+ cb_extract_search_index(index, idx);
5420
5278
  rb_ary_push(indexes, index);
5421
5279
  }
5422
5280
  rb_hash_aset(res, rb_id2sym(rb_intern("indexes")), indexes);
@@ -5441,7 +5299,7 @@ cb_Backend_search_index_get(VALUE self, VALUE index_name, VALUE timeout)
5441
5299
  VALUE exc = Qnil;
5442
5300
  do {
5443
5301
  couchbase::operations::search_index_get_request req{};
5444
- exc = cb__extract_timeout(req, timeout);
5302
+ exc = cb_extract_timeout(req, timeout);
5445
5303
  if (!NIL_P(exc)) {
5446
5304
  break;
5447
5305
  }
@@ -5450,17 +5308,17 @@ cb_Backend_search_index_get(VALUE self, VALUE index_name, VALUE timeout)
5450
5308
  auto f = barrier->get_future();
5451
5309
  backend->cluster->execute_http(
5452
5310
  req, [barrier](couchbase::operations::search_index_get_response&& resp) mutable { barrier->set_value(resp); });
5453
- auto resp = f.get();
5311
+ auto resp = cb_wait_for_future(f);
5454
5312
  if (resp.ctx.ec) {
5455
5313
  if (resp.error.empty()) {
5456
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\"", req.index_name));
5314
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\"", req.index_name));
5457
5315
  } else {
5458
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\": {}", req.index_name, resp.error));
5316
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get search index \"{}\": {}", req.index_name, resp.error));
5459
5317
  }
5460
5318
  break;
5461
5319
  }
5462
5320
  VALUE res = rb_hash_new();
5463
- cb__extract_search_index(res, resp.index);
5321
+ cb_extract_search_index(res, resp.index);
5464
5322
  return res;
5465
5323
  } while (false);
5466
5324
  rb_exc_raise(exc);
@@ -5482,7 +5340,7 @@ cb_Backend_search_index_upsert(VALUE self, VALUE index_definition, VALUE timeout
5482
5340
  VALUE exc = Qnil;
5483
5341
  do {
5484
5342
  couchbase::operations::search_index_upsert_request req{};
5485
- exc = cb__extract_timeout(req, timeout);
5343
+ exc = cb_extract_timeout(req, timeout);
5486
5344
  if (!NIL_P(exc)) {
5487
5345
  break;
5488
5346
  }
@@ -5539,17 +5397,17 @@ cb_Backend_search_index_upsert(VALUE self, VALUE index_definition, VALUE timeout
5539
5397
  auto f = barrier->get_future();
5540
5398
  backend->cluster->execute_http(
5541
5399
  req, [barrier](couchbase::operations::search_index_upsert_response&& resp) mutable { barrier->set_value(resp); });
5542
- auto resp = f.get();
5400
+ auto resp = cb_wait_for_future(f);
5543
5401
  if (resp.ctx.ec) {
5544
5402
  if (resp.error.empty()) {
5545
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\"", req.index.name));
5403
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\"", req.index.name));
5546
5404
  } else {
5547
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\": {}", req.index.name, resp.error));
5405
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to upsert the search index \"{}\": {}", req.index.name, resp.error));
5548
5406
  }
5549
5407
  break;
5550
5408
  }
5551
5409
  VALUE res = rb_hash_new();
5552
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5410
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5553
5411
  return res;
5554
5412
  } while (false);
5555
5413
  rb_exc_raise(exc);
@@ -5571,7 +5429,7 @@ cb_Backend_search_index_drop(VALUE self, VALUE index_name, VALUE timeout)
5571
5429
  VALUE exc = Qnil;
5572
5430
  do {
5573
5431
  couchbase::operations::search_index_drop_request req{};
5574
- exc = cb__extract_timeout(req, timeout);
5432
+ exc = cb_extract_timeout(req, timeout);
5575
5433
  if (!NIL_P(exc)) {
5576
5434
  break;
5577
5435
  }
@@ -5580,17 +5438,17 @@ cb_Backend_search_index_drop(VALUE self, VALUE index_name, VALUE timeout)
5580
5438
  auto f = barrier->get_future();
5581
5439
  backend->cluster->execute_http(
5582
5440
  req, [barrier](couchbase::operations::search_index_drop_response&& resp) mutable { barrier->set_value(resp); });
5583
- auto resp = f.get();
5441
+ auto resp = cb_wait_for_future(f);
5584
5442
  if (resp.ctx.ec) {
5585
5443
  if (resp.error.empty()) {
5586
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\"", req.index_name));
5444
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\"", req.index_name));
5587
5445
  } else {
5588
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\": {}", req.index_name, resp.error));
5446
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop the search index \"{}\": {}", req.index_name, resp.error));
5589
5447
  }
5590
5448
  break;
5591
5449
  }
5592
5450
  VALUE res = rb_hash_new();
5593
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5451
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5594
5452
  return res;
5595
5453
  } while (false);
5596
5454
  rb_exc_raise(exc);
@@ -5612,7 +5470,7 @@ cb_Backend_search_index_get_documents_count(VALUE self, VALUE index_name, VALUE
5612
5470
  VALUE exc = Qnil;
5613
5471
  do {
5614
5472
  couchbase::operations::search_index_get_documents_count_request req{};
5615
- exc = cb__extract_timeout(req, timeout);
5473
+ exc = cb_extract_timeout(req, timeout);
5616
5474
  if (!NIL_P(exc)) {
5617
5475
  break;
5618
5476
  }
@@ -5621,20 +5479,20 @@ cb_Backend_search_index_get_documents_count(VALUE self, VALUE index_name, VALUE
5621
5479
  auto f = barrier->get_future();
5622
5480
  backend->cluster->execute_http(
5623
5481
  req, [barrier](couchbase::operations::search_index_get_documents_count_response&& resp) mutable { barrier->set_value(resp); });
5624
- auto resp = f.get();
5482
+ auto resp = cb_wait_for_future(f);
5625
5483
  if (resp.ctx.ec) {
5626
5484
  if (resp.error.empty()) {
5627
- exc = cb__map_error_code(
5485
+ exc = cb_map_error_code(
5628
5486
  resp.ctx, fmt::format("unable to get number of the indexed documents for the search index \"{}\"", req.index_name));
5629
5487
  } else {
5630
- exc = cb__map_error_code(
5488
+ exc = cb_map_error_code(
5631
5489
  resp.ctx,
5632
5490
  fmt::format("unable to get number of the indexed documents for the search index \"{}\": {}", req.index_name, resp.error));
5633
5491
  }
5634
5492
  break;
5635
5493
  }
5636
5494
  VALUE res = rb_hash_new();
5637
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5495
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5638
5496
  rb_hash_aset(res, rb_id2sym(rb_intern("count")), ULL2NUM(resp.count));
5639
5497
  return res;
5640
5498
  } while (false);
@@ -5657,7 +5515,7 @@ cb_Backend_search_index_get_stats(VALUE self, VALUE index_name, VALUE timeout)
5657
5515
  VALUE exc = Qnil;
5658
5516
  do {
5659
5517
  couchbase::operations::search_index_get_stats_request req{};
5660
- exc = cb__extract_timeout(req, timeout);
5518
+ exc = cb_extract_timeout(req, timeout);
5661
5519
  if (!NIL_P(exc)) {
5662
5520
  break;
5663
5521
  }
@@ -5666,17 +5524,17 @@ cb_Backend_search_index_get_stats(VALUE self, VALUE index_name, VALUE timeout)
5666
5524
  auto f = barrier->get_future();
5667
5525
  backend->cluster->execute_http(
5668
5526
  req, [barrier](couchbase::operations::search_index_get_stats_response&& resp) mutable { barrier->set_value(resp); });
5669
- auto resp = f.get();
5527
+ auto resp = cb_wait_for_future(f);
5670
5528
  if (resp.ctx.ec) {
5671
5529
  if (resp.error.empty()) {
5672
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to get stats for the search index \"{}\"", req.index_name));
5530
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to get stats for the search index \"{}\"", req.index_name));
5673
5531
  } else {
5674
- exc = cb__map_error_code(resp.ctx,
5675
- fmt::format("unable to get stats for the search index \"{}\": {}", req.index_name, resp.error));
5532
+ exc = cb_map_error_code(resp.ctx,
5533
+ fmt::format("unable to get stats for the search index \"{}\": {}", req.index_name, resp.error));
5676
5534
  }
5677
5535
  break;
5678
5536
  }
5679
- return rb_external_str_new(resp.stats.data(), static_cast<long>(resp.stats.size()));
5537
+ return cb_str_new(resp.stats);
5680
5538
  } while (false);
5681
5539
  rb_exc_raise(exc);
5682
5540
  return Qnil;
@@ -5696,7 +5554,7 @@ cb_Backend_search_get_stats(VALUE self, VALUE timeout)
5696
5554
  VALUE exc = Qnil;
5697
5555
  do {
5698
5556
  couchbase::operations::search_index_stats_request req{};
5699
- exc = cb__extract_timeout(req, timeout);
5557
+ exc = cb_extract_timeout(req, timeout);
5700
5558
  if (!NIL_P(exc)) {
5701
5559
  break;
5702
5560
  }
@@ -5704,12 +5562,12 @@ cb_Backend_search_get_stats(VALUE self, VALUE timeout)
5704
5562
  auto f = barrier->get_future();
5705
5563
  backend->cluster->execute_http(
5706
5564
  req, [barrier](couchbase::operations::search_index_stats_response&& resp) mutable { barrier->set_value(resp); });
5707
- auto resp = f.get();
5565
+ auto resp = cb_wait_for_future(f);
5708
5566
  if (resp.ctx.ec) {
5709
- exc = cb__map_error_code(resp.ctx, "unable to get stats for the search service");
5567
+ exc = cb_map_error_code(resp.ctx, "unable to get stats for the search service");
5710
5568
  break;
5711
5569
  }
5712
- return rb_external_str_new(resp.stats.data(), static_cast<long>(resp.stats.size()));
5570
+ return cb_str_new(resp.stats);
5713
5571
  } while (false);
5714
5572
  rb_exc_raise(exc);
5715
5573
  return Qnil;
@@ -5730,7 +5588,7 @@ cb_Backend_search_index_pause_ingest(VALUE self, VALUE index_name, VALUE timeout
5730
5588
  VALUE exc = Qnil;
5731
5589
  do {
5732
5590
  couchbase::operations::search_index_control_ingest_request req{};
5733
- exc = cb__extract_timeout(req, timeout);
5591
+ exc = cb_extract_timeout(req, timeout);
5734
5592
  if (!NIL_P(exc)) {
5735
5593
  break;
5736
5594
  }
@@ -5740,18 +5598,18 @@ cb_Backend_search_index_pause_ingest(VALUE self, VALUE index_name, VALUE timeout
5740
5598
  auto f = barrier->get_future();
5741
5599
  backend->cluster->execute_http(
5742
5600
  req, [barrier](couchbase::operations::search_index_control_ingest_response&& resp) mutable { barrier->set_value(resp); });
5743
- auto resp = f.get();
5601
+ auto resp = cb_wait_for_future(f);
5744
5602
  if (resp.ctx.ec) {
5745
5603
  if (resp.error.empty()) {
5746
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to pause ingest for the search index \"{}\"", req.index_name));
5604
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to pause ingest for the search index \"{}\"", req.index_name));
5747
5605
  } else {
5748
- exc = cb__map_error_code(resp.ctx,
5749
- fmt::format("unable to pause ingest for the search index \"{}\": {}", req.index_name, resp.error));
5606
+ exc = cb_map_error_code(resp.ctx,
5607
+ fmt::format("unable to pause ingest for the search index \"{}\": {}", req.index_name, resp.error));
5750
5608
  }
5751
5609
  break;
5752
5610
  }
5753
5611
  VALUE res = rb_hash_new();
5754
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5612
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5755
5613
  return res;
5756
5614
  } while (false);
5757
5615
  rb_exc_raise(exc);
@@ -5773,7 +5631,7 @@ cb_Backend_search_index_resume_ingest(VALUE self, VALUE index_name, VALUE timeou
5773
5631
  VALUE exc = Qnil;
5774
5632
  do {
5775
5633
  couchbase::operations::search_index_control_ingest_request req{};
5776
- exc = cb__extract_timeout(req, timeout);
5634
+ exc = cb_extract_timeout(req, timeout);
5777
5635
  if (!NIL_P(exc)) {
5778
5636
  break;
5779
5637
  }
@@ -5783,18 +5641,18 @@ cb_Backend_search_index_resume_ingest(VALUE self, VALUE index_name, VALUE timeou
5783
5641
  auto f = barrier->get_future();
5784
5642
  backend->cluster->execute_http(
5785
5643
  req, [barrier](couchbase::operations::search_index_control_ingest_response&& resp) mutable { barrier->set_value(resp); });
5786
- auto resp = f.get();
5644
+ auto resp = cb_wait_for_future(f);
5787
5645
  if (resp.ctx.ec) {
5788
5646
  if (resp.error.empty()) {
5789
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to resume ingest for the search index \"{}\"", req.index_name));
5647
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to resume ingest for the search index \"{}\"", req.index_name));
5790
5648
  } else {
5791
- exc = cb__map_error_code(
5792
- resp.ctx, fmt::format("unable to resume ingest for the search index \"{}\": {}", req.index_name, resp.error));
5649
+ exc = cb_map_error_code(resp.ctx,
5650
+ fmt::format("unable to resume ingest for the search index \"{}\": {}", req.index_name, resp.error));
5793
5651
  }
5794
5652
  break;
5795
5653
  }
5796
5654
  VALUE res = rb_hash_new();
5797
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5655
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5798
5656
  return res;
5799
5657
  } while (false);
5800
5658
  rb_exc_raise(exc);
@@ -5816,7 +5674,7 @@ cb_Backend_search_index_allow_querying(VALUE self, VALUE index_name, VALUE timeo
5816
5674
  VALUE exc = Qnil;
5817
5675
  do {
5818
5676
  couchbase::operations::search_index_control_query_request req{};
5819
- exc = cb__extract_timeout(req, timeout);
5677
+ exc = cb_extract_timeout(req, timeout);
5820
5678
  if (!NIL_P(exc)) {
5821
5679
  break;
5822
5680
  }
@@ -5826,18 +5684,18 @@ cb_Backend_search_index_allow_querying(VALUE self, VALUE index_name, VALUE timeo
5826
5684
  auto f = barrier->get_future();
5827
5685
  backend->cluster->execute_http(
5828
5686
  req, [barrier](couchbase::operations::search_index_control_query_response&& resp) mutable { barrier->set_value(resp); });
5829
- auto resp = f.get();
5687
+ auto resp = cb_wait_for_future(f);
5830
5688
  if (resp.ctx.ec) {
5831
5689
  if (resp.error.empty()) {
5832
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to allow querying for the search index \"{}\"", req.index_name));
5690
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to allow querying for the search index \"{}\"", req.index_name));
5833
5691
  } else {
5834
- exc = cb__map_error_code(
5692
+ exc = cb_map_error_code(
5835
5693
  resp.ctx, fmt::format("unable to allow querying for the search index \"{}\": {}", req.index_name, resp.error));
5836
5694
  }
5837
5695
  break;
5838
5696
  }
5839
5697
  VALUE res = rb_hash_new();
5840
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5698
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5841
5699
  return res;
5842
5700
  } while (false);
5843
5701
  rb_exc_raise(exc);
@@ -5859,7 +5717,7 @@ cb_Backend_search_index_disallow_querying(VALUE self, VALUE index_name, VALUE ti
5859
5717
  VALUE exc = Qnil;
5860
5718
  do {
5861
5719
  couchbase::operations::search_index_control_query_request req{};
5862
- exc = cb__extract_timeout(req, timeout);
5720
+ exc = cb_extract_timeout(req, timeout);
5863
5721
  if (!NIL_P(exc)) {
5864
5722
  break;
5865
5723
  }
@@ -5869,18 +5727,18 @@ cb_Backend_search_index_disallow_querying(VALUE self, VALUE index_name, VALUE ti
5869
5727
  auto f = barrier->get_future();
5870
5728
  backend->cluster->execute_http(
5871
5729
  req, [barrier](couchbase::operations::search_index_control_query_response&& resp) mutable { barrier->set_value(resp); });
5872
- auto resp = f.get();
5730
+ auto resp = cb_wait_for_future(f);
5873
5731
  if (resp.ctx.ec) {
5874
5732
  if (resp.error.empty()) {
5875
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to disallow querying for the search index \"{}\"", req.index_name));
5733
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to disallow querying for the search index \"{}\"", req.index_name));
5876
5734
  } else {
5877
- exc = cb__map_error_code(
5735
+ exc = cb_map_error_code(
5878
5736
  resp.ctx, fmt::format("unable to disallow querying for the search index \"{}\": {}", req.index_name, resp.error));
5879
5737
  }
5880
5738
  break;
5881
5739
  }
5882
5740
  VALUE res = rb_hash_new();
5883
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5741
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5884
5742
  return res;
5885
5743
  } while (false);
5886
5744
  rb_exc_raise(exc);
@@ -5902,7 +5760,7 @@ cb_Backend_search_index_freeze_plan(VALUE self, VALUE index_name, VALUE timeout)
5902
5760
  VALUE exc = Qnil;
5903
5761
  do {
5904
5762
  couchbase::operations::search_index_control_plan_freeze_request req{};
5905
- exc = cb__extract_timeout(req, timeout);
5763
+ exc = cb_extract_timeout(req, timeout);
5906
5764
  if (!NIL_P(exc)) {
5907
5765
  break;
5908
5766
  }
@@ -5912,18 +5770,18 @@ cb_Backend_search_index_freeze_plan(VALUE self, VALUE index_name, VALUE timeout)
5912
5770
  auto f = barrier->get_future();
5913
5771
  backend->cluster->execute_http(
5914
5772
  req, [barrier](couchbase::operations::search_index_control_plan_freeze_response&& resp) mutable { barrier->set_value(resp); });
5915
- auto resp = f.get();
5773
+ auto resp = cb_wait_for_future(f);
5916
5774
  if (resp.ctx.ec) {
5917
5775
  if (resp.error.empty()) {
5918
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\"", req.index_name));
5776
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\"", req.index_name));
5919
5777
  } else {
5920
5778
  exc =
5921
- cb__map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\": {}", req.index_name, resp.error));
5779
+ cb_map_error_code(resp.ctx, fmt::format("unable to freeze for the search index \"{}\": {}", req.index_name, resp.error));
5922
5780
  }
5923
5781
  break;
5924
5782
  }
5925
5783
  VALUE res = rb_hash_new();
5926
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5784
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5927
5785
  return res;
5928
5786
  } while (false);
5929
5787
  rb_exc_raise(exc);
@@ -5945,7 +5803,7 @@ cb_Backend_search_index_unfreeze_plan(VALUE self, VALUE index_name, VALUE timeou
5945
5803
  VALUE exc = Qnil;
5946
5804
  do {
5947
5805
  couchbase::operations::search_index_control_plan_freeze_request req{};
5948
- exc = cb__extract_timeout(req, timeout);
5806
+ exc = cb_extract_timeout(req, timeout);
5949
5807
  if (!NIL_P(exc)) {
5950
5808
  break;
5951
5809
  }
@@ -5955,18 +5813,18 @@ cb_Backend_search_index_unfreeze_plan(VALUE self, VALUE index_name, VALUE timeou
5955
5813
  auto f = barrier->get_future();
5956
5814
  backend->cluster->execute_http(
5957
5815
  req, [barrier](couchbase::operations::search_index_control_plan_freeze_response&& resp) mutable { barrier->set_value(resp); });
5958
- auto resp = f.get();
5816
+ auto resp = cb_wait_for_future(f);
5959
5817
  if (resp.ctx.ec) {
5960
5818
  if (resp.error.empty()) {
5961
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to unfreeze plan for the search index \"{}\"", req.index_name));
5819
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to unfreeze plan for the search index \"{}\"", req.index_name));
5962
5820
  } else {
5963
- exc = cb__map_error_code(resp.ctx,
5964
- fmt::format("unable to unfreeze for the search index \"{}\": {}", req.index_name, resp.error));
5821
+ exc = cb_map_error_code(resp.ctx,
5822
+ fmt::format("unable to unfreeze for the search index \"{}\": {}", req.index_name, resp.error));
5965
5823
  }
5966
5824
  break;
5967
5825
  }
5968
5826
  VALUE res = rb_hash_new();
5969
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
5827
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5970
5828
  return res;
5971
5829
  } while (false);
5972
5830
  rb_exc_raise(exc);
@@ -5989,7 +5847,7 @@ cb_Backend_search_index_analyze_document(VALUE self, VALUE index_name, VALUE enc
5989
5847
  VALUE exc = Qnil;
5990
5848
  do {
5991
5849
  couchbase::operations::search_index_analyze_document_request req{};
5992
- exc = cb__extract_timeout(req, timeout);
5850
+ exc = cb_extract_timeout(req, timeout);
5993
5851
  if (!NIL_P(exc)) {
5994
5852
  break;
5995
5853
  }
@@ -6001,20 +5859,19 @@ cb_Backend_search_index_analyze_document(VALUE self, VALUE index_name, VALUE enc
6001
5859
  auto f = barrier->get_future();
6002
5860
  backend->cluster->execute_http(
6003
5861
  req, [barrier](couchbase::operations::search_index_analyze_document_response&& resp) mutable { barrier->set_value(resp); });
6004
- auto resp = f.get();
5862
+ auto resp = cb_wait_for_future(f);
6005
5863
  if (resp.ctx.ec) {
6006
5864
  if (resp.error.empty()) {
6007
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to analyze document using the search index \"{}\"", req.index_name));
5865
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to analyze document using the search index \"{}\"", req.index_name));
6008
5866
  } else {
6009
- exc = cb__map_error_code(
5867
+ exc = cb_map_error_code(
6010
5868
  resp.ctx, fmt::format("unable to analyze document using the search index \"{}\": {}", req.index_name, resp.error));
6011
5869
  }
6012
5870
  break;
6013
5871
  }
6014
5872
  VALUE res = rb_hash_new();
6015
- rb_hash_aset(res, rb_id2sym(rb_intern("status")), rb_external_str_new(resp.status.data(), static_cast<long>(resp.status.size())));
6016
- rb_hash_aset(
6017
- res, rb_id2sym(rb_intern("analysis")), rb_external_str_new(resp.analysis.data(), static_cast<long>(resp.analysis.size())));
5873
+ rb_hash_aset(res, rb_id2sym(rb_intern("status")), cb_str_new(resp.status));
5874
+ rb_hash_aset(res, rb_id2sym(rb_intern("analysis")), cb_str_new(resp.analysis));
6018
5875
  return res;
6019
5876
  } while (false);
6020
5877
  rb_exc_raise(exc);
@@ -6044,7 +5901,7 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6044
5901
  Check_Type(client_context_id, T_STRING);
6045
5902
  req.client_context_id.assign(RSTRING_PTR(client_context_id), static_cast<size_t>(RSTRING_LEN(client_context_id)));
6046
5903
  }
6047
- exc = cb__extract_timeout(req, options);
5904
+ exc = cb_extract_timeout(req, options);
6048
5905
  if (!NIL_P(exc)) {
6049
5906
  break;
6050
5907
  }
@@ -6182,25 +6039,22 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6182
6039
  VALUE raw_params = rb_hash_aref(options, rb_id2sym(rb_intern("raw_parameters")));
6183
6040
  if (!NIL_P(raw_params)) {
6184
6041
  Check_Type(raw_params, T_HASH);
6185
- rb_hash_foreach(raw_params, INT_FUNC(cb__for_each_named_param), reinterpret_cast<VALUE>(&req));
6042
+ rb_hash_foreach(raw_params, INT_FUNC(cb_for_each_named_param), reinterpret_cast<VALUE>(&req));
6186
6043
  }
6187
6044
 
6188
6045
  auto barrier = std::make_shared<std::promise<couchbase::operations::search_response>>();
6189
6046
  auto f = barrier->get_future();
6190
6047
  backend->cluster->execute_http(req, [barrier](couchbase::operations::search_response&& resp) mutable { barrier->set_value(resp); });
6191
- auto resp = f.get();
6048
+ auto resp = cb_wait_for_future(f);
6192
6049
  if (resp.ctx.ec) {
6193
6050
  exc =
6194
- cb__map_error_code(resp.ctx, fmt::format("unable to perform search query for index \"{}\": {}", req.index_name, resp.error));
6051
+ cb_map_error_code(resp.ctx, fmt::format("unable to perform search query for index \"{}\": {}", req.index_name, resp.error));
6195
6052
  break;
6196
6053
  }
6197
6054
  VALUE res = rb_hash_new();
6198
6055
 
6199
6056
  VALUE meta_data = rb_hash_new();
6200
- rb_hash_aset(
6201
- meta_data,
6202
- rb_id2sym(rb_intern("client_context_id")),
6203
- rb_external_str_new(resp.meta_data.client_context_id.data(), static_cast<long>(resp.meta_data.client_context_id.size())));
6057
+ rb_hash_aset(meta_data, rb_id2sym(rb_intern("client_context_id")), cb_str_new(resp.meta_data.client_context_id));
6204
6058
 
6205
6059
  VALUE metrics = rb_hash_new();
6206
6060
  rb_hash_aset(metrics,
@@ -6214,10 +6068,8 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6214
6068
 
6215
6069
  if (!resp.meta_data.errors.empty()) {
6216
6070
  VALUE errors = rb_hash_new();
6217
- for (auto err : resp.meta_data.errors) {
6218
- rb_hash_aset(errors,
6219
- rb_external_str_new(err.first.data(), static_cast<long>(err.first.size())),
6220
- rb_external_str_new(err.second.data(), static_cast<long>(err.second.size())));
6071
+ for (const auto& err : resp.meta_data.errors) {
6072
+ rb_hash_aset(errors, cb_str_new(err.first), cb_str_new(err.second));
6221
6073
  }
6222
6074
  rb_hash_aset(meta_data, rb_id2sym(rb_intern("errors")), errors);
6223
6075
  }
@@ -6227,16 +6079,14 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6227
6079
  VALUE rows = rb_ary_new_capa(static_cast<long>(resp.rows.size()));
6228
6080
  for (const auto& entry : resp.rows) {
6229
6081
  VALUE row = rb_hash_new();
6230
- rb_hash_aset(
6231
- row, rb_id2sym(rb_intern("index")), rb_external_str_new(entry.index.data(), static_cast<long>(entry.index.size())));
6232
- rb_hash_aset(row, rb_id2sym(rb_intern("id")), rb_external_str_new(entry.id.data(), static_cast<long>(entry.id.size())));
6082
+ rb_hash_aset(row, rb_id2sym(rb_intern("index")), cb_str_new(entry.index));
6083
+ rb_hash_aset(row, rb_id2sym(rb_intern("id")), cb_str_new(entry.id));
6233
6084
  rb_hash_aset(row, rb_id2sym(rb_intern("score")), DBL2NUM(entry.score));
6234
6085
  VALUE locations = rb_ary_new_capa(static_cast<long>(entry.locations.size()));
6235
6086
  for (const auto& loc : entry.locations) {
6236
6087
  VALUE location = rb_hash_new();
6237
- rb_hash_aset(
6238
- row, rb_id2sym(rb_intern("field")), rb_external_str_new(loc.field.data(), static_cast<long>(loc.field.size())));
6239
- rb_hash_aset(row, rb_id2sym(rb_intern("term")), rb_external_str_new(loc.term.data(), static_cast<long>(loc.term.size())));
6088
+ rb_hash_aset(row, rb_id2sym(rb_intern("field")), cb_str_new(loc.field));
6089
+ rb_hash_aset(row, rb_id2sym(rb_intern("term")), cb_str_new(loc.term));
6240
6090
  rb_hash_aset(row, rb_id2sym(rb_intern("pos")), ULL2NUM(loc.position));
6241
6091
  rb_hash_aset(row, rb_id2sym(rb_intern("start_offset")), ULL2NUM(loc.start_offset));
6242
6092
  rb_hash_aset(row, rb_id2sym(rb_intern("end_offset")), ULL2NUM(loc.end_offset));
@@ -6255,22 +6105,17 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6255
6105
  for (const auto& field_fragments : entry.fragments) {
6256
6106
  VALUE fragments_list = rb_ary_new_capa(static_cast<long>(field_fragments.second.size()));
6257
6107
  for (const auto& fragment : field_fragments.second) {
6258
- rb_ary_push(fragments_list, rb_external_str_new(fragment.data(), static_cast<long>(fragment.size())));
6108
+ rb_ary_push(fragments_list, cb_str_new(fragment));
6259
6109
  }
6260
- rb_hash_aset(fragments,
6261
- rb_external_str_new(field_fragments.first.data(), static_cast<long>(field_fragments.first.size())),
6262
- fragments_list);
6110
+ rb_hash_aset(fragments, cb_str_new(field_fragments.first), fragments_list);
6263
6111
  }
6264
6112
  rb_hash_aset(row, rb_id2sym(rb_intern("fragments")), fragments);
6265
6113
  }
6266
6114
  if (!entry.fields.empty()) {
6267
- rb_hash_aset(
6268
- row, rb_id2sym(rb_intern("fields")), rb_external_str_new(entry.fields.data(), static_cast<long>(entry.fields.size())));
6115
+ rb_hash_aset(row, rb_id2sym(rb_intern("fields")), cb_str_new(entry.fields));
6269
6116
  }
6270
6117
  if (!entry.explanation.empty()) {
6271
- rb_hash_aset(row,
6272
- rb_id2sym(rb_intern("explanation")),
6273
- rb_external_str_new(entry.explanation.data(), static_cast<long>(entry.explanation.size())));
6118
+ rb_hash_aset(row, rb_id2sym(rb_intern("explanation")), cb_str_new(entry.explanation));
6274
6119
  }
6275
6120
  rb_ary_push(rows, row);
6276
6121
  }
@@ -6280,10 +6125,9 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6280
6125
  VALUE result_facets = rb_hash_new();
6281
6126
  for (const auto& entry : resp.facets) {
6282
6127
  VALUE facet = rb_hash_new();
6283
- VALUE facet_name = rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size()));
6128
+ VALUE facet_name = cb_str_new(entry.name);
6284
6129
  rb_hash_aset(facet, rb_id2sym(rb_intern("name")), facet_name);
6285
- rb_hash_aset(
6286
- facet, rb_id2sym(rb_intern("field")), rb_external_str_new(entry.field.data(), static_cast<long>(entry.field.size())));
6130
+ rb_hash_aset(facet, rb_id2sym(rb_intern("field")), cb_str_new(entry.field));
6287
6131
  rb_hash_aset(facet, rb_id2sym(rb_intern("total")), ULL2NUM(entry.total));
6288
6132
  rb_hash_aset(facet, rb_id2sym(rb_intern("missing")), ULL2NUM(entry.missing));
6289
6133
  rb_hash_aset(facet, rb_id2sym(rb_intern("other")), ULL2NUM(entry.other));
@@ -6291,8 +6135,7 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6291
6135
  VALUE terms = rb_ary_new_capa(static_cast<long>(entry.terms.size()));
6292
6136
  for (const auto& item : entry.terms) {
6293
6137
  VALUE term = rb_hash_new();
6294
- rb_hash_aset(
6295
- term, rb_id2sym(rb_intern("term")), rb_external_str_new(item.term.data(), static_cast<long>(item.term.size())));
6138
+ rb_hash_aset(term, rb_id2sym(rb_intern("term")), cb_str_new(item.term));
6296
6139
  rb_hash_aset(term, rb_id2sym(rb_intern("count")), ULL2NUM(item.count));
6297
6140
  rb_ary_push(terms, term);
6298
6141
  }
@@ -6301,19 +6144,13 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6301
6144
  VALUE date_ranges = rb_ary_new_capa(static_cast<long>(entry.date_ranges.size()));
6302
6145
  for (const auto& item : entry.date_ranges) {
6303
6146
  VALUE date_range = rb_hash_new();
6304
- rb_hash_aset(date_range,
6305
- rb_id2sym(rb_intern("name")),
6306
- rb_external_str_new(item.name.data(), static_cast<long>(item.name.size())));
6147
+ rb_hash_aset(date_range, rb_id2sym(rb_intern("name")), cb_str_new(item.name));
6307
6148
  rb_hash_aset(date_range, rb_id2sym(rb_intern("count")), ULL2NUM(item.count));
6308
6149
  if (item.start) {
6309
- rb_hash_aset(date_range,
6310
- rb_id2sym(rb_intern("start_time")),
6311
- rb_external_str_new(item.start->data(), static_cast<long>(item.start->size())));
6150
+ rb_hash_aset(date_range, rb_id2sym(rb_intern("start_time")), cb_str_new(item.start.value()));
6312
6151
  }
6313
6152
  if (item.end) {
6314
- rb_hash_aset(date_range,
6315
- rb_id2sym(rb_intern("end_time")),
6316
- rb_external_str_new(item.end->data(), static_cast<long>(item.end->size())));
6153
+ rb_hash_aset(date_range, rb_id2sym(rb_intern("end_time")), cb_str_new(item.end.value()));
6317
6154
  }
6318
6155
  rb_ary_push(date_ranges, date_range);
6319
6156
  }
@@ -6322,9 +6159,7 @@ cb_Backend_document_search(VALUE self, VALUE index_name, VALUE query, VALUE opti
6322
6159
  VALUE numeric_ranges = rb_ary_new_capa(static_cast<long>(entry.numeric_ranges.size()));
6323
6160
  for (const auto& item : entry.numeric_ranges) {
6324
6161
  VALUE numeric_range = rb_hash_new();
6325
- rb_hash_aset(numeric_range,
6326
- rb_id2sym(rb_intern("name")),
6327
- rb_external_str_new(item.name.data(), static_cast<long>(item.name.size())));
6162
+ rb_hash_aset(numeric_range, rb_id2sym(rb_intern("name")), cb_str_new(item.name));
6328
6163
  rb_hash_aset(numeric_range, rb_id2sym(rb_intern("count")), ULL2NUM(item.count));
6329
6164
  if (std::holds_alternative<double>(item.min)) {
6330
6165
  rb_hash_aset(numeric_range, rb_id2sym(rb_intern("min")), DBL2NUM(std::get<double>(item.min)));
@@ -6385,18 +6220,16 @@ cb_Backend_dns_srv(VALUE self, VALUE hostname, VALUE service)
6385
6220
  barrier->set_value(resp);
6386
6221
  });
6387
6222
  ctx.run();
6388
- auto resp = f.get();
6223
+ auto resp = cb_wait_for_future(f);
6389
6224
  if (resp.ec) {
6390
- exc = cb__map_error_code(resp.ec, fmt::format("DNS SRV query failure for name \"{}\" (service: {})", host_name, service_name));
6225
+ exc = cb_map_error_code(resp.ec, fmt::format("DNS SRV query failure for name \"{}\" (service: {})", host_name, service_name));
6391
6226
  break;
6392
6227
  }
6393
6228
 
6394
6229
  VALUE res = rb_ary_new();
6395
6230
  for (const auto& target : resp.targets) {
6396
6231
  VALUE addr = rb_hash_new();
6397
- rb_hash_aset(addr,
6398
- rb_id2sym(rb_intern("hostname")),
6399
- rb_external_str_new(target.hostname.data(), static_cast<long>(target.hostname.size())));
6232
+ rb_hash_aset(addr, rb_id2sym(rb_intern("hostname")), cb_str_new(target.hostname));
6400
6233
  rb_hash_aset(addr, rb_id2sym(rb_intern("port")), UINT2NUM(target.port));
6401
6234
  rb_ary_push(res, addr);
6402
6235
  }
@@ -6420,7 +6253,7 @@ cb_Backend_analytics_get_pending_mutations(VALUE self, VALUE timeout)
6420
6253
  VALUE exc = Qnil;
6421
6254
  do {
6422
6255
  couchbase::operations::analytics_get_pending_mutations_request req{};
6423
- exc = cb__extract_timeout(req, timeout);
6256
+ exc = cb_extract_timeout(req, timeout);
6424
6257
  if (!NIL_P(exc)) {
6425
6258
  break;
6426
6259
  }
@@ -6428,13 +6261,13 @@ cb_Backend_analytics_get_pending_mutations(VALUE self, VALUE timeout)
6428
6261
  auto f = barrier->get_future();
6429
6262
  backend->cluster->execute_http(
6430
6263
  req, [barrier](couchbase::operations::analytics_get_pending_mutations_response&& resp) mutable { barrier->set_value(resp); });
6431
- auto resp = f.get();
6264
+ auto resp = cb_wait_for_future(f);
6432
6265
  if (resp.ctx.ec) {
6433
6266
  if (resp.errors.empty()) {
6434
- exc = cb__map_error_code(resp.ctx, "unable to get pending mutations for the analytics service");
6267
+ exc = cb_map_error_code(resp.ctx, "unable to get pending mutations for the analytics service");
6435
6268
  } else {
6436
6269
  const auto& first_error = resp.errors.front();
6437
- exc = cb__map_error_code(
6270
+ exc = cb_map_error_code(
6438
6271
  resp.ctx,
6439
6272
  fmt::format("unable to get pending mutations for the analytics service ({}: {})", first_error.code, first_error.message));
6440
6273
  }
@@ -6442,7 +6275,7 @@ cb_Backend_analytics_get_pending_mutations(VALUE self, VALUE timeout)
6442
6275
  }
6443
6276
  VALUE res = rb_hash_new();
6444
6277
  for (const auto& entry : resp.stats) {
6445
- rb_hash_aset(res, rb_external_str_new(entry.first.data(), static_cast<long>(entry.first.size())), ULL2NUM(entry.second));
6278
+ rb_hash_aset(res, cb_str_new(entry.first), ULL2NUM(entry.second));
6446
6279
  }
6447
6280
  return res;
6448
6281
  } while (false);
@@ -6464,7 +6297,7 @@ cb_Backend_analytics_dataset_get_all(VALUE self, VALUE timeout)
6464
6297
  VALUE exc = Qnil;
6465
6298
  do {
6466
6299
  couchbase::operations::analytics_dataset_get_all_request req{};
6467
- exc = cb__extract_timeout(req, timeout);
6300
+ exc = cb_extract_timeout(req, timeout);
6468
6301
  if (!NIL_P(exc)) {
6469
6302
  break;
6470
6303
  }
@@ -6472,29 +6305,24 @@ cb_Backend_analytics_dataset_get_all(VALUE self, VALUE timeout)
6472
6305
  auto f = barrier->get_future();
6473
6306
  backend->cluster->execute_http(
6474
6307
  req, [barrier](couchbase::operations::analytics_dataset_get_all_response&& resp) mutable { barrier->set_value(resp); });
6475
- auto resp = f.get();
6308
+ auto resp = cb_wait_for_future(f);
6476
6309
  if (resp.ctx.ec) {
6477
6310
  if (resp.errors.empty()) {
6478
- exc = cb__map_error_code(resp.ctx, "unable to fetch all datasets");
6311
+ exc = cb_map_error_code(resp.ctx, "unable to fetch all datasets");
6479
6312
  } else {
6480
6313
  const auto& first_error = resp.errors.front();
6481
6314
  exc =
6482
- cb__map_error_code(resp.ctx, fmt::format("unable to fetch all datasets ({}: {})", first_error.code, first_error.message));
6315
+ cb_map_error_code(resp.ctx, fmt::format("unable to fetch all datasets ({}: {})", first_error.code, first_error.message));
6483
6316
  }
6484
6317
  break;
6485
6318
  }
6486
6319
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.datasets.size()));
6487
6320
  for (const auto& ds : resp.datasets) {
6488
6321
  VALUE dataset = rb_hash_new();
6489
- rb_hash_aset(dataset, rb_id2sym(rb_intern("name")), rb_external_str_new(ds.name.data(), static_cast<long>(ds.name.size())));
6490
- rb_hash_aset(dataset,
6491
- rb_id2sym(rb_intern("dataverse_name")),
6492
- rb_external_str_new(ds.dataverse_name.data(), static_cast<long>(ds.dataverse_name.size())));
6493
- rb_hash_aset(
6494
- dataset, rb_id2sym(rb_intern("link_name")), rb_external_str_new(ds.link_name.data(), static_cast<long>(ds.link_name.size())));
6495
- rb_hash_aset(dataset,
6496
- rb_id2sym(rb_intern("bucket_name")),
6497
- rb_external_str_new(ds.bucket_name.data(), static_cast<long>(ds.bucket_name.size())));
6322
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("name")), cb_str_new(ds.name));
6323
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("dataverse_name")), cb_str_new(ds.dataverse_name));
6324
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("link_name")), cb_str_new(ds.link_name));
6325
+ rb_hash_aset(dataset, rb_id2sym(rb_intern("bucket_name")), cb_str_new(ds.bucket_name));
6498
6326
  rb_ary_push(res, dataset);
6499
6327
  }
6500
6328
  return res;
@@ -6522,7 +6350,7 @@ cb_Backend_analytics_dataset_drop(VALUE self, VALUE dataset_name, VALUE datavers
6522
6350
  VALUE exc = Qnil;
6523
6351
  do {
6524
6352
  couchbase::operations::analytics_dataset_drop_request req{};
6525
- exc = cb__extract_timeout(req, timeout);
6353
+ exc = cb_extract_timeout(req, timeout);
6526
6354
  if (!NIL_P(exc)) {
6527
6355
  break;
6528
6356
  }
@@ -6537,18 +6365,18 @@ cb_Backend_analytics_dataset_drop(VALUE self, VALUE dataset_name, VALUE datavers
6537
6365
  auto f = barrier->get_future();
6538
6366
  backend->cluster->execute_http(
6539
6367
  req, [barrier](couchbase::operations::analytics_dataset_drop_response&& resp) mutable { barrier->set_value(resp); });
6540
- auto resp = f.get();
6368
+ auto resp = cb_wait_for_future(f);
6541
6369
  if (resp.ctx.ec) {
6542
6370
  if (resp.errors.empty()) {
6543
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6371
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6544
6372
  } else {
6545
6373
  const auto& first_error = resp.errors.front();
6546
- exc = cb__map_error_code(resp.ctx,
6547
- fmt::format("unable to drop dataset `{}`.`{}` ({}: {})",
6548
- req.dataverse_name,
6549
- req.dataset_name,
6550
- first_error.code,
6551
- first_error.message));
6374
+ exc = cb_map_error_code(resp.ctx,
6375
+ fmt::format("unable to drop dataset `{}`.`{}` ({}: {})",
6376
+ req.dataverse_name,
6377
+ req.dataset_name,
6378
+ first_error.code,
6379
+ first_error.message));
6552
6380
  }
6553
6381
  break;
6554
6382
  }
@@ -6587,7 +6415,7 @@ cb_Backend_analytics_dataset_create(VALUE self,
6587
6415
  VALUE exc = Qnil;
6588
6416
  do {
6589
6417
  couchbase::operations::analytics_dataset_create_request req{};
6590
- exc = cb__extract_timeout(req, timeout);
6418
+ exc = cb_extract_timeout(req, timeout);
6591
6419
  if (!NIL_P(exc)) {
6592
6420
  break;
6593
6421
  }
@@ -6606,18 +6434,18 @@ cb_Backend_analytics_dataset_create(VALUE self,
6606
6434
  auto f = barrier->get_future();
6607
6435
  backend->cluster->execute_http(
6608
6436
  req, [barrier](couchbase::operations::analytics_dataset_create_response&& resp) mutable { barrier->set_value(resp); });
6609
- auto resp = f.get();
6437
+ auto resp = cb_wait_for_future(f);
6610
6438
  if (resp.ctx.ec) {
6611
6439
  if (resp.errors.empty()) {
6612
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to create dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6440
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to create dataset `{}`.`{}`", req.dataverse_name, req.dataset_name));
6613
6441
  } else {
6614
6442
  const auto& first_error = resp.errors.front();
6615
- exc = cb__map_error_code(resp.ctx,
6616
- fmt::format("unable to create dataset `{}`.`{}` ({}: {})",
6617
- req.dataverse_name,
6618
- req.dataset_name,
6619
- first_error.code,
6620
- first_error.message));
6443
+ exc = cb_map_error_code(resp.ctx,
6444
+ fmt::format("unable to create dataset `{}`.`{}` ({}: {})",
6445
+ req.dataverse_name,
6446
+ req.dataset_name,
6447
+ first_error.code,
6448
+ first_error.message));
6621
6449
  }
6622
6450
  break;
6623
6451
  }
@@ -6643,7 +6471,7 @@ cb_Backend_analytics_dataverse_drop(VALUE self, VALUE dataverse_name, VALUE igno
6643
6471
  VALUE exc = Qnil;
6644
6472
  do {
6645
6473
  couchbase::operations::analytics_dataverse_drop_request req{};
6646
- exc = cb__extract_timeout(req, timeout);
6474
+ exc = cb_extract_timeout(req, timeout);
6647
6475
  if (!NIL_P(exc)) {
6648
6476
  break;
6649
6477
  }
@@ -6655,13 +6483,13 @@ cb_Backend_analytics_dataverse_drop(VALUE self, VALUE dataverse_name, VALUE igno
6655
6483
  auto f = barrier->get_future();
6656
6484
  backend->cluster->execute_http(
6657
6485
  req, [barrier](couchbase::operations::analytics_dataverse_drop_response&& resp) mutable { barrier->set_value(resp); });
6658
- auto resp = f.get();
6486
+ auto resp = cb_wait_for_future(f);
6659
6487
  if (resp.ctx.ec) {
6660
6488
  if (resp.errors.empty()) {
6661
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to drop dataverse `{}`", req.dataverse_name));
6489
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to drop dataverse `{}`", req.dataverse_name));
6662
6490
  } else {
6663
6491
  const auto& first_error = resp.errors.front();
6664
- exc = cb__map_error_code(
6492
+ exc = cb_map_error_code(
6665
6493
  resp.ctx,
6666
6494
  fmt::format("unable to drop dataverse `{}` ({}: {})", req.dataverse_name, first_error.code, first_error.message));
6667
6495
  }
@@ -6692,7 +6520,7 @@ cb_Backend_analytics_dataverse_create(VALUE self, VALUE dataverse_name, VALUE ig
6692
6520
  VALUE exc = Qnil;
6693
6521
  do {
6694
6522
  couchbase::operations::analytics_dataverse_create_request req{};
6695
- exc = cb__extract_timeout(req, timeout);
6523
+ exc = cb_extract_timeout(req, timeout);
6696
6524
  if (!NIL_P(exc)) {
6697
6525
  break;
6698
6526
  }
@@ -6704,13 +6532,13 @@ cb_Backend_analytics_dataverse_create(VALUE self, VALUE dataverse_name, VALUE ig
6704
6532
  auto f = barrier->get_future();
6705
6533
  backend->cluster->execute_http(
6706
6534
  req, [barrier](couchbase::operations::analytics_dataverse_create_response&& resp) mutable { barrier->set_value(resp); });
6707
- auto resp = f.get();
6535
+ auto resp = cb_wait_for_future(f);
6708
6536
  if (resp.ctx.ec) {
6709
6537
  if (resp.errors.empty()) {
6710
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to create dataverse `{}`", req.dataverse_name));
6538
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to create dataverse `{}`", req.dataverse_name));
6711
6539
  } else {
6712
6540
  const auto& first_error = resp.errors.front();
6713
- exc = cb__map_error_code(
6541
+ exc = cb_map_error_code(
6714
6542
  resp.ctx,
6715
6543
  fmt::format("unable to create dataverse `{}` ({}: {})", req.dataverse_name, first_error.code, first_error.message));
6716
6544
  }
@@ -6736,7 +6564,7 @@ cb_Backend_analytics_index_get_all(VALUE self, VALUE timeout)
6736
6564
  VALUE exc = Qnil;
6737
6565
  do {
6738
6566
  couchbase::operations::analytics_index_get_all_request req{};
6739
- exc = cb__extract_timeout(req, timeout);
6567
+ exc = cb_extract_timeout(req, timeout);
6740
6568
  if (!NIL_P(exc)) {
6741
6569
  break;
6742
6570
  }
@@ -6744,27 +6572,23 @@ cb_Backend_analytics_index_get_all(VALUE self, VALUE timeout)
6744
6572
  auto f = barrier->get_future();
6745
6573
  backend->cluster->execute_http(
6746
6574
  req, [barrier](couchbase::operations::analytics_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
6747
- auto resp = f.get();
6575
+ auto resp = cb_wait_for_future(f);
6748
6576
  if (resp.ctx.ec) {
6749
6577
  if (resp.errors.empty()) {
6750
- exc = cb__map_error_code(resp.ctx, "unable to fetch all indexes");
6578
+ exc = cb_map_error_code(resp.ctx, "unable to fetch all indexes");
6751
6579
  } else {
6752
6580
  const auto& first_error = resp.errors.front();
6753
6581
  exc =
6754
- cb__map_error_code(resp.ctx, fmt::format("unable to fetch all indexes ({}: {})", first_error.code, first_error.message));
6582
+ cb_map_error_code(resp.ctx, fmt::format("unable to fetch all indexes ({}: {})", first_error.code, first_error.message));
6755
6583
  }
6756
6584
  break;
6757
6585
  }
6758
6586
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.indexes.size()));
6759
6587
  for (const auto& idx : resp.indexes) {
6760
6588
  VALUE index = rb_hash_new();
6761
- rb_hash_aset(index, rb_id2sym(rb_intern("name")), rb_external_str_new(idx.name.data(), static_cast<long>(idx.name.size())));
6762
- rb_hash_aset(index,
6763
- rb_id2sym(rb_intern("dataset_name")),
6764
- rb_external_str_new(idx.dataset_name.data(), static_cast<long>(idx.dataset_name.size())));
6765
- rb_hash_aset(index,
6766
- rb_id2sym(rb_intern("dataverse_name")),
6767
- rb_external_str_new(idx.dataverse_name.data(), static_cast<long>(idx.dataverse_name.size())));
6589
+ rb_hash_aset(index, rb_id2sym(rb_intern("name")), cb_str_new(idx.name));
6590
+ rb_hash_aset(index, rb_id2sym(rb_intern("dataset_name")), cb_str_new(idx.dataset_name));
6591
+ rb_hash_aset(index, rb_id2sym(rb_intern("dataverse_name")), cb_str_new(idx.dataverse_name));
6768
6592
  rb_hash_aset(index, rb_id2sym(rb_intern("is_primary")), idx.is_primary ? Qtrue : Qfalse);
6769
6593
  rb_ary_push(res, index);
6770
6594
  }
@@ -6801,7 +6625,7 @@ cb_Backend_analytics_index_create(VALUE self,
6801
6625
  VALUE exc = Qnil;
6802
6626
  do {
6803
6627
  couchbase::operations::analytics_index_create_request req{};
6804
- exc = cb__extract_timeout(req, timeout);
6628
+ exc = cb_extract_timeout(req, timeout);
6805
6629
  if (!NIL_P(exc)) {
6806
6630
  break;
6807
6631
  }
@@ -6828,20 +6652,20 @@ cb_Backend_analytics_index_create(VALUE self,
6828
6652
  auto f = barrier->get_future();
6829
6653
  backend->cluster->execute_http(
6830
6654
  req, [barrier](couchbase::operations::analytics_index_create_response&& resp) mutable { barrier->set_value(resp); });
6831
- auto resp = f.get();
6655
+ auto resp = cb_wait_for_future(f);
6832
6656
  if (resp.ctx.ec) {
6833
6657
  if (resp.errors.empty()) {
6834
- exc = cb__map_error_code(
6658
+ exc = cb_map_error_code(
6835
6659
  resp.ctx, fmt::format("unable to create index `{}` on `{}`.`{}`", req.index_name, req.dataverse_name, req.dataset_name));
6836
6660
  } else {
6837
6661
  const auto& first_error = resp.errors.front();
6838
- exc = cb__map_error_code(resp.ctx,
6839
- fmt::format("unable to create index `{}` on `{}`.`{}` ({}: {})",
6840
- req.index_name,
6841
- req.dataverse_name,
6842
- req.dataset_name,
6843
- first_error.code,
6844
- first_error.message));
6662
+ exc = cb_map_error_code(resp.ctx,
6663
+ fmt::format("unable to create index `{}` on `{}`.`{}` ({}: {})",
6664
+ req.index_name,
6665
+ req.dataverse_name,
6666
+ req.dataset_name,
6667
+ first_error.code,
6668
+ first_error.message));
6845
6669
  }
6846
6670
  break;
6847
6671
  }
@@ -6876,7 +6700,7 @@ cb_Backend_analytics_index_drop(VALUE self,
6876
6700
  VALUE exc = Qnil;
6877
6701
  do {
6878
6702
  couchbase::operations::analytics_index_drop_request req{};
6879
- exc = cb__extract_timeout(req, timeout);
6703
+ exc = cb_extract_timeout(req, timeout);
6880
6704
  if (!NIL_P(exc)) {
6881
6705
  break;
6882
6706
  }
@@ -6892,20 +6716,20 @@ cb_Backend_analytics_index_drop(VALUE self,
6892
6716
  auto f = barrier->get_future();
6893
6717
  backend->cluster->execute_http(
6894
6718
  req, [barrier](couchbase::operations::analytics_index_drop_response&& resp) mutable { barrier->set_value(resp); });
6895
- auto resp = f.get();
6719
+ auto resp = cb_wait_for_future(f);
6896
6720
  if (resp.ctx.ec) {
6897
6721
  if (resp.errors.empty()) {
6898
- exc = cb__map_error_code(
6722
+ exc = cb_map_error_code(
6899
6723
  resp.ctx, fmt::format("unable to drop index `{}`.`{}`.`{}`", req.dataverse_name, req.dataset_name, req.index_name));
6900
6724
  } else {
6901
6725
  const auto& first_error = resp.errors.front();
6902
- exc = cb__map_error_code(resp.ctx,
6903
- fmt::format("unable to drop index `{}`.`{}`.`{}` ({}: {})",
6904
- req.dataverse_name,
6905
- req.dataset_name,
6906
- req.index_name,
6907
- first_error.code,
6908
- first_error.message));
6726
+ exc = cb_map_error_code(resp.ctx,
6727
+ fmt::format("unable to drop index `{}`.`{}`.`{}` ({}: {})",
6728
+ req.dataverse_name,
6729
+ req.dataset_name,
6730
+ req.index_name,
6731
+ first_error.code,
6732
+ first_error.message));
6909
6733
  }
6910
6734
  break;
6911
6735
  }
@@ -6934,7 +6758,7 @@ cb_Backend_analytics_link_connect(VALUE self, VALUE link_name, VALUE force, VALU
6934
6758
  VALUE exc = Qnil;
6935
6759
  do {
6936
6760
  couchbase::operations::analytics_link_connect_request req{};
6937
- exc = cb__extract_timeout(req, timeout);
6761
+ exc = cb_extract_timeout(req, timeout);
6938
6762
  if (!NIL_P(exc)) {
6939
6763
  break;
6940
6764
  }
@@ -6949,18 +6773,18 @@ cb_Backend_analytics_link_connect(VALUE self, VALUE link_name, VALUE force, VALU
6949
6773
  auto f = barrier->get_future();
6950
6774
  backend->cluster->execute_http(
6951
6775
  req, [barrier](couchbase::operations::analytics_link_connect_response&& resp) mutable { barrier->set_value(resp); });
6952
- auto resp = f.get();
6776
+ auto resp = cb_wait_for_future(f);
6953
6777
  if (resp.ctx.ec) {
6954
6778
  if (resp.errors.empty()) {
6955
- exc = cb__map_error_code(resp.ctx, fmt::format("unable to connect link `{}` on `{}`", req.link_name, req.dataverse_name));
6779
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to connect link `{}` on `{}`", req.link_name, req.dataverse_name));
6956
6780
  } else {
6957
6781
  const auto& first_error = resp.errors.front();
6958
- exc = cb__map_error_code(resp.ctx,
6959
- fmt::format("unable to connect link `{}` on `{}` ({}: {})",
6960
- req.link_name,
6961
- req.dataverse_name,
6962
- first_error.code,
6963
- first_error.message));
6782
+ exc = cb_map_error_code(resp.ctx,
6783
+ fmt::format("unable to connect link `{}` on `{}` ({}: {})",
6784
+ req.link_name,
6785
+ req.dataverse_name,
6786
+ first_error.code,
6787
+ first_error.message));
6964
6788
  }
6965
6789
  break;
6966
6790
  }
@@ -6989,7 +6813,7 @@ cb_Backend_analytics_link_disconnect(VALUE self, VALUE link_name, VALUE datavers
6989
6813
  VALUE exc = Qnil;
6990
6814
  do {
6991
6815
  couchbase::operations::analytics_link_disconnect_request req{};
6992
- exc = cb__extract_timeout(req, timeout);
6816
+ exc = cb_extract_timeout(req, timeout);
6993
6817
  if (!NIL_P(exc)) {
6994
6818
  break;
6995
6819
  }
@@ -7001,19 +6825,18 @@ cb_Backend_analytics_link_disconnect(VALUE self, VALUE link_name, VALUE datavers
7001
6825
  auto f = barrier->get_future();
7002
6826
  backend->cluster->execute_http(
7003
6827
  req, [barrier](couchbase::operations::analytics_link_disconnect_response&& resp) mutable { barrier->set_value(resp); });
7004
- auto resp = f.get();
6828
+ auto resp = cb_wait_for_future(f);
7005
6829
  if (resp.ctx.ec) {
7006
6830
  if (resp.errors.empty()) {
7007
- exc =
7008
- cb__map_error_code(resp.ctx, fmt::format("unable to disconnect link `{}` on `{}`", req.link_name, req.dataverse_name));
6831
+ exc = cb_map_error_code(resp.ctx, fmt::format("unable to disconnect link `{}` on `{}`", req.link_name, req.dataverse_name));
7009
6832
  } else {
7010
6833
  const auto& first_error = resp.errors.front();
7011
- exc = cb__map_error_code(resp.ctx,
7012
- fmt::format("unable to disconnect link `{}` on `{}` ({}: {})",
7013
- req.link_name,
7014
- req.dataverse_name,
7015
- first_error.code,
7016
- first_error.message));
6834
+ exc = cb_map_error_code(resp.ctx,
6835
+ fmt::format("unable to disconnect link `{}` on `{}` ({}: {})",
6836
+ req.link_name,
6837
+ req.dataverse_name,
6838
+ first_error.code,
6839
+ first_error.message));
7017
6840
  }
7018
6841
  break;
7019
6842
  }
@@ -7024,7 +6847,7 @@ cb_Backend_analytics_link_disconnect(VALUE self, VALUE link_name, VALUE datavers
7024
6847
  }
7025
6848
 
7026
6849
  static int
7027
- cb__for_each_named_param__analytics(VALUE key, VALUE value, VALUE arg)
6850
+ cb_for_each_named_param_analytics(VALUE key, VALUE value, VALUE arg)
7028
6851
  {
7029
6852
  auto* preq = reinterpret_cast<couchbase::operations::analytics_request*>(arg);
7030
6853
  Check_Type(key, T_STRING);
@@ -7058,7 +6881,7 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7058
6881
  Check_Type(client_context_id, T_STRING);
7059
6882
  req.client_context_id.assign(RSTRING_PTR(client_context_id), static_cast<size_t>(RSTRING_LEN(client_context_id)));
7060
6883
  }
7061
- exc = cb__extract_timeout(req, options);
6884
+ exc = cb_extract_timeout(req, options);
7062
6885
  if (!NIL_P(exc)) {
7063
6886
  break;
7064
6887
  }
@@ -7085,7 +6908,7 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7085
6908
  VALUE named_params = rb_hash_aref(options, rb_id2sym(rb_intern("named_parameters")));
7086
6909
  if (!NIL_P(named_params)) {
7087
6910
  Check_Type(named_params, T_HASH);
7088
- rb_hash_foreach(named_params, INT_FUNC(cb__for_each_named_param__analytics), reinterpret_cast<VALUE>(&req));
6911
+ rb_hash_foreach(named_params, INT_FUNC(cb_for_each_named_param_analytics), reinterpret_cast<VALUE>(&req));
7089
6912
  }
7090
6913
  VALUE scan_consistency = rb_hash_aref(options, rb_id2sym(rb_intern("scan_consistency")));
7091
6914
  if (!NIL_P(scan_consistency)) {
@@ -7118,21 +6941,21 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7118
6941
  VALUE raw_params = rb_hash_aref(options, rb_id2sym(rb_intern("raw_parameters")));
7119
6942
  if (!NIL_P(raw_params)) {
7120
6943
  Check_Type(raw_params, T_HASH);
7121
- rb_hash_foreach(raw_params, INT_FUNC(cb__for_each_named_param__analytics), reinterpret_cast<VALUE>(&req));
6944
+ rb_hash_foreach(raw_params, INT_FUNC(cb_for_each_named_param_analytics), reinterpret_cast<VALUE>(&req));
7122
6945
  }
7123
6946
 
7124
6947
  auto barrier = std::make_shared<std::promise<couchbase::operations::analytics_response>>();
7125
6948
  auto f = barrier->get_future();
7126
6949
  backend->cluster->execute_http(req,
7127
6950
  [barrier](couchbase::operations::analytics_response&& resp) mutable { barrier->set_value(resp); });
7128
- auto resp = f.get();
6951
+ auto resp = cb_wait_for_future(f);
7129
6952
  if (resp.ctx.ec) {
7130
6953
  if (resp.payload.meta_data.errors && !resp.payload.meta_data.errors->empty()) {
7131
6954
  const auto& first_error = resp.payload.meta_data.errors->front();
7132
- exc = cb__map_error_code(resp.ctx,
7133
- fmt::format("unable to execute analytics query ({}: {})", first_error.code, first_error.message));
6955
+ exc = cb_map_error_code(resp.ctx,
6956
+ fmt::format("unable to execute analytics query ({}: {})", first_error.code, first_error.message));
7134
6957
  } else {
7135
- exc = cb__map_error_code(resp.ctx, "unable to execute analytics query");
6958
+ exc = cb_map_error_code(resp.ctx, "unable to execute analytics query");
7136
6959
  }
7137
6960
  break;
7138
6961
  }
@@ -7140,43 +6963,25 @@ cb_Backend_document_analytics(VALUE self, VALUE statement, VALUE options)
7140
6963
  VALUE rows = rb_ary_new_capa(static_cast<long>(resp.payload.rows.size()));
7141
6964
  rb_hash_aset(res, rb_id2sym(rb_intern("rows")), rows);
7142
6965
  for (auto& row : resp.payload.rows) {
7143
- rb_ary_push(rows, rb_external_str_new(row.data(), static_cast<long>(row.size())));
6966
+ rb_ary_push(rows, cb_str_new(row));
7144
6967
  }
7145
6968
  VALUE meta = rb_hash_new();
7146
6969
  rb_hash_aset(res, rb_id2sym(rb_intern("meta")), meta);
7147
6970
  rb_hash_aset(meta,
7148
6971
  rb_id2sym(rb_intern("status")),
7149
6972
  rb_id2sym(rb_intern2(resp.payload.meta_data.status.data(), static_cast<long>(resp.payload.meta_data.status.size()))));
7150
- rb_hash_aset(
7151
- meta,
7152
- rb_id2sym(rb_intern("request_id")),
7153
- rb_external_str_new(resp.payload.meta_data.request_id.data(), static_cast<long>(resp.payload.meta_data.request_id.size())));
7154
- rb_hash_aset(meta,
7155
- rb_id2sym(rb_intern("client_context_id")),
7156
- rb_external_str_new(resp.payload.meta_data.client_context_id.data(),
7157
- static_cast<long>(resp.payload.meta_data.client_context_id.size())));
6973
+ rb_hash_aset(meta, rb_id2sym(rb_intern("request_id")), cb_str_new(resp.payload.meta_data.request_id));
6974
+ rb_hash_aset(meta, rb_id2sym(rb_intern("client_context_id")), cb_str_new(resp.payload.meta_data.client_context_id));
7158
6975
  if (resp.payload.meta_data.signature) {
7159
- rb_hash_aset(
7160
- meta,
7161
- rb_id2sym(rb_intern("signature")),
7162
- rb_external_str_new(resp.payload.meta_data.signature->data(), static_cast<long>(resp.payload.meta_data.signature->size())));
6976
+ rb_hash_aset(meta, rb_id2sym(rb_intern("signature")), cb_str_new(resp.payload.meta_data.signature.value()));
7163
6977
  }
7164
6978
  if (resp.payload.meta_data.profile) {
7165
- rb_hash_aset(
7166
- meta,
7167
- rb_id2sym(rb_intern("profile")),
7168
- rb_external_str_new(resp.payload.meta_data.profile->data(), static_cast<long>(resp.payload.meta_data.profile->size())));
6979
+ rb_hash_aset(meta, rb_id2sym(rb_intern("profile")), cb_str_new(resp.payload.meta_data.profile.value()));
7169
6980
  }
7170
6981
  VALUE metrics = rb_hash_new();
7171
6982
  rb_hash_aset(meta, rb_id2sym(rb_intern("metrics")), metrics);
7172
- rb_hash_aset(metrics,
7173
- rb_id2sym(rb_intern("elapsed_time")),
7174
- rb_external_str_new(resp.payload.meta_data.metrics.elapsed_time.data(),
7175
- static_cast<long>(resp.payload.meta_data.metrics.elapsed_time.size())));
7176
- rb_hash_aset(metrics,
7177
- rb_id2sym(rb_intern("execution_time")),
7178
- rb_external_str_new(resp.payload.meta_data.metrics.execution_time.data(),
7179
- static_cast<long>(resp.payload.meta_data.metrics.execution_time.size())));
6983
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("elapsed_time")), cb_str_new(resp.payload.meta_data.metrics.elapsed_time));
6984
+ rb_hash_aset(metrics, rb_id2sym(rb_intern("execution_time")), cb_str_new(resp.payload.meta_data.metrics.execution_time));
7180
6985
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_count")), ULL2NUM(resp.payload.meta_data.metrics.result_count));
7181
6986
  rb_hash_aset(metrics, rb_id2sym(rb_intern("result_size")), ULL2NUM(resp.payload.meta_data.metrics.result_count));
7182
6987
  if (resp.payload.meta_data.metrics.sort_count) {
@@ -7209,16 +7014,14 @@ cb_Backend_parse_connection_string(VALUE self, VALUE connection_string)
7209
7014
 
7210
7015
  VALUE res = rb_hash_new();
7211
7016
  if (!connstr.scheme.empty()) {
7212
- rb_hash_aset(
7213
- res, rb_id2sym(rb_intern("scheme")), rb_external_str_new(connstr.scheme.data(), static_cast<long>(connstr.scheme.size())));
7017
+ rb_hash_aset(res, rb_id2sym(rb_intern("scheme")), cb_str_new(connstr.scheme));
7214
7018
  rb_hash_aset(res, rb_id2sym(rb_intern("tls")), connstr.tls ? Qtrue : Qfalse);
7215
7019
  }
7216
7020
 
7217
7021
  VALUE nodes = rb_ary_new_capa(static_cast<long>(connstr.bootstrap_nodes.size()));
7218
7022
  for (const auto& entry : connstr.bootstrap_nodes) {
7219
7023
  VALUE node = rb_hash_new();
7220
- rb_hash_aset(
7221
- node, rb_id2sym(rb_intern("address")), rb_external_str_new(entry.address.data(), static_cast<long>(entry.address.size())));
7024
+ rb_hash_aset(node, rb_id2sym(rb_intern("address")), cb_str_new(entry.address));
7222
7025
  if (entry.port > 0) {
7223
7026
  rb_hash_aset(node, rb_id2sym(rb_intern("port")), UINT2NUM(entry.port));
7224
7027
  }
@@ -7249,16 +7052,12 @@ cb_Backend_parse_connection_string(VALUE self, VALUE connection_string)
7249
7052
 
7250
7053
  VALUE params = rb_hash_new();
7251
7054
  for (const auto& param : connstr.params) {
7252
- rb_hash_aset(params,
7253
- rb_external_str_new(param.first.data(), static_cast<long>(param.first.size())),
7254
- rb_external_str_new(param.second.data(), static_cast<long>(param.second.size())));
7055
+ rb_hash_aset(params, cb_str_new(param.first), cb_str_new(param.second));
7255
7056
  }
7256
7057
  rb_hash_aset(res, rb_id2sym(rb_intern("params")), params);
7257
7058
 
7258
7059
  if (connstr.default_bucket_name) {
7259
- rb_hash_aset(res,
7260
- rb_id2sym(rb_intern("default_bucket_name")),
7261
- rb_external_str_new(connstr.default_bucket_name->data(), static_cast<long>(connstr.default_bucket_name->size())));
7060
+ rb_hash_aset(res, rb_id2sym(rb_intern("default_bucket_name")), cb_str_new(connstr.default_bucket_name.value()));
7262
7061
  }
7263
7062
  if (connstr.default_port > 0) {
7264
7063
  rb_hash_aset(res, rb_id2sym(rb_intern("default_port")), UINT2NUM(connstr.default_port));
@@ -7274,8 +7073,7 @@ cb_Backend_parse_connection_string(VALUE self, VALUE connection_string)
7274
7073
  break;
7275
7074
  }
7276
7075
  if (connstr.error) {
7277
- rb_hash_aset(
7278
- res, rb_id2sym(rb_intern("error")), rb_external_str_new(connstr.error->data(), static_cast<long>(connstr.error->size())));
7076
+ rb_hash_aset(res, rb_id2sym(rb_intern("error")), cb_str_new(connstr.error.value()));
7279
7077
  }
7280
7078
  return res;
7281
7079
  }
@@ -7310,7 +7108,7 @@ cb_Backend_view_index_get_all(VALUE self, VALUE bucket_name, VALUE name_space, V
7310
7108
  couchbase::operations::view_index_get_all_request req{};
7311
7109
  req.bucket_name.assign(RSTRING_PTR(bucket_name), static_cast<size_t>(RSTRING_LEN(bucket_name)));
7312
7110
  req.name_space = ns;
7313
- exc = cb__extract_timeout(req, timeout);
7111
+ exc = cb_extract_timeout(req, timeout);
7314
7112
  if (!NIL_P(exc)) {
7315
7113
  break;
7316
7114
  }
@@ -7318,16 +7116,16 @@ cb_Backend_view_index_get_all(VALUE self, VALUE bucket_name, VALUE name_space, V
7318
7116
  auto f = barrier->get_future();
7319
7117
  backend->cluster->execute_http(
7320
7118
  req, [barrier](couchbase::operations::view_index_get_all_response&& resp) mutable { barrier->set_value(resp); });
7321
- auto resp = f.get();
7119
+ auto resp = cb_wait_for_future(f);
7322
7120
  if (resp.ctx.ec) {
7323
- exc = cb__map_error_code(resp.ctx, "unable to get list of the design documents");
7121
+ exc = cb_map_error_code(resp.ctx, "unable to get list of the design documents");
7324
7122
  break;
7325
7123
  }
7326
7124
  VALUE res = rb_ary_new_capa(static_cast<long>(resp.design_documents.size()));
7327
7125
  for (const auto& entry : resp.design_documents) {
7328
7126
  VALUE dd = rb_hash_new();
7329
- rb_hash_aset(dd, rb_id2sym(rb_intern("name")), rb_external_str_new(entry.name.data(), static_cast<long>(entry.name.size())));
7330
- rb_hash_aset(dd, rb_id2sym(rb_intern("rev")), rb_external_str_new(entry.rev.data(), static_cast<long>(entry.rev.size())));
7127
+ rb_hash_aset(dd, rb_id2sym(rb_intern("name")), cb_str_new(entry.name));
7128
+ rb_hash_aset(dd, rb_id2sym(rb_intern("rev")), cb_str_new(entry.rev));
7331
7129
  switch (entry.ns) {
7332
7130
  case couchbase::operations::design_document::name_space::development:
7333
7131
  rb_hash_aset(dd, rb_id2sym(rb_intern("namespace")), rb_id2sym(rb_intern("development")));
@@ -7338,19 +7136,14 @@ cb_Backend_view_index_get_all(VALUE self, VALUE bucket_name, VALUE name_space, V
7338
7136
  }
7339
7137
  VALUE views = rb_hash_new();
7340
7138
  for (const auto& view_entry : entry.views) {
7341
- VALUE view_name = rb_external_str_new(view_entry.first.data(), static_cast<long>(view_entry.first.size()));
7139
+ VALUE view_name = cb_str_new(view_entry.first);
7342
7140
  VALUE view = rb_hash_new();
7343
7141
  rb_hash_aset(view, rb_id2sym(rb_intern("name")), view_name);
7344
7142
  if (view_entry.second.map) {
7345
- rb_hash_aset(view,
7346
- rb_id2sym(rb_intern("map")),
7347
- rb_external_str_new(view_entry.second.map->data(), static_cast<long>(view_entry.second.map->size())));
7143
+ rb_hash_aset(view, rb_id2sym(rb_intern("map")), cb_str_new(view_entry.second.map.value()));
7348
7144
  }
7349
7145
  if (view_entry.second.reduce) {
7350
- rb_hash_aset(
7351
- view,
7352
- rb_id2sym(rb_intern("reduce")),
7353
- rb_external_str_new(view_entry.second.reduce->data(), static_cast<long>(view_entry.second.reduce->size())));
7146
+ rb_hash_aset(view, rb_id2sym(rb_intern("reduce")), cb_str_new(view_entry.second.reduce.value()));
7354
7147
  }
7355
7148
  rb_hash_aset(views, view_name, view);
7356
7149
  }
@@ -7395,7 +7188,7 @@ cb_Backend_view_index_get(VALUE self, VALUE bucket_name, VALUE document_name, VA
7395
7188
  req.bucket_name.assign(RSTRING_PTR(bucket_name), static_cast<size_t>(RSTRING_LEN(bucket_name)));
7396
7189
  req.document_name.assign(RSTRING_PTR(document_name), static_cast<size_t>(RSTRING_LEN(document_name)));
7397
7190
  req.name_space = ns;
7398
- exc = cb__extract_timeout(req, timeout);
7191
+ exc = cb_extract_timeout(req, timeout);
7399
7192
  if (!NIL_P(exc)) {
7400
7193
  break;
7401
7194
  }
@@ -7403,18 +7196,16 @@ cb_Backend_view_index_get(VALUE self, VALUE bucket_name, VALUE document_name, VA
7403
7196
  auto f = barrier->get_future();
7404
7197
  backend->cluster->execute_http(
7405
7198
  req, [barrier](couchbase::operations::view_index_get_response&& resp) mutable { barrier->set_value(resp); });
7406
- auto resp = f.get();
7199
+ auto resp = cb_wait_for_future(f);
7407
7200
  if (resp.ctx.ec) {
7408
- exc = cb__map_error_code(
7201
+ exc = cb_map_error_code(
7409
7202
  resp.ctx,
7410
7203
  fmt::format(R"(unable to get design document "{}" ({}) on bucket "{}")", req.document_name, req.name_space, req.bucket_name));
7411
7204
  break;
7412
7205
  }
7413
7206
  VALUE res = rb_hash_new();
7414
- rb_hash_aset(
7415
- res, rb_id2sym(rb_intern("name")), rb_external_str_new(resp.document.name.data(), static_cast<long>(resp.document.name.size())));
7416
- rb_hash_aset(
7417
- res, rb_id2sym(rb_intern("rev")), rb_external_str_new(resp.document.rev.data(), static_cast<long>(resp.document.rev.size())));
7207
+ rb_hash_aset(res, rb_id2sym(rb_intern("name")), cb_str_new(resp.document.name));
7208
+ rb_hash_aset(res, rb_id2sym(rb_intern("rev")), cb_str_new(resp.document.rev));
7418
7209
  switch (resp.document.ns) {
7419
7210
  case couchbase::operations::design_document::name_space::development:
7420
7211
  rb_hash_aset(res, rb_id2sym(rb_intern("namespace")), rb_id2sym(rb_intern("development")));
@@ -7425,18 +7216,14 @@ cb_Backend_view_index_get(VALUE self, VALUE bucket_name, VALUE document_name, VA
7425
7216
  }
7426
7217
  VALUE views = rb_hash_new();
7427
7218
  for (const auto& view_entry : resp.document.views) {
7428
- VALUE view_name = rb_external_str_new(view_entry.first.data(), static_cast<long>(view_entry.first.size()));
7219
+ VALUE view_name = cb_str_new(view_entry.first);
7429
7220
  VALUE view = rb_hash_new();
7430
7221
  rb_hash_aset(view, rb_id2sym(rb_intern("name")), view_name);
7431
7222
  if (view_entry.second.map) {
7432
- rb_hash_aset(view,
7433
- rb_id2sym(rb_intern("map")),
7434
- rb_external_str_new(view_entry.second.map->data(), static_cast<long>(view_entry.second.map->size())));
7223
+ rb_hash_aset(view, rb_id2sym(rb_intern("map")), cb_str_new(view_entry.second.map.value()));
7435
7224
  }
7436
7225
  if (view_entry.second.reduce) {
7437
- rb_hash_aset(view,
7438
- rb_id2sym(rb_intern("reduce")),
7439
- rb_external_str_new(view_entry.second.reduce->data(), static_cast<long>(view_entry.second.reduce->size())));
7226
+ rb_hash_aset(view, rb_id2sym(rb_intern("reduce")), cb_str_new(view_entry.second.reduce.value()));
7440
7227
  }
7441
7228
  rb_hash_aset(views, view_name, view);
7442
7229
  }
@@ -7479,7 +7266,7 @@ cb_Backend_view_index_drop(VALUE self, VALUE bucket_name, VALUE document_name, V
7479
7266
  req.bucket_name.assign(RSTRING_PTR(bucket_name), static_cast<size_t>(RSTRING_LEN(bucket_name)));
7480
7267
  req.document_name.assign(RSTRING_PTR(document_name), static_cast<size_t>(RSTRING_LEN(document_name)));
7481
7268
  req.name_space = ns;
7482
- exc = cb__extract_timeout(req, timeout);
7269
+ exc = cb_extract_timeout(req, timeout);
7483
7270
  if (!NIL_P(exc)) {
7484
7271
  break;
7485
7272
  }
@@ -7487,9 +7274,9 @@ cb_Backend_view_index_drop(VALUE self, VALUE bucket_name, VALUE document_name, V
7487
7274
  auto f = barrier->get_future();
7488
7275
  backend->cluster->execute_http(
7489
7276
  req, [barrier](couchbase::operations::view_index_drop_response&& resp) mutable { barrier->set_value(resp); });
7490
- auto resp = f.get();
7277
+ auto resp = cb_wait_for_future(f);
7491
7278
  if (resp.ctx.ec) {
7492
- exc = cb__map_error_code(
7279
+ exc = cb_map_error_code(
7493
7280
  resp.ctx,
7494
7281
  fmt::format(
7495
7282
  R"(unable to drop design document "{}" ({}) on bucket "{}")", req.document_name, req.name_space, req.bucket_name));
@@ -7560,7 +7347,7 @@ cb_Backend_view_index_upsert(VALUE self, VALUE bucket_name, VALUE document, VALU
7560
7347
  }
7561
7348
  }
7562
7349
 
7563
- exc = cb__extract_timeout(req, timeout);
7350
+ exc = cb_extract_timeout(req, timeout);
7564
7351
  if (!NIL_P(exc)) {
7565
7352
  break;
7566
7353
  }
@@ -7568,9 +7355,9 @@ cb_Backend_view_index_upsert(VALUE self, VALUE bucket_name, VALUE document, VALU
7568
7355
  auto f = barrier->get_future();
7569
7356
  backend->cluster->execute_http(
7570
7357
  req, [barrier](couchbase::operations::view_index_upsert_response&& resp) mutable { barrier->set_value(resp); });
7571
- auto resp = f.get();
7358
+ auto resp = cb_wait_for_future(f);
7572
7359
  if (resp.ctx.ec) {
7573
- exc = cb__map_error_code(
7360
+ exc = cb_map_error_code(
7574
7361
  resp.ctx,
7575
7362
  fmt::format(
7576
7363
  R"(unable to store design document "{}" ({}) on bucket "{}")", req.document.name, req.document.ns, req.bucket_name));
@@ -7618,7 +7405,7 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7618
7405
  req.document_name.assign(RSTRING_PTR(design_document_name), static_cast<size_t>(RSTRING_LEN(design_document_name)));
7619
7406
  req.view_name.assign(RSTRING_PTR(view_name), static_cast<size_t>(RSTRING_LEN(view_name)));
7620
7407
  req.name_space = ns;
7621
- exc = cb__extract_timeout(req, options);
7408
+ exc = cb_extract_timeout(req, options);
7622
7409
  if (!NIL_P(exc)) {
7623
7410
  break;
7624
7411
  }
@@ -7718,13 +7505,13 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7718
7505
  auto f = barrier->get_future();
7719
7506
  backend->cluster->execute_http(
7720
7507
  req, [barrier](couchbase::operations::document_view_response&& resp) mutable { barrier->set_value(resp); });
7721
- auto resp = f.get();
7508
+ auto resp = cb_wait_for_future(f);
7722
7509
  if (resp.ctx.ec) {
7723
7510
  if (resp.error) {
7724
- exc = cb__map_error_code(resp.ctx,
7725
- fmt::format(R"(unable to execute view query {} ({}))", resp.error->code, resp.error->message));
7511
+ exc = cb_map_error_code(resp.ctx,
7512
+ fmt::format(R"(unable to execute view query {} ({}))", resp.error->code, resp.error->message));
7726
7513
  } else {
7727
- exc = cb__map_error_code(resp.ctx, "unable to execute view query");
7514
+ exc = cb_map_error_code(resp.ctx, "unable to execute view query");
7728
7515
  }
7729
7516
  break;
7730
7517
  }
@@ -7735,9 +7522,7 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7735
7522
  rb_hash_aset(meta, rb_id2sym(rb_intern("total_rows")), ULL2NUM(*resp.meta_data.total_rows));
7736
7523
  }
7737
7524
  if (resp.meta_data.debug_info) {
7738
- rb_hash_aset(meta,
7739
- rb_id2sym(rb_intern("debug_info")),
7740
- rb_external_str_new(resp.meta_data.debug_info->data(), static_cast<long>(resp.meta_data.debug_info->size())));
7525
+ rb_hash_aset(meta, rb_id2sym(rb_intern("debug_info")), cb_str_new(resp.meta_data.debug_info.value()));
7741
7526
  }
7742
7527
  rb_hash_aset(res, rb_id2sym(rb_intern("meta")), meta);
7743
7528
 
@@ -7745,11 +7530,10 @@ cb_Backend_document_view(VALUE self, VALUE bucket_name, VALUE design_document_na
7745
7530
  for (const auto& entry : resp.rows) {
7746
7531
  VALUE row = rb_hash_new();
7747
7532
  if (entry.id) {
7748
- rb_hash_aset(row, rb_id2sym(rb_intern("id")), rb_external_str_new(entry.id->data(), static_cast<long>(entry.id->size())));
7533
+ rb_hash_aset(row, rb_id2sym(rb_intern("id")), cb_str_new(entry.id.value()));
7749
7534
  }
7750
- rb_hash_aset(row, rb_id2sym(rb_intern("key")), rb_external_str_new(entry.key.data(), static_cast<long>(entry.key.size())));
7751
- rb_hash_aset(
7752
- row, rb_id2sym(rb_intern("value")), rb_external_str_new(entry.value.data(), static_cast<long>(entry.value.size())));
7535
+ rb_hash_aset(row, rb_id2sym(rb_intern("key")), cb_str_new(entry.key));
7536
+ rb_hash_aset(row, rb_id2sym(rb_intern("value")), cb_str_new(entry.value));
7753
7537
  rb_ary_push(rows, row);
7754
7538
  }
7755
7539
  rb_hash_aset(res, rb_id2sym(rb_intern("rows")), rows);
@@ -7820,6 +7604,7 @@ cb_Backend_snappy_compress(VALUE self, VALUE data)
7820
7604
 
7821
7605
  std::string compressed{};
7822
7606
  std::size_t compressed_size = snappy::Compress(RSTRING_PTR(data), static_cast<std::size_t>(RSTRING_LEN(data)), &compressed);
7607
+
7823
7608
  return rb_external_str_new(compressed.data(), static_cast<long>(compressed_size));
7824
7609
  }
7825
7610
 
@@ -7832,7 +7617,7 @@ cb_Backend_snappy_uncompress(VALUE self, VALUE data)
7832
7617
  std::string uncompressed{};
7833
7618
  bool success = snappy::Uncompress(RSTRING_PTR(data), static_cast<std::size_t>(RSTRING_LEN(data)), &uncompressed);
7834
7619
  if (success) {
7835
- return rb_external_str_new(uncompressed.data(), static_cast<long>(uncompressed.size()));
7620
+ return cb_str_new(uncompressed);
7836
7621
  }
7837
7622
  rb_raise(rb_eArgError, "Unable to decompress buffer");
7838
7623
  return Qnil;
@@ -7851,7 +7636,7 @@ cb_Backend_leb128_encode(VALUE self, VALUE number)
7851
7636
  }
7852
7637
  couchbase::protocol::unsigned_leb128<std::uint64_t> encoded(NUM2ULL(number));
7853
7638
  std::string buf = encoded.get();
7854
- return rb_external_str_new(buf.data(), static_cast<long>(buf.size()));
7639
+ return cb_str_new(buf);
7855
7640
  }
7856
7641
 
7857
7642
  static VALUE