couchbase 3.0.0.alpha.1-universal-darwin-19 → 3.0.0.alpha.2-universal-darwin-19
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/tests-6.0.3.yml +49 -0
- data/.github/workflows/tests.yml +47 -0
- data/.gitmodules +3 -0
- data/.idea/dictionaries/gem_terms.xml +5 -0
- data/.idea/inspectionProfiles/Project_Default.xml +1 -0
- data/.idea/vcs.xml +1 -0
- data/Gemfile +1 -0
- data/README.md +55 -2
- data/Rakefile +18 -0
- data/bin/init-cluster +62 -0
- data/bin/setup +1 -0
- data/couchbase.gemspec +3 -2
- data/examples/crud.rb +1 -2
- data/examples/managing_buckets.rb +47 -0
- data/examples/managing_collections.rb +58 -0
- data/examples/managing_query_indexes.rb +63 -0
- data/examples/query.rb +3 -2
- data/examples/query_with_consistency.rb +76 -0
- data/examples/subdocument.rb +23 -1
- data/ext/.clang-format +1 -1
- data/ext/.idea/dictionaries/couchbase_terms.xml +2 -0
- data/ext/.idea/vcs.xml +1 -0
- data/ext/CMakeLists.txt +30 -12
- data/ext/build_version.hxx.in +26 -0
- data/ext/couchbase/bucket.hxx +69 -8
- data/ext/couchbase/cluster.hxx +70 -54
- data/ext/couchbase/collections_manifest.hxx +3 -3
- data/ext/couchbase/configuration.hxx +14 -0
- data/ext/couchbase/couchbase.cxx +2044 -383
- data/ext/couchbase/{operations/document_id.hxx → document_id.hxx} +5 -4
- data/ext/couchbase/io/http_message.hxx +5 -1
- data/ext/couchbase/io/http_parser.hxx +2 -1
- data/ext/couchbase/io/http_session.hxx +6 -3
- data/ext/couchbase/io/{binary_message.hxx → mcbp_message.hxx} +15 -12
- data/ext/couchbase/io/mcbp_parser.hxx +99 -0
- data/ext/couchbase/io/{key_value_session.hxx → mcbp_session.hxx} +200 -95
- data/ext/couchbase/io/session_manager.hxx +37 -22
- data/ext/couchbase/mutation_token.hxx +2 -1
- data/ext/couchbase/operations.hxx +38 -8
- data/ext/couchbase/operations/bucket_create.hxx +138 -0
- data/ext/couchbase/operations/bucket_drop.hxx +65 -0
- data/ext/couchbase/operations/bucket_flush.hxx +65 -0
- data/ext/couchbase/operations/bucket_get.hxx +69 -0
- data/ext/couchbase/operations/bucket_get_all.hxx +62 -0
- data/ext/couchbase/operations/bucket_settings.hxx +111 -0
- data/ext/couchbase/operations/bucket_update.hxx +115 -0
- data/ext/couchbase/operations/cluster_developer_preview_enable.hxx +60 -0
- data/ext/couchbase/operations/collection_create.hxx +86 -0
- data/ext/couchbase/operations/collection_drop.hxx +82 -0
- data/ext/couchbase/operations/command.hxx +10 -10
- data/ext/couchbase/operations/document_decrement.hxx +80 -0
- data/ext/couchbase/operations/document_exists.hxx +80 -0
- data/ext/couchbase/operations/{get.hxx → document_get.hxx} +4 -2
- data/ext/couchbase/operations/document_get_and_lock.hxx +64 -0
- data/ext/couchbase/operations/document_get_and_touch.hxx +64 -0
- data/ext/couchbase/operations/document_increment.hxx +80 -0
- data/ext/couchbase/operations/document_insert.hxx +74 -0
- data/ext/couchbase/operations/{lookup_in.hxx → document_lookup_in.hxx} +2 -2
- data/ext/couchbase/operations/{mutate_in.hxx → document_mutate_in.hxx} +11 -2
- data/ext/couchbase/operations/{query.hxx → document_query.hxx} +101 -6
- data/ext/couchbase/operations/document_remove.hxx +67 -0
- data/ext/couchbase/operations/document_replace.hxx +76 -0
- data/ext/couchbase/operations/{upsert.hxx → document_touch.hxx} +14 -14
- data/ext/couchbase/operations/{remove.hxx → document_unlock.hxx} +12 -10
- data/ext/couchbase/operations/document_upsert.hxx +74 -0
- data/ext/couchbase/operations/query_index_build_deferred.hxx +85 -0
- data/ext/couchbase/operations/query_index_create.hxx +134 -0
- data/ext/couchbase/operations/query_index_drop.hxx +108 -0
- data/ext/couchbase/operations/query_index_get_all.hxx +106 -0
- data/ext/couchbase/operations/scope_create.hxx +81 -0
- data/ext/couchbase/operations/scope_drop.hxx +79 -0
- data/ext/couchbase/operations/scope_get_all.hxx +72 -0
- data/ext/couchbase/protocol/client_opcode.hxx +35 -0
- data/ext/couchbase/protocol/client_request.hxx +56 -9
- data/ext/couchbase/protocol/client_response.hxx +52 -15
- data/ext/couchbase/protocol/cmd_cluster_map_change_notification.hxx +81 -0
- data/ext/couchbase/protocol/cmd_decrement.hxx +187 -0
- data/ext/couchbase/protocol/cmd_exists.hxx +171 -0
- data/ext/couchbase/protocol/cmd_get.hxx +31 -8
- data/ext/couchbase/protocol/cmd_get_and_lock.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_and_touch.hxx +142 -0
- data/ext/couchbase/protocol/cmd_get_cluster_config.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_collections_manifest.hxx +16 -3
- data/ext/couchbase/protocol/cmd_get_error_map.hxx +16 -3
- data/ext/couchbase/protocol/cmd_hello.hxx +24 -8
- data/ext/couchbase/protocol/cmd_increment.hxx +187 -0
- data/ext/couchbase/protocol/cmd_info.hxx +1 -0
- data/ext/couchbase/protocol/cmd_insert.hxx +172 -0
- data/ext/couchbase/protocol/cmd_lookup_in.hxx +28 -13
- data/ext/couchbase/protocol/cmd_mutate_in.hxx +65 -13
- data/ext/couchbase/protocol/cmd_remove.hxx +59 -4
- data/ext/couchbase/protocol/cmd_replace.hxx +172 -0
- data/ext/couchbase/protocol/cmd_sasl_auth.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_list_mechs.hxx +15 -3
- data/ext/couchbase/protocol/cmd_sasl_step.hxx +15 -3
- data/ext/couchbase/protocol/cmd_select_bucket.hxx +14 -2
- data/ext/couchbase/protocol/cmd_touch.hxx +102 -0
- data/ext/couchbase/protocol/cmd_unlock.hxx +95 -0
- data/ext/couchbase/protocol/cmd_upsert.hxx +50 -14
- data/ext/couchbase/protocol/durability_level.hxx +67 -0
- data/ext/couchbase/protocol/frame_info_id.hxx +187 -0
- data/ext/couchbase/protocol/hello_feature.hxx +137 -0
- data/ext/couchbase/protocol/server_opcode.hxx +57 -0
- data/ext/couchbase/protocol/server_request.hxx +122 -0
- data/ext/couchbase/protocol/unsigned_leb128.h +15 -15
- data/ext/couchbase/utils/byteswap.hxx +1 -2
- data/ext/couchbase/utils/url_codec.hxx +225 -0
- data/ext/couchbase/version.hxx +3 -1
- data/ext/extconf.rb +4 -1
- data/ext/test/main.cxx +37 -113
- data/ext/third_party/snappy/.appveyor.yml +36 -0
- data/ext/third_party/snappy/.gitignore +8 -0
- data/ext/third_party/snappy/.travis.yml +98 -0
- data/ext/third_party/snappy/AUTHORS +1 -0
- data/ext/third_party/snappy/CMakeLists.txt +345 -0
- data/ext/third_party/snappy/CONTRIBUTING.md +26 -0
- data/ext/third_party/snappy/COPYING +54 -0
- data/ext/third_party/snappy/NEWS +188 -0
- data/ext/third_party/snappy/README.md +148 -0
- data/ext/third_party/snappy/cmake/SnappyConfig.cmake.in +33 -0
- data/ext/third_party/snappy/cmake/config.h.in +59 -0
- data/ext/third_party/snappy/docs/README.md +72 -0
- data/ext/third_party/snappy/format_description.txt +110 -0
- data/ext/third_party/snappy/framing_format.txt +135 -0
- data/ext/third_party/snappy/snappy-c.cc +90 -0
- data/ext/third_party/snappy/snappy-c.h +138 -0
- data/ext/third_party/snappy/snappy-internal.h +315 -0
- data/ext/third_party/snappy/snappy-sinksource.cc +121 -0
- data/ext/third_party/snappy/snappy-sinksource.h +182 -0
- data/ext/third_party/snappy/snappy-stubs-internal.cc +42 -0
- data/ext/third_party/snappy/snappy-stubs-internal.h +493 -0
- data/ext/third_party/snappy/snappy-stubs-public.h.in +63 -0
- data/ext/third_party/snappy/snappy-test.cc +613 -0
- data/ext/third_party/snappy/snappy-test.h +526 -0
- data/ext/third_party/snappy/snappy.cc +1770 -0
- data/ext/third_party/snappy/snappy.h +209 -0
- data/ext/third_party/snappy/snappy_compress_fuzzer.cc +60 -0
- data/ext/third_party/snappy/snappy_uncompress_fuzzer.cc +58 -0
- data/ext/third_party/snappy/snappy_unittest.cc +1512 -0
- data/ext/third_party/snappy/testdata/alice29.txt +3609 -0
- data/ext/third_party/snappy/testdata/asyoulik.txt +4122 -0
- data/ext/third_party/snappy/testdata/baddata1.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata2.snappy +0 -0
- data/ext/third_party/snappy/testdata/baddata3.snappy +0 -0
- data/ext/third_party/snappy/testdata/fireworks.jpeg +0 -0
- data/ext/third_party/snappy/testdata/geo.protodata +0 -0
- data/ext/third_party/snappy/testdata/html +1 -0
- data/ext/third_party/snappy/testdata/html_x_4 +1 -0
- data/ext/third_party/snappy/testdata/kppkn.gtb +0 -0
- data/ext/third_party/snappy/testdata/lcet10.txt +7519 -0
- data/ext/third_party/snappy/testdata/paper-100k.pdf +600 -2
- data/ext/third_party/snappy/testdata/plrabn12.txt +10699 -0
- data/ext/third_party/snappy/testdata/urls.10K +10000 -0
- data/lib/couchbase/binary_collection.rb +33 -76
- data/lib/couchbase/binary_collection_options.rb +94 -0
- data/lib/couchbase/bucket.rb +9 -3
- data/lib/couchbase/cluster.rb +161 -23
- data/lib/couchbase/collection.rb +108 -191
- data/lib/couchbase/collection_options.rb +430 -0
- data/lib/couchbase/errors.rb +136 -134
- data/lib/couchbase/json_transcoder.rb +32 -0
- data/lib/couchbase/management/analytics_index_manager.rb +185 -9
- data/lib/couchbase/management/bucket_manager.rb +84 -33
- data/lib/couchbase/management/collection_manager.rb +166 -1
- data/lib/couchbase/management/query_index_manager.rb +261 -0
- data/lib/couchbase/management/search_index_manager.rb +291 -0
- data/lib/couchbase/management/user_manager.rb +12 -10
- data/lib/couchbase/management/view_index_manager.rb +151 -1
- data/lib/couchbase/mutation_state.rb +11 -1
- data/lib/couchbase/scope.rb +4 -4
- data/lib/couchbase/version.rb +1 -1
- metadata +113 -18
- data/.travis.yml +0 -7
- data/ext/couchbase/io/binary_parser.hxx +0 -64
- data/lib/couchbase/results.rb +0 -307
@@ -49,14 +49,14 @@ template
|
|
49
49
|
typename std::enable_if<std::is_unsigned<T>::value, std::pair<T, std::string_view>>::type
|
50
50
|
decode_unsigned_leb128(std::string_view buf, struct Leb128NoThrow)
|
51
51
|
{
|
52
|
-
T rv = static_cast<uint8_t>(buf[0]) &
|
52
|
+
T rv = static_cast<uint8_t>(buf[0]) & 0x7fULL;
|
53
53
|
size_t end = 0;
|
54
|
-
if ((buf[0] & 0x80) ==
|
54
|
+
if ((buf[0] & 0x80) == 0x80ULL) {
|
55
55
|
T shift = 7;
|
56
56
|
// shift in the remaining data
|
57
57
|
for (end = 1; end < buf.size(); end++) {
|
58
|
-
rv |= (buf[end] &
|
59
|
-
if ((static_cast<uint8_t>(buf[end]) &
|
58
|
+
rv |= (buf[end] & 0x7fULL) << shift;
|
59
|
+
if ((static_cast<uint8_t>(buf[end]) & 0x80ULL) == 0) {
|
60
60
|
break; // no more
|
61
61
|
}
|
62
62
|
shift += 7;
|
@@ -112,7 +112,7 @@ unsigned_leb128_get_stop_byte_index(std::string_view buf)
|
|
112
112
|
// If buf does not contain a stop-byte, invalid
|
113
113
|
size_t stopByte = 0;
|
114
114
|
for (auto c : buf) {
|
115
|
-
if ((static_cast<uint8_t>(c) &
|
115
|
+
if ((static_cast<uint8_t>(c) & 0x80ULL) == 0) {
|
116
116
|
return stopByte;
|
117
117
|
}
|
118
118
|
stopByte++;
|
@@ -134,45 +134,45 @@ template
|
|
134
134
|
class unsigned_leb128<T, typename std::enable_if<std::is_unsigned<T>::value>::type>
|
135
135
|
{
|
136
136
|
public:
|
137
|
-
unsigned_leb128(T in)
|
137
|
+
explicit unsigned_leb128(T in)
|
138
138
|
{
|
139
139
|
while (in > 0) {
|
140
|
-
auto byte = gsl::narrow_cast<uint8_t>(in &
|
140
|
+
auto byte = gsl::narrow_cast<uint8_t>(in & 0x7fULL);
|
141
141
|
in >>= 7;
|
142
142
|
|
143
143
|
// In has more data?
|
144
144
|
if (in > 0) {
|
145
145
|
byte |= 0x80;
|
146
|
-
encodedData[encodedSize -
|
146
|
+
encodedData[encodedSize - 1U] = byte;
|
147
147
|
// Increase the size
|
148
148
|
encodedSize++;
|
149
149
|
} else {
|
150
|
-
encodedData[encodedSize -
|
150
|
+
encodedData[encodedSize - 1U] = byte;
|
151
151
|
}
|
152
152
|
}
|
153
153
|
}
|
154
154
|
|
155
|
-
std::
|
155
|
+
[[nodiscard]] std::string get() const
|
156
156
|
{
|
157
|
-
return {
|
157
|
+
return { begin(), end() };
|
158
158
|
}
|
159
159
|
|
160
|
-
const uint8_t* begin() const
|
160
|
+
[[nodiscard]] const uint8_t* begin() const
|
161
161
|
{
|
162
162
|
return encodedData.data();
|
163
163
|
}
|
164
164
|
|
165
|
-
const uint8_t* end() const
|
165
|
+
[[nodiscard]] const uint8_t* end() const
|
166
166
|
{
|
167
167
|
return encodedData.data() + encodedSize;
|
168
168
|
}
|
169
169
|
|
170
|
-
const uint8_t* data() const
|
170
|
+
[[nodiscard]] const uint8_t* data() const
|
171
171
|
{
|
172
172
|
return encodedData.data();
|
173
173
|
}
|
174
174
|
|
175
|
-
size_t size() const
|
175
|
+
[[nodiscard]] size_t size() const
|
176
176
|
{
|
177
177
|
return encodedSize;
|
178
178
|
}
|
@@ -22,7 +22,6 @@ namespace couchbase::utils
|
|
22
22
|
static inline std::uint64_t
|
23
23
|
byte_swap_64(std::uint64_t val)
|
24
24
|
{
|
25
|
-
;
|
26
25
|
std::uint64_t ret = 0U;
|
27
26
|
for (std::size_t i = 0; i < sizeof(std::uint64_t); ++i) {
|
28
27
|
ret <<= 8U;
|
@@ -31,4 +30,4 @@ byte_swap_64(std::uint64_t val)
|
|
31
30
|
}
|
32
31
|
return ret;
|
33
32
|
}
|
34
|
-
} // namespace couchbase::utils
|
33
|
+
} // namespace couchbase::utils
|
@@ -0,0 +1,225 @@
|
|
1
|
+
#pragma once
|
2
|
+
|
3
|
+
namespace couchbase::utils::string_codec
|
4
|
+
{
|
5
|
+
template<typename Ti, typename To>
|
6
|
+
bool
|
7
|
+
url_decode(Ti first, Ti last, To out, size_t& nout)
|
8
|
+
{
|
9
|
+
for (; first != last && *first != '\0'; ++first) {
|
10
|
+
if (*first == '%') {
|
11
|
+
char nextbuf[3] = { 0 };
|
12
|
+
size_t jj = 0;
|
13
|
+
first++;
|
14
|
+
nextbuf[0] = *first;
|
15
|
+
for (; first != last && jj < 2; ++jj) {
|
16
|
+
nextbuf[jj] = *first;
|
17
|
+
if (jj != 1) {
|
18
|
+
first++;
|
19
|
+
}
|
20
|
+
}
|
21
|
+
if (jj != 2) {
|
22
|
+
return false;
|
23
|
+
}
|
24
|
+
|
25
|
+
unsigned octet = 0;
|
26
|
+
if (sscanf(nextbuf, "%2X", &octet) != 1) {
|
27
|
+
return false;
|
28
|
+
}
|
29
|
+
|
30
|
+
*out = static_cast<char>(octet);
|
31
|
+
} else {
|
32
|
+
*out = *first;
|
33
|
+
}
|
34
|
+
|
35
|
+
out++;
|
36
|
+
nout++;
|
37
|
+
}
|
38
|
+
return true;
|
39
|
+
}
|
40
|
+
|
41
|
+
inline bool
|
42
|
+
url_decode(const char* input, char* output)
|
43
|
+
{
|
44
|
+
const char* endp = input + strlen(input);
|
45
|
+
size_t nout = 0;
|
46
|
+
if (url_decode(input, endp, output, nout)) {
|
47
|
+
output[nout] = '\0';
|
48
|
+
return true;
|
49
|
+
}
|
50
|
+
return false;
|
51
|
+
}
|
52
|
+
|
53
|
+
inline bool
|
54
|
+
url_decode(char* in_out)
|
55
|
+
{
|
56
|
+
return url_decode(in_out, in_out);
|
57
|
+
}
|
58
|
+
|
59
|
+
inline bool
|
60
|
+
url_decode(std::string& s)
|
61
|
+
{
|
62
|
+
size_t n = 0;
|
63
|
+
if (url_decode(s.begin(), s.end(), s.begin(), n)) {
|
64
|
+
s.resize(n);
|
65
|
+
return true;
|
66
|
+
}
|
67
|
+
return false;
|
68
|
+
}
|
69
|
+
|
70
|
+
namespace priv
|
71
|
+
{
|
72
|
+
inline bool
|
73
|
+
is_legal_uri_char(char c)
|
74
|
+
{
|
75
|
+
auto uc = static_cast<unsigned char>(c);
|
76
|
+
if ((isalpha(uc) != 0) || (isdigit(uc) != 0)) {
|
77
|
+
return true;
|
78
|
+
}
|
79
|
+
switch (uc) {
|
80
|
+
case '-':
|
81
|
+
case '_':
|
82
|
+
case '.':
|
83
|
+
case '~':
|
84
|
+
case '!':
|
85
|
+
case '*':
|
86
|
+
case '\'':
|
87
|
+
case '(':
|
88
|
+
case ')':
|
89
|
+
case ';':
|
90
|
+
case ':':
|
91
|
+
case '@':
|
92
|
+
case '&':
|
93
|
+
case '=':
|
94
|
+
case '+':
|
95
|
+
case '$':
|
96
|
+
case ',':
|
97
|
+
case '/':
|
98
|
+
case '?':
|
99
|
+
case '#':
|
100
|
+
case '[':
|
101
|
+
case ']':
|
102
|
+
return true;
|
103
|
+
default:
|
104
|
+
break;
|
105
|
+
}
|
106
|
+
return false;
|
107
|
+
}
|
108
|
+
|
109
|
+
template<typename T>
|
110
|
+
inline bool
|
111
|
+
is_already_escape(T first, T last)
|
112
|
+
{
|
113
|
+
first++; // ignore '%'
|
114
|
+
size_t jj;
|
115
|
+
for (jj = 0; first != last && jj < 2; ++jj, ++first) {
|
116
|
+
if (!isxdigit(*first)) {
|
117
|
+
return false;
|
118
|
+
}
|
119
|
+
}
|
120
|
+
return jj == 2;
|
121
|
+
}
|
122
|
+
} // namespace priv
|
123
|
+
|
124
|
+
template<typename Ti, typename To>
|
125
|
+
bool
|
126
|
+
url_encode(Ti first, Ti last, To& o, bool check_encoded = true)
|
127
|
+
{
|
128
|
+
// If re-encoding detection is enabled, this flag indicates not to
|
129
|
+
// re-encode
|
130
|
+
bool skip_encoding = false;
|
131
|
+
|
132
|
+
for (; first != last; ++first) {
|
133
|
+
if (!skip_encoding && check_encoded) {
|
134
|
+
if (*first == '%') {
|
135
|
+
skip_encoding = priv::is_already_escape(first, last);
|
136
|
+
} else if (*first == '+') {
|
137
|
+
skip_encoding = true;
|
138
|
+
}
|
139
|
+
}
|
140
|
+
if (skip_encoding || priv::is_legal_uri_char(*first)) {
|
141
|
+
if (skip_encoding && *first != '%' && !priv::is_legal_uri_char(*first)) {
|
142
|
+
return false;
|
143
|
+
}
|
144
|
+
|
145
|
+
o.insert(o.end(), first, first + 1);
|
146
|
+
} else {
|
147
|
+
unsigned int c = static_cast<unsigned char>(*first);
|
148
|
+
size_t numbytes = 0;
|
149
|
+
|
150
|
+
if ((c & 0x80) == 0) { /* ASCII character */
|
151
|
+
numbytes = 1;
|
152
|
+
} else if ((c & 0xE0) == 0xC0) { /* 110x xxxx */
|
153
|
+
numbytes = 2;
|
154
|
+
} else if ((c & 0xF0) == 0xE0) { /* 1110 xxxx */
|
155
|
+
numbytes = 3;
|
156
|
+
} else if ((c & 0xF8) == 0xF0) { /* 1111 0xxx */
|
157
|
+
numbytes = 4;
|
158
|
+
} else {
|
159
|
+
return false;
|
160
|
+
}
|
161
|
+
|
162
|
+
do {
|
163
|
+
char buf[4];
|
164
|
+
sprintf(buf, "%%%02X", static_cast<unsigned char>(*first));
|
165
|
+
o.insert(o.end(), &buf[0], &buf[0] + 3);
|
166
|
+
} while (--numbytes && ++first != last);
|
167
|
+
}
|
168
|
+
}
|
169
|
+
return true;
|
170
|
+
}
|
171
|
+
|
172
|
+
template<typename Tin, typename Tout>
|
173
|
+
bool
|
174
|
+
url_encode(const Tin& in, Tout& out)
|
175
|
+
{
|
176
|
+
return url_encode(in.begin(), in.end(), out);
|
177
|
+
}
|
178
|
+
|
179
|
+
/* See: https://url.spec.whatwg.org/#urlencoded-serializing: */
|
180
|
+
/*
|
181
|
+
* 0x2A
|
182
|
+
* 0x2D
|
183
|
+
* 0x2E
|
184
|
+
* 0x30 to 0x39
|
185
|
+
* 0x41 to 0x5A
|
186
|
+
* 0x5F
|
187
|
+
* 0x61 to 0x7A
|
188
|
+
* Append a code point whose value is byte to output.
|
189
|
+
* Otherwise
|
190
|
+
* Append byte, percent encoded, to output.
|
191
|
+
*/
|
192
|
+
template<typename Ti, typename To>
|
193
|
+
void
|
194
|
+
form_encode(Ti first, Ti last, To& out)
|
195
|
+
{
|
196
|
+
for (; first != last; ++first) {
|
197
|
+
auto c = static_cast<unsigned char>(*first);
|
198
|
+
if (isalnum(c)) {
|
199
|
+
out.insert(out.end(), first, first + 1);
|
200
|
+
continue;
|
201
|
+
}
|
202
|
+
if (c == ' ') {
|
203
|
+
char tmp = '+';
|
204
|
+
out.insert(out.end(), &tmp, &tmp + 1);
|
205
|
+
} else if ((c == 0x2A || c == 0x2D || c == 0x2E) || (c >= 0x30 && c <= 0x39) || (c >= 0x41 && c <= 0x5A) || (c == 0x5F) ||
|
206
|
+
(c >= 0x60 && c <= 0x7A)) {
|
207
|
+
out.insert(out.end(), static_cast<char>(c));
|
208
|
+
} else {
|
209
|
+
char buf[3] = { 0 };
|
210
|
+
out.insert(out.end(), '%');
|
211
|
+
sprintf(buf, "%02X", c);
|
212
|
+
out.insert(out.end(), &buf[0], &buf[0] + 2);
|
213
|
+
}
|
214
|
+
}
|
215
|
+
}
|
216
|
+
|
217
|
+
std::string
|
218
|
+
form_encode(const std::string& src)
|
219
|
+
{
|
220
|
+
std::string dst;
|
221
|
+
form_encode(src.begin(), src.end(), dst);
|
222
|
+
return dst;
|
223
|
+
}
|
224
|
+
|
225
|
+
} // namespace couchbase::utils::string_codec
|
data/ext/couchbase/version.hxx
CHANGED
data/ext/extconf.rb
CHANGED
@@ -12,6 +12,7 @@ def sys(*cmd)
|
|
12
12
|
system(*cmd)
|
13
13
|
end
|
14
14
|
|
15
|
+
|
15
16
|
build_type = ENV["DEBUG"] ? "Debug" : "RelWithDebInfo"
|
16
17
|
cmake_flags = [
|
17
18
|
"-DCMAKE_BUILD_TYPE=#{build_type}",
|
@@ -19,9 +20,11 @@ cmake_flags = [
|
|
19
20
|
"-DRUBY_ARCH_HDR_DIR=#{RbConfig::CONFIG["rubyarchhdrdir"]}",
|
20
21
|
"-DTAOCPP_JSON_BUILD_TESTS=OFF",
|
21
22
|
"-DTAOCPP_JSON_BUILD_EXAMPLES=OFF",
|
23
|
+
"-DSNAPPY_BUILD_TESTS=OFF",
|
24
|
+
"-DSNAPPY_INSTALL=OFF",
|
22
25
|
]
|
23
26
|
openssl_root = `brew --prefix openssl 2> /dev/null`.strip
|
24
|
-
|
27
|
+
unless openssl_root.empty?
|
25
28
|
cmake_flags << "-DOPENSSL_ROOT_DIR=#{openssl_root}"
|
26
29
|
end
|
27
30
|
|
data/ext/test/main.cxx
CHANGED
@@ -15,129 +15,53 @@
|
|
15
15
|
* limitations under the License.
|
16
16
|
*/
|
17
17
|
|
18
|
-
#include <
|
18
|
+
#include <generated_config.hxx>
|
19
19
|
|
20
|
-
#include <
|
20
|
+
#include <spdlog/spdlog.h>
|
21
21
|
|
22
|
-
#include <
|
23
|
-
#include <operations/get.hxx>
|
24
|
-
#include <operations/upsert.hxx>
|
25
|
-
#include <operations/lookup_in.hxx>
|
26
|
-
#include <operations/query.hxx>
|
22
|
+
#include <ruby.h>
|
27
23
|
|
28
|
-
|
29
|
-
|
30
|
-
bool
|
31
|
-
done()
|
24
|
+
void
|
25
|
+
run_script(const char* script)
|
32
26
|
{
|
33
|
-
|
34
|
-
|
35
|
-
|
27
|
+
spdlog::info("run script:\n----------------------------------------{}---------------------------------------\n", script);
|
28
|
+
int status = 0;
|
29
|
+
rb_eval_string_protect(script, &status);
|
30
|
+
if (status != 0) {
|
31
|
+
VALUE rbError = rb_funcall(rb_gv_get("$!"), rb_intern("message"), 0);
|
32
|
+
spdlog::critical("ruby execution failure: {}", StringValuePtr(rbError));
|
33
|
+
exit(EXIT_FAILURE);
|
34
|
+
}
|
36
35
|
}
|
37
36
|
|
38
37
|
int
|
39
38
|
main()
|
40
39
|
{
|
41
|
-
|
42
|
-
|
43
|
-
|
40
|
+
ruby_init();
|
41
|
+
ruby_init_loadpath();
|
42
|
+
|
43
|
+
rb_require(LIBCOUCHBASE_EXT_PATH);
|
44
|
+
run_script(R"(
|
45
|
+
p Couchbase::VERSION
|
46
|
+
)");
|
44
47
|
|
45
|
-
|
48
|
+
run_script(R"(
|
49
|
+
B = Couchbase::Backend.new
|
50
|
+
#B.open("192.168.42.101", "Administrator", "password")
|
51
|
+
B.open("localhost", "Administrator", "password")
|
52
|
+
)");
|
46
53
|
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
54
|
+
run_script(R"(
|
55
|
+
p B.open_bucket("default")
|
56
|
+
p B.document_increment("default", "_default._default", "foo", {:initial_value => 32, :expiration => 42})
|
57
|
+
p B.document_get("default", "_default._default", "foo")
|
58
|
+
p B.document_decrement("default", "_default._default", "foo", {:initial_value => 32, :expiration => 42})
|
59
|
+
)");
|
52
60
|
|
53
|
-
|
54
|
-
|
61
|
+
run_script(R"(
|
62
|
+
B.close
|
63
|
+
)");
|
55
64
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
cluster.execute(req, [&](couchbase::operations::query_response resp) {
|
60
|
-
spdlog::info("QUERY {}: ec={}, body={}",
|
61
|
-
couchbase::uuid::to_string(resp.client_context_id),
|
62
|
-
resp.ec.message(),
|
63
|
-
resp.payload.meta_data.metrics.result_size);
|
64
|
-
for (auto &r : resp.payload.rows) {
|
65
|
-
spdlog::info("ROW: {}", r);
|
66
|
-
}
|
67
|
-
if (resp.payload.meta_data.profile) {
|
68
|
-
spdlog::info("PROFILE: {}", *resp.payload.meta_data.profile);
|
69
|
-
}
|
70
|
-
cluster.close();
|
71
|
-
});
|
72
|
-
#if 0
|
73
|
-
cluster.open_bucket(bucket_name, [&](std::error_code ec2) {
|
74
|
-
if (!ec2) {
|
75
|
-
couchbase::operations::mutate_in_request req{
|
76
|
-
couchbase::operations::document_id{ bucket_name, collection_name, "foo" },
|
77
|
-
};
|
78
|
-
req.specs.add_spec(couchbase::protocol::subdoc_opcode::dict_upsert, false, false, false, "test", R"({"name":"sergey"})");
|
79
|
-
req.specs.add_spec(couchbase::protocol::subdoc_opcode::counter, false, false, false,"num", 24);
|
80
|
-
cluster.execute(req, [&](couchbase::operations::mutate_in_response resp) {
|
81
|
-
spdlog::info("MUTATE_IN {}: ec={}, cas={}, fields={}", resp.id, resp.ec.message(), resp.cas, resp.fields.size());
|
82
|
-
size_t idx = 0;
|
83
|
-
for (const auto& field : resp.fields) {
|
84
|
-
spdlog::info(" {}. {}: {} {}", idx++, field.path, field.status, field.value);
|
85
|
-
}
|
86
|
-
// if (done()) {
|
87
|
-
cluster.close();
|
88
|
-
//}
|
89
|
-
});
|
90
|
-
couchbase::operations::lookup_in_request req{
|
91
|
-
couchbase::operations::document_id{ bucket_name, collection_name, "foo" },
|
92
|
-
};
|
93
|
-
req.access_deleted = true;
|
94
|
-
req.specs.add_spec(couchbase::protocol::subdoc_opcode::get, true, "$document");
|
95
|
-
req.specs.add_spec(couchbase::protocol::subdoc_opcode::exists, false, "bar");
|
96
|
-
req.specs.add_spec(couchbase::protocol::subdoc_opcode::get, false, "foo");
|
97
|
-
cluster.execute(req, [&](couchbase::operations::lookup_in_response resp) {
|
98
|
-
spdlog::info("LOOKUP_IN {}: ec={}, cas={}, fields={}", resp.id, resp.ec.message(), resp.cas, resp.fields.size());
|
99
|
-
size_t idx = 0;
|
100
|
-
for (const auto &field : resp.fields) {
|
101
|
-
spdlog::info(" {}. {}{}: {}", idx++, field.path, field.exists ? "(hit) " : "(miss)", field.value);
|
102
|
-
}
|
103
|
-
//if (done()) {
|
104
|
-
cluster.close();
|
105
|
-
//}
|
106
|
-
});
|
107
|
-
cluster.execute(
|
108
|
-
couchbase::operations::get_request{
|
109
|
-
couchbase::operations::document_id{ bucket_name, collection_name, "foo" },
|
110
|
-
},
|
111
|
-
[&](couchbase::operations::get_response resp) {
|
112
|
-
spdlog::info("GET {}: ec={}, cas={}\n{}", resp.id, resp.ec.message(), resp.cas, resp.value);
|
113
|
-
if (done()) {
|
114
|
-
cluster.close();
|
115
|
-
}
|
116
|
-
});
|
117
|
-
cluster.execute(
|
118
|
-
couchbase::operations::get_request{
|
119
|
-
couchbase::operations::document_id{ bucket_name, collection_name, "bar" },
|
120
|
-
},
|
121
|
-
[&](couchbase::operations::get_response resp) {
|
122
|
-
spdlog::info("GET {}: ec={}, cas={}\n{}", resp.id, resp.ec.message(), resp.cas, resp.value);
|
123
|
-
if (done()) {
|
124
|
-
cluster.close();
|
125
|
-
}
|
126
|
-
});
|
127
|
-
cluster.execute(
|
128
|
-
couchbase::operations::upsert_request{ couchbase::operations::document_id{ bucket_name, collection_name, "foo" },
|
129
|
-
"{\"prop\":42}" },
|
130
|
-
[&](couchbase::operations::upsert_response resp) {
|
131
|
-
spdlog::info("UPSERT {}: ec={}, cas={}", resp.id, resp.ec.message(), resp.cas);
|
132
|
-
if (done()) {
|
133
|
-
cluster.close();
|
134
|
-
}
|
135
|
-
});
|
136
|
-
} else {
|
137
|
-
spdlog::info("unable to open the bucket: {}", ec2.message());
|
138
|
-
}
|
139
|
-
});
|
140
|
-
#endif
|
141
|
-
});
|
142
|
-
ctx.run();
|
143
|
-
}
|
65
|
+
ruby_finalize();
|
66
|
+
return 0;
|
67
|
+
}
|