@based/db 0.0.30 → 0.0.32

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/README.md +565 -3
  2. package/dist/lib/darwin_aarch64/include/selva/db.h +3 -2
  3. package/dist/lib/darwin_aarch64/include/selva/fields.h +10 -7
  4. package/dist/lib/darwin_aarch64/include/selva/types.h +3 -1
  5. package/dist/lib/darwin_aarch64/libdeflate.dylib +0 -0
  6. package/dist/lib/darwin_aarch64/libjemalloc_selva.2.dylib +0 -0
  7. package/dist/lib/darwin_aarch64/libnode-v20.node +0 -0
  8. package/dist/lib/darwin_aarch64/libselva.dylib +0 -0
  9. package/dist/src/client/flushModify.d.ts +1 -1
  10. package/dist/src/client/flushModify.js +5 -4
  11. package/dist/src/client/index.d.ts +3 -2
  12. package/dist/src/client/modify/binary.js +1 -1
  13. package/dist/src/client/modify/cardinality.js +1 -1
  14. package/dist/src/client/modify/references/appendEdgeRefs.js +3 -0
  15. package/dist/src/client/modify/references/edge.js +6 -0
  16. package/dist/src/client/modify/references/getEdgeSize.js +1 -1
  17. package/dist/src/client/modify/string.js +10 -4
  18. package/dist/src/client/modify/text.js +1 -9
  19. package/dist/src/client/modify/types.d.ts +1 -0
  20. package/dist/src/client/modify/types.js +1 -0
  21. package/dist/src/client/modify/upsert.js +33 -21
  22. package/dist/src/client/query/BasedDbQuery.js +1 -1
  23. package/dist/src/client/query/BasedIterable.d.ts +2 -2
  24. package/dist/src/client/query/BasedIterable.js +7 -1
  25. package/dist/src/client/query/aggregates/aggregation.d.ts +4 -0
  26. package/dist/src/client/query/aggregates/aggregation.js +12 -0
  27. package/dist/src/client/query/aggregation.d.ts +1 -1
  28. package/dist/src/client/query/debug.js +3 -2
  29. package/dist/src/client/query/display.js +1 -1
  30. package/dist/src/client/query/filter/createFixedFilterBuffer.js +1 -1
  31. package/dist/src/client/query/filter/createVariableFilterBuffer.js +1 -1
  32. package/dist/src/client/query/filter/parseFilterValue.js +1 -2
  33. package/dist/src/client/query/queryDef.js +2 -2
  34. package/dist/src/client/query/read/read.js +4 -14
  35. package/dist/src/client/query/registerQuery.js +1 -1
  36. package/dist/src/client/query/search/index.d.ts +1 -1
  37. package/dist/src/client/query/search/index.js +1 -1
  38. package/dist/src/client/query/sort.d.ts +1 -1
  39. package/dist/src/client/query/toBuffer.js +11 -15
  40. package/dist/src/client/query/types.d.ts +7 -0
  41. package/dist/src/client/query/types.js +8 -0
  42. package/dist/src/client/query/validation.d.ts +1 -1
  43. package/dist/src/client/query/validation.js +4 -5
  44. package/dist/src/client/string.js +1 -3
  45. package/dist/src/client/xxHash64.d.ts +1 -1
  46. package/dist/src/index.d.ts +1 -0
  47. package/dist/src/index.js +31 -3
  48. package/dist/src/native.d.ts +1 -2
  49. package/dist/src/native.js +2 -5
  50. package/dist/src/server/csmt/draw-dot.d.ts +3 -1
  51. package/dist/src/server/csmt/draw-dot.js +7 -2
  52. package/dist/src/server/csmt/match.d.ts +1 -1
  53. package/dist/src/server/csmt/memebership-proof.d.ts +1 -1
  54. package/dist/src/server/csmt/tree-utils.d.ts +4 -4
  55. package/dist/src/server/csmt/tree.d.ts +1 -1
  56. package/dist/src/server/csmt/tree.js +1 -1
  57. package/dist/src/server/csmt/types.d.ts +10 -10
  58. package/dist/src/server/dbHash.d.ts +1 -1
  59. package/dist/src/server/dbHash.js +1 -1
  60. package/dist/src/server/index.d.ts +8 -4
  61. package/dist/src/server/index.js +28 -13
  62. package/dist/src/server/migrate/worker.js +11 -0
  63. package/dist/src/server/save.js +4 -6
  64. package/dist/src/server/start.js +17 -11
  65. package/dist/src/server/tree.d.ts +1 -1
  66. package/dist/src/server/tree.js +2 -2
  67. package/dist/src/utils.d.ts +0 -10
  68. package/dist/src/utils.js +0 -152
  69. package/package.json +3 -3
  70. package/dist/lib/darwin_aarch64/include/selva/xxhash64.h +0 -23
  71. package/dist/lib/darwin_aarch64/libnode-v21.node +0 -0
  72. package/dist/lib/darwin_aarch64/libnode-v22.node +0 -0
  73. package/dist/lib/darwin_aarch64/libnode-v23.node +0 -0
  74. package/dist/lib/linux_aarch64/include/cdefs.h +0 -317
  75. package/dist/lib/linux_aarch64/include/jemalloc.h +0 -468
  76. package/dist/lib/linux_aarch64/include/libdeflate.h +0 -322
  77. package/dist/lib/linux_aarch64/include/libdeflate_strings.h +0 -35
  78. package/dist/lib/linux_aarch64/include/linker_set.h +0 -109
  79. package/dist/lib/linux_aarch64/include/queue.h +0 -627
  80. package/dist/lib/linux_aarch64/include/selva/_export.h +0 -7
  81. package/dist/lib/linux_aarch64/include/selva/align.h +0 -9
  82. package/dist/lib/linux_aarch64/include/selva/backoff_timeout.h +0 -29
  83. package/dist/lib/linux_aarch64/include/selva/bitmap.h +0 -95
  84. package/dist/lib/linux_aarch64/include/selva/crc32c.h +0 -17
  85. package/dist/lib/linux_aarch64/include/selva/ctime.h +0 -135
  86. package/dist/lib/linux_aarch64/include/selva/db.h +0 -417
  87. package/dist/lib/linux_aarch64/include/selva/endian.h +0 -301
  88. package/dist/lib/linux_aarch64/include/selva/fast_linear_search.h +0 -23
  89. package/dist/lib/linux_aarch64/include/selva/fast_memcmp.h +0 -18
  90. package/dist/lib/linux_aarch64/include/selva/fast_memmem.h +0 -11
  91. package/dist/lib/linux_aarch64/include/selva/fast_parsei.h +0 -36
  92. package/dist/lib/linux_aarch64/include/selva/fields.h +0 -378
  93. package/dist/lib/linux_aarch64/include/selva/find.h +0 -47
  94. package/dist/lib/linux_aarch64/include/selva/history.h +0 -64
  95. package/dist/lib/linux_aarch64/include/selva/hll.h +0 -81
  96. package/dist/lib/linux_aarch64/include/selva/lpf.h +0 -28
  97. package/dist/lib/linux_aarch64/include/selva/node_id_set.h +0 -43
  98. package/dist/lib/linux_aarch64/include/selva/poptop.h +0 -114
  99. package/dist/lib/linux_aarch64/include/selva/queue_r.h +0 -190
  100. package/dist/lib/linux_aarch64/include/selva/selva_hash128.h +0 -49
  101. package/dist/lib/linux_aarch64/include/selva/selva_lang.h +0 -105
  102. package/dist/lib/linux_aarch64/include/selva/selva_math.h +0 -37
  103. package/dist/lib/linux_aarch64/include/selva/selva_string.h +0 -674
  104. package/dist/lib/linux_aarch64/include/selva/sort.h +0 -140
  105. package/dist/lib/linux_aarch64/include/selva/strsearch.h +0 -43
  106. package/dist/lib/linux_aarch64/include/selva/timestamp.h +0 -25
  107. package/dist/lib/linux_aarch64/include/selva/traverse.h +0 -65
  108. package/dist/lib/linux_aarch64/include/selva/types.h +0 -104
  109. package/dist/lib/linux_aarch64/include/selva/vector.h +0 -35
  110. package/dist/lib/linux_aarch64/include/selva/worker_ctx.h +0 -13
  111. package/dist/lib/linux_aarch64/include/selva/xxhash64.h +0 -23
  112. package/dist/lib/linux_aarch64/include/selva_error.h +0 -137
  113. package/dist/lib/linux_aarch64/include/selva_lang_code.h +0 -157
  114. package/dist/lib/linux_aarch64/include/tree.h +0 -852
  115. package/dist/lib/linux_aarch64/libdeflate.so +0 -0
  116. package/dist/lib/linux_aarch64/libjemalloc_selva.so.2 +0 -0
  117. package/dist/lib/linux_aarch64/libnode-v20.node +0 -0
  118. package/dist/lib/linux_aarch64/libnode-v21.node +0 -0
  119. package/dist/lib/linux_aarch64/libnode-v22.node +0 -0
  120. package/dist/lib/linux_aarch64/libnode-v23.node +0 -0
  121. package/dist/lib/linux_aarch64/libselva.so +0 -0
  122. package/dist/lib/linux_aarch64/libxxhash.so.0 +0 -0
  123. package/dist/lib/linux_x86_64/include/cdefs.h +0 -317
  124. package/dist/lib/linux_x86_64/include/jemalloc.h +0 -468
  125. package/dist/lib/linux_x86_64/include/libdeflate.h +0 -322
  126. package/dist/lib/linux_x86_64/include/libdeflate_strings.h +0 -35
  127. package/dist/lib/linux_x86_64/include/linker_set.h +0 -109
  128. package/dist/lib/linux_x86_64/include/queue.h +0 -627
  129. package/dist/lib/linux_x86_64/include/selva/_export.h +0 -7
  130. package/dist/lib/linux_x86_64/include/selva/align.h +0 -9
  131. package/dist/lib/linux_x86_64/include/selva/backoff_timeout.h +0 -29
  132. package/dist/lib/linux_x86_64/include/selva/bitmap.h +0 -95
  133. package/dist/lib/linux_x86_64/include/selva/crc32c.h +0 -17
  134. package/dist/lib/linux_x86_64/include/selva/ctime.h +0 -135
  135. package/dist/lib/linux_x86_64/include/selva/db.h +0 -417
  136. package/dist/lib/linux_x86_64/include/selva/endian.h +0 -301
  137. package/dist/lib/linux_x86_64/include/selva/fast_linear_search.h +0 -23
  138. package/dist/lib/linux_x86_64/include/selva/fast_memcmp.h +0 -18
  139. package/dist/lib/linux_x86_64/include/selva/fast_memmem.h +0 -11
  140. package/dist/lib/linux_x86_64/include/selva/fast_parsei.h +0 -36
  141. package/dist/lib/linux_x86_64/include/selva/fields.h +0 -378
  142. package/dist/lib/linux_x86_64/include/selva/find.h +0 -47
  143. package/dist/lib/linux_x86_64/include/selva/history.h +0 -64
  144. package/dist/lib/linux_x86_64/include/selva/hll.h +0 -81
  145. package/dist/lib/linux_x86_64/include/selva/lpf.h +0 -28
  146. package/dist/lib/linux_x86_64/include/selva/node_id_set.h +0 -43
  147. package/dist/lib/linux_x86_64/include/selva/poptop.h +0 -114
  148. package/dist/lib/linux_x86_64/include/selva/queue_r.h +0 -190
  149. package/dist/lib/linux_x86_64/include/selva/selva_hash128.h +0 -49
  150. package/dist/lib/linux_x86_64/include/selva/selva_lang.h +0 -105
  151. package/dist/lib/linux_x86_64/include/selva/selva_math.h +0 -37
  152. package/dist/lib/linux_x86_64/include/selva/selva_string.h +0 -674
  153. package/dist/lib/linux_x86_64/include/selva/sort.h +0 -140
  154. package/dist/lib/linux_x86_64/include/selva/strsearch.h +0 -43
  155. package/dist/lib/linux_x86_64/include/selva/timestamp.h +0 -25
  156. package/dist/lib/linux_x86_64/include/selva/traverse.h +0 -65
  157. package/dist/lib/linux_x86_64/include/selva/types.h +0 -104
  158. package/dist/lib/linux_x86_64/include/selva/vector.h +0 -35
  159. package/dist/lib/linux_x86_64/include/selva/worker_ctx.h +0 -13
  160. package/dist/lib/linux_x86_64/include/selva/xxhash64.h +0 -23
  161. package/dist/lib/linux_x86_64/include/selva_error.h +0 -137
  162. package/dist/lib/linux_x86_64/include/selva_lang_code.h +0 -157
  163. package/dist/lib/linux_x86_64/include/tree.h +0 -852
  164. package/dist/lib/linux_x86_64/libdeflate.so +0 -0
  165. package/dist/lib/linux_x86_64/libjemalloc_selva.so.2 +0 -0
  166. package/dist/lib/linux_x86_64/libnode-v20.node +0 -0
  167. package/dist/lib/linux_x86_64/libnode-v21.node +0 -0
  168. package/dist/lib/linux_x86_64/libnode-v22.node +0 -0
  169. package/dist/lib/linux_x86_64/libnode-v23.node +0 -0
  170. package/dist/lib/linux_x86_64/libselva.so +0 -0
  171. package/dist/lib/linux_x86_64/libxxhash.so.0 +0 -0
  172. package/dist/src/client/query/subscription/markers.d.ts +0 -10
  173. package/dist/src/client/query/subscription/markers.js +0 -213
  174. package/dist/src/client/query/subscription/run.d.ts +0 -5
  175. package/dist/src/client/query/subscription/run.js +0 -76
@@ -1,674 +0,0 @@
1
- /*
2
- * Copyright (c) 2022-2025 SAULX
3
- * SPDX-License-Identifier: MIT
4
- */
5
- #pragma once
6
-
7
- #include <stdint.h>
8
- #include <sys/types.h>
9
- #include "selva/_export.h"
10
-
11
- struct finalizer;
12
- struct selva_string;
13
-
14
- /**
15
- * Selva string flags.
16
- */
17
- enum selva_string_flags {
18
- /**
19
- * CRC enabled.
20
- * For compressed string this is for the uncompressed string.
21
- */
22
- SELVA_STRING_CRC = 0x01,
23
- /**
24
- * Permanently shared string; Shouldn't be freed.
25
- */
26
- SELVA_STRING_FREEZE = 0x02,
27
- /**
28
- * A mutable string.
29
- */
30
- SELVA_STRING_MUTABLE = 0x04,
31
- /**
32
- * Fixed size mutable string.
33
- * Mutable only with selva_string_replace() and selva_string_to_mstr().
34
- */
35
- SELVA_STRING_MUTABLE_FIXED = 0x08,
36
- /**
37
- * Static string.
38
- * The selva_string structure is not allocated by selva_string.
39
- */
40
- SELVA_STRING_STATIC = 0x10,
41
- /**
42
- * Compressed string.
43
- */
44
- SELVA_STRING_COMPRESS = 0x20,
45
- SELVA_STRING_LEN_PARITY = 0x80,
46
- } __packed;
47
-
48
- #define INVALID_FLAGS_MASK (~(SELVA_STRING_CRC | SELVA_STRING_FREEZE | SELVA_STRING_MUTABLE | SELVA_STRING_MUTABLE_FIXED | SELVA_STRING_STATIC | SELVA_STRING_COMPRESS | SELVA_STRING_LEN_PARITY))
49
-
50
- /**
51
- * Header before compressed string.
52
- * This is stored just before the actual string.
53
- * Currently the compression used is raw DEFLATE.
54
- */
55
- struct selva_string_compressed_hdr {
56
- /* TODO uint8_t type header here. */
57
- /**
58
- * Uncompressed size of the string.
59
- */
60
- uint32_t uncompressed_size;
61
- } __packed;
62
-
63
- #define SELVA_STRING_STRUCT_SIZE 16
64
- #ifndef __zig
65
- struct selva_string {
66
- struct {
67
- uint64_t len: 56;
68
- enum selva_string_flags flags: 8;
69
- };
70
- /* Don't add __counted_by(len) here because it's not the real size. */
71
- union {
72
- char *p;
73
- char emb[sizeof(char *)];
74
- };
75
- };
76
- static_assert(sizeof(struct selva_string) == SELVA_STRING_STRUCT_SIZE);
77
-
78
- #define SELVA_STRING_STATIC_BUF_SIZE(len) \
79
- (((len + 1) < sizeof(char *)) ? 0 : len + 1 - sizeof(char *))
80
-
81
- #define SELVA_STRING_STATIC_BUF_SIZE_WCRC(len) \
82
- (((len + 1 + sizeof(uint32_t)) < sizeof(char *)) ? 0 : len + 1 - sizeof(char *) + sizeof(uint32_t))
83
-
84
- #define SELVA_STRING_STATIC_S(name, len) \
85
- struct { \
86
- struct selva_string name; \
87
- char name ## buf[SELVA_STRING_STATIC_BUF_SIZE(len)]; \
88
- }
89
-
90
- #define SELVA_STRING_STATIC_S_WCRC(name, len) \
91
- struct { \
92
- struct selva_string name; \
93
- char name ## buf[SELVA_STRING_STATIC_BUF_SIZE_WCRC(len)]; \
94
- }
95
- #endif
96
-
97
- void selva_string_init_tls(void);
98
- void selva_string_deinit_tls(void);
99
-
100
- /**
101
- * Initialize a statically allocated selva_string.
102
- * Note that the string buffer doesn't need to be statically allocated, just the struct.
103
- * The `SELVA_STRING_STATIC` macro should be used to also allocate the buffer statically
104
- * with a fixed size.
105
- * If `SELVA_STRING_MUTABLE_FIXED` is given then the buffer following the string must be large
106
- * enough.
107
- * @param str can be NULL if a mutable flag is set.
108
- */
109
- SELVA_EXPORT
110
- int selva_string_init(struct selva_string *s, const char *str, size_t len, enum selva_string_flags flags);
111
-
112
-
113
- /**
114
- * Same as selva_string_init() but with a precalculated CRC32-C.
115
- */
116
- SELVA_EXPORT
117
- int selva_string_init_crc(struct selva_string *s, const char *str, size_t len, uint32_t crc, enum selva_string_flags flags);
118
-
119
- /**
120
- * Create a new string.
121
- * @param str can be NULL.
122
- */
123
- [[nodiscard]]
124
- SELVA_EXPORT
125
- struct selva_string *selva_string_create(const char *str, size_t len, enum selva_string_flags flags)
126
- __attribute__((access(read_only, 1)));
127
-
128
- /**
129
- * Create a new string with a user provided CRC.
130
- * @param str can be NULL.
131
- */
132
- SELVA_EXPORT
133
- struct selva_string *selva_string_create_crc(const char *str, size_t len, enum selva_string_flags flags, uint32_t crc)
134
- __attribute__((access(read_only, 1, 2)));
135
-
136
- /**
137
- * Create a string using a printf format string.
138
- */
139
- [[nodiscard]]
140
- SELVA_EXPORT
141
- struct selva_string *selva_string_createf(const char *fmt, ...)
142
- __attribute__((format(printf, 1, 2)));
143
-
144
- #if defined(_STDIO_H) || defined(_STDIO_H_)
145
- /**
146
- * Read a string from a file directly into a new selva_string.
147
- * If the resulting string is shorter than `size` an errno is set. Use the
148
- * ferror() and feof() functions to distinguish between a read error and an
149
- * end-of-file.
150
- * @param flags can be SELVA_STRING_CRC | SELVA_STRING_COMPRESS.
151
- */
152
- [[nodiscard]]
153
- SELVA_EXPORT
154
- struct selva_string *selva_string_fread(FILE *fp, size_t size, enum selva_string_flags flags);
155
- #endif
156
-
157
- /**
158
- * Create a compressed string.
159
- * Note that most of the selva_string functions don't know how to handle with
160
- * compressed strings and will just assume it's a regular string.
161
- * @param flags Compressed strings can't handle most of the flags but notably
162
- * SELVA_STRING_CRC is supported.
163
- */
164
- [[nodiscard]]
165
- SELVA_EXPORT
166
- struct selva_string *selva_string_createz(const char *in_str, size_t in_len, enum selva_string_flags flags)
167
- __attribute__((access(read_only, 1, 2)));
168
-
169
- /**
170
- * Decompress a compressed string.
171
- * @param s is a pointer to a compressed selva_string.
172
- * @param buf is the destination where the decompressed string will be copied to.
173
- * The size of the buffer must be at least selva_string_getz_ulen(s) bytes.
174
- * @returns 0 if succeeded;
175
- * SELVA_PROTO_EINTYPE if not a compressed string;
176
- * SELVA_EINVAL if the string cannot be decompressed.
177
- */
178
- SELVA_EXPORT
179
- int selva_string_decompress(const struct selva_string * restrict s, char * restrict buf)
180
- __attribute__((access(read_only, 1), access(write_only, 2)));
181
-
182
- /**
183
- * Duplicate a string.
184
- * @param s is a pointer to a selva_string.
185
- */
186
- [[nodiscard]]
187
- SELVA_EXPORT
188
- struct selva_string *selva_string_dup(const struct selva_string *s, enum selva_string_flags flags)
189
- __attribute__((access(read_only, 1)));
190
-
191
- /**
192
- * Truncate the string s to a new length of newlen.
193
- * @param s is a pointer to a selva_string. Must be mutable.
194
- * @param newlen is the new length of the string.
195
- * @returns 0 if succeeded; Otherwise an error code.
196
- */
197
- SELVA_EXPORT
198
- int selva_string_truncate(struct selva_string *s, size_t newlen)
199
- __attribute__((access(read_write, 1)));
200
-
201
- /**
202
- * Append str of length len to the string s.
203
- * @param s is a pointer to a selva_string. Must be mutable.
204
- * @returns 0 if succeeded; Otherwise an error code.
205
- */
206
- SELVA_EXPORT
207
- int selva_string_append(struct selva_string *s, const char *str, size_t len)
208
- __attribute__((access(read_only, 2)));
209
-
210
- /**
211
- * Replace current value of the string s with str.
212
- * @param s must be mutable.
213
- * @returns 0 if succeeded; Otherwise an error code.
214
- */
215
- SELVA_EXPORT
216
- int selva_string_replace(struct selva_string *s, const char *str, size_t len)
217
- __attribute__((access(read_only, 2, 3)));
218
-
219
- /**
220
- * Replace current value of the string s with str and an externally computed crc.
221
- * @param s must be mutable.
222
- * @returns 0 if succeeded; Otherwise an error code.
223
- */
224
- SELVA_EXPORT
225
- int selva_string_replace_crc(struct selva_string *s, const char *str, size_t len, uint32_t crc)
226
- __attribute__((access(read_only, 2, 3)));
227
-
228
- /**
229
- * Allows selva_string_free() to be passed to finalizer_add() and other similar
230
- * functions accepting void functions.
231
- */
232
- typedef union {
233
- struct selva_string *__s;
234
- void *__p;
235
- } _selva_string_ptr_t __transparent_union;
236
-
237
-
238
- /**
239
- * Free the strings s.
240
- * @param s is a pointer to a selva_string.
241
- */
242
- SELVA_EXPORT
243
- void selva_string_free(_selva_string_ptr_t s);
244
-
245
- /**
246
- * Add a selva_string to the given finalizer.
247
- * @param finalizer is a pointer to a finalizer.
248
- * @param s is a pointer to a selva_string.
249
- */
250
- SELVA_EXPORT
251
- void selva_string_auto_finalize(struct finalizer *finalizer, struct selva_string *s);
252
-
253
- /**
254
- * Get the currently set flags of the string s.
255
- * @param s is a pointer to a selva_string.
256
- */
257
- SELVA_EXPORT
258
- enum selva_string_flags selva_string_get_flags(const struct selva_string *s)
259
- __attribute__((access(read_only, 1)));
260
-
261
- /**
262
- * Get string length.
263
- * If the string is compressed then the length returned is the compressed
264
- * length including any metadata related to the compression algorithm.
265
- */
266
- SELVA_EXPORT
267
- size_t selva_string_get_len(const struct selva_string *s)
268
- __attribute__((access(read_only, 1)));
269
-
270
- /**
271
- * Get uncompressed length.
272
- * The function will return the right size regardless whether the string is
273
- * actually compressed.
274
- */
275
- SELVA_EXPORT
276
- size_t selva_string_getz_ulen(const struct selva_string *s)
277
- __attribute__((access(read_only, 1)));
278
-
279
- /**
280
- * Get compression ratio.
281
- */
282
- SELVA_EXPORT
283
- double selva_string_getz_cratio(const struct selva_string *s)
284
- __attribute__((access(read_only, 1)));
285
-
286
- /**
287
- * Get the raw buffer including CRC.
288
- */
289
- SELVA_EXPORT
290
- const uint8_t *selva_string_to_buf(const struct selva_string *s, size_t *size)
291
- __attribute__((access(write_only, 2)));
292
-
293
- /**
294
- * Get a pointer to the contained C-string.
295
- * If the string is compressed then the compressed string is returned.
296
- * selva_string_decompress() can be used to retrieve the original string.
297
- * @param s is a pointer to a selva_string.
298
- * @param[out] len is a pointer to a variable to store the length of s.
299
- * @retruns Returns a pointer to the C-string.
300
- */
301
- SELVA_EXPORT
302
- const char *selva_string_to_str(const struct selva_string *s, size_t *len)
303
- __attribute__((access(write_only, 2)));
304
-
305
- /**
306
- * Get a pointer to the mutable C-string.
307
- * @param s is a pointer to a selva_string.
308
- * @param[out] len is a pointer to a variable to store the length of s.
309
- * @returns Returns a pointer to the C-string if the string is mutable; Otherwise a NULL pointer is returned.
310
- */
311
- SELVA_EXPORT
312
- char *selva_string_to_mstr(struct selva_string *s, size_t *len)
313
- __attribute__((access(write_only, 2)));
314
-
315
- /**
316
- * Convert a string into a long long integer.
317
- */
318
- SELVA_EXPORT
319
- int selva_string_to_ll(const struct selva_string *s, long long *ll)
320
- __attribute__((access(write_only, 2)));
321
-
322
- /**
323
- * Convert a string into an unsigned long long integer.
324
- */
325
- SELVA_EXPORT
326
- int selva_string_to_ull(const struct selva_string *s, unsigned long long *ull)
327
- __attribute__((access(write_only, 2)));
328
-
329
- /**
330
- * Convert a string into a float.
331
- */
332
- SELVA_EXPORT
333
- int selva_string_to_float(const struct selva_string *s, float *f)
334
- __attribute__((access(write_only, 2)));
335
-
336
- /**
337
- * Convert a string into a double.
338
- */
339
- SELVA_EXPORT
340
- int selva_string_to_double(const struct selva_string *s, double *d)
341
- __attribute__((access(write_only, 2)));
342
-
343
- /**
344
- * Convert a string into a long double.
345
- */
346
- SELVA_EXPORT
347
- int selva_string_to_ldouble(const struct selva_string *s, long double *ld)
348
- __attribute__((access(write_only, 2)));
349
-
350
- /**
351
- * Freeze the string s in memory.
352
- * Freezing a string allows sharing it in memory between multiple users and
353
- * disallows freeing it until the program exits.
354
- * This function can be called even if the string is immutable.
355
- * @param s is a pointer to a selva_string.
356
- */
357
- SELVA_EXPORT
358
- void selva_string_freeze(struct selva_string *s)
359
- __attribute((access(read_write, 1)));
360
-
361
- /**
362
- * Verify the CRC of the string s.
363
- * If the string is compressed the CRC is computed from the compressed data.
364
- * @param s is a pointer to a selva_string.
365
- */
366
- SELVA_EXPORT
367
- int selva_string_verify_crc(const struct selva_string *s)
368
- __attribute((access(read_only, 1)));
369
-
370
- /**
371
- * Get the CRC of the string s.
372
- */
373
- SELVA_EXPORT
374
- uint32_t selva_string_get_crc(const struct selva_string *s)
375
- __attribute((access(read_only, 1)));
376
-
377
- SELVA_EXPORT
378
- void selva_string_set_crc(struct selva_string *s, uint32_t csum);
379
-
380
- /**
381
- * Set SELVA_STRING_COMPRESS flag on an existing string.
382
- * Setting the flag won't compress the string but mark it as compressed;
383
- * i.e. it's only a metadata update.
384
- * This function should be used if you know that you have a selva_string
385
- * that has been marked as uncompressed but it actually contains data that
386
- * the selva_string compression utility will recognize properly. Usually
387
- * meaning that the data was originally compressed using selva_string.
388
- */
389
- SELVA_EXPORT
390
- void selva_string_set_compress(struct selva_string *s)
391
- __attribute__((access(read_write, 1)));
392
-
393
- /**
394
- * Compare two strings.
395
- * This function works correctly with compressed strings.
396
- * @param a is a pointer to the first string to be compared.
397
- * @param b is a pointer to the second strings to be compared.
398
- * @returns < 0 if the first character that does not match has a lower value in ptr1 than in ptr2;
399
- * 0 if the contents of both strings are equal;
400
- * > 0 if the first character that does not match has a greater value in ptr1 than in ptr2.
401
- */
402
- SELVA_EXPORT
403
- int selva_string_cmp(const struct selva_string *a, const struct selva_string *b)
404
- __attribute__((access(read_only, 1), access(read_only, 2)));
405
-
406
- /**
407
- * Test if a string ends with suffix.
408
- * This function works correctly with compressed strings.
409
- */
410
- SELVA_EXPORT
411
- int selva_string_endswith(const struct selva_string *s, const char *suffix)
412
- __attribute__((access(read_only, 1), access(read_only, 2)));
413
-
414
- #define TO_STR_1(_var) \
415
- size_t _var##_len; \
416
- const char * _var##_str = selva_string_to_str(_var, & _var##_len);
417
-
418
- #define TO_STR_2(_var, ...) \
419
- TO_STR_1(_var) \
420
- TO_STR_1(__VA_ARGS__)
421
-
422
- #define TO_STR_3(_var, ...) \
423
- TO_STR_1(_var) \
424
- TO_STR_2(__VA_ARGS__)
425
-
426
- #define TO_STR_4(_var, ...) \
427
- TO_STR_1(_var) \
428
- TO_STR_3(__VA_ARGS__)
429
-
430
- #define TO_STR_5(_var, ...) \
431
- TO_STR_1(_var) \
432
- TO_STR_4(__VA_ARGS__)
433
-
434
- #define TO_STR_6(_var, ...) \
435
- TO_STR_1(_var) \
436
- TO_STR_5(__VA_ARGS__)
437
-
438
- #define TO_STR_7(_var, ...) \
439
- TO_STR_1(_var) \
440
- TO_STR_6(__VA_ARGS__)
441
-
442
- #define TO_STR_8(_var, ...) \
443
- TO_STR_1(_var) \
444
- TO_STR_7(__VA_ARGS__)
445
-
446
- #define TO_STR_9(_var, ...) \
447
- TO_STR_1(_var) \
448
- TO_STR_7(__VA_ARGS__)
449
-
450
- #define TO_STR_10(_var, ...) \
451
- TO_STR_1(_var) \
452
- TO_STR_9(__VA_ARGS__)
453
-
454
- #define TO_STR_11(_var, ...) \
455
- TO_STR_1(_var) \
456
- TO_STR_10(__VA_ARGS__)
457
-
458
- #define TO_STR_12(_var, ...) \
459
- TO_STR_1(_var) \
460
- TO_STR_11(__VA_ARGS__)
461
-
462
- #define TO_STR_13(_var, ...) \
463
- TO_STR_1(_var) \
464
- TO_STR_12(__VA_ARGS__)
465
-
466
- #define TO_STR_14(_var, ...) \
467
- TO_STR_1(_var) \
468
- TO_STR_13(__VA_ARGS__)
469
-
470
- #define TO_STR_15(_var, ...) \
471
- TO_STR_1(_var) \
472
- TO_STR_14(__VA_ARGS__)
473
-
474
- #define TO_STR_16(_var, ...) \
475
- TO_STR_1(_var) \
476
- TO_STR_15(__VA_ARGS__)
477
-
478
- #define TO_STR_17(_var, ...) \
479
- TO_STR_1(_var) \
480
- TO_STR_16(__VA_ARGS__)
481
-
482
- #define TO_STR_18(_var, ...) \
483
- TO_STR_1(_var) \
484
- TO_STR_17(__VA_ARGS__)
485
-
486
- #define TO_STR_19(_var, ...) \
487
- TO_STR_1(_var) \
488
- TO_STR_18(__VA_ARGS__)
489
-
490
- #define TO_STR_20(_var, ...) \
491
- TO_STR_1(_var) \
492
- TO_STR_19(__VA_ARGS__)
493
-
494
- #define TO_STR_21(_var, ...) \
495
- TO_STR_1(_var) \
496
- TO_STR_20(__VA_ARGS__)
497
-
498
- #define TO_STR_22(_var, ...) \
499
- TO_STR_1(_var) \
500
- TO_STR_21(__VA_ARGS__)
501
-
502
- #define TO_STR_23(_var, ...) \
503
- TO_STR_1(_var) \
504
- TO_STR_22(__VA_ARGS__)
505
-
506
- #define TO_STR_24(_var, ...) \
507
- TO_STR_1(_var) \
508
- TO_STR_23(__VA_ARGS__)
509
-
510
- #define TO_STR_25(_var, ...) \
511
- TO_STR_1(_var) \
512
- TO_STR_24(__VA_ARGS__)
513
-
514
- #define TO_STR_26(_var, ...) \
515
- TO_STR_1(_var) \
516
- TO_STR_25(__VA_ARGS__)
517
-
518
- #define TO_STR_27(_var, ...) \
519
- TO_STR_1(_var) \
520
- TO_STR_26(__VA_ARGS__)
521
-
522
- #define TO_STR_28(_var, ...) \
523
- TO_STR_1(_var) \
524
- TO_STR_27(__VA_ARGS__)
525
-
526
- #define TO_STR_29(_var, ...) \
527
- TO_STR_1(_var) \
528
- TO_STR_28(__VA_ARGS__)
529
-
530
- #define TO_STR_30(_var, ...) \
531
- TO_STR_1(_var) \
532
- TO_STR_29(__VA_ARGS__)
533
-
534
- #define TO_STR_31(_var, ...) \
535
- TO_STR_1(_var) \
536
- TO_STR_30(__VA_ARGS__)
537
-
538
- #define TO_STR_32(_var, ...) \
539
- TO_STR_1(_var) \
540
- TO_STR_31(__VA_ARGS__)
541
-
542
- #define TO_STR_33(_var, ...) \
543
- TO_STR_1(_var) \
544
- TO_STR_32(__VA_ARGS__)
545
-
546
- #define TO_STR_34(_var, ...) \
547
- TO_STR_1(_var) \
548
- TO_STR_33(__VA_ARGS__)
549
-
550
- #define TO_STR_35(_var, ...) \
551
- TO_STR_1(_var) \
552
- TO_STR_34(__VA_ARGS__)
553
-
554
- #define TO_STR_36(_var, ...) \
555
- TO_STR_1(_var) \
556
- TO_STR_35(__VA_ARGS__)
557
-
558
- #define TO_STR_37(_var, ...) \
559
- TO_STR_1(_var) \
560
- TO_STR_36(__VA_ARGS__)
561
-
562
- #define TO_STR_38(_var, ...) \
563
- TO_STR_1(_var) \
564
- TO_STR_37(__VA_ARGS__)
565
-
566
- #define TO_STR_39(_var, ...) \
567
- TO_STR_1(_var) \
568
- TO_STR_38(__VA_ARGS__)
569
-
570
- #define TO_STR_40(_var, ...) \
571
- TO_STR_1(_var) \
572
- TO_STR_39(__VA_ARGS__)
573
-
574
- #define TO_STR_41(_var, ...) \
575
- TO_STR_1(_var) \
576
- TO_STR_40(__VA_ARGS__)
577
-
578
- #define TO_STR_42(_var, ...) \
579
- TO_STR_1(_var) \
580
- TO_STR_41(__VA_ARGS__)
581
-
582
- #define TO_STR_43(_var, ...) \
583
- TO_STR_1(_var) \
584
- TO_STR_42(__VA_ARGS__)
585
-
586
- #define TO_STR_44(_var, ...) \
587
- TO_STR_1(_var) \
588
- TO_STR_43(__VA_ARGS__)
589
-
590
- #define TO_STR_45(_var, ...) \
591
- TO_STR_1(_var) \
592
- TO_STR_44(__VA_ARGS__)
593
-
594
- #define TO_STR_46(_var, ...) \
595
- TO_STR_1(_var) \
596
- TO_STR_45(__VA_ARGS__)
597
-
598
- #define TO_STR_47(_var, ...) \
599
- TO_STR_1(_var) \
600
- TO_STR_46(__VA_ARGS__)
601
-
602
- #define TO_STR_48(_var, ...) \
603
- TO_STR_1(_var) \
604
- TO_STR_47(__VA_ARGS__)
605
-
606
- #define TO_STR_49(_var, ...) \
607
- TO_STR_1(_var) \
608
- TO_STR_48(__VA_ARGS__)
609
-
610
- #define TO_STR_50(_var, ...) \
611
- TO_STR_1(_var) \
612
- TO_STR_49(__VA_ARGS__)
613
-
614
- #define TO_STR_51(_var, ...) \
615
- TO_STR_1(_var) \
616
- TO_STR_50(__VA_ARGS__)
617
-
618
- #define TO_STR_52(_var, ...) \
619
- TO_STR_1(_var) \
620
- TO_STR_51(__VA_ARGS__)
621
-
622
- #define TO_STR_53(_var, ...) \
623
- TO_STR_1(_var) \
624
- TO_STR_52(__VA_ARGS__)
625
-
626
- #define TO_STR_54(_var, ...) \
627
- TO_STR_1(_var) \
628
- TO_STR_53(__VA_ARGS__)
629
-
630
- #define TO_STR_55(_var, ...) \
631
- TO_STR_1(_var) \
632
- TO_STR_54(__VA_ARGS__)
633
-
634
- #define TO_STR_56(_var, ...) \
635
- TO_STR_1(_var) \
636
- TO_STR_55(__VA_ARGS__)
637
-
638
- #define TO_STR_57(_var, ...) \
639
- TO_STR_1(_var) \
640
- TO_STR_56(__VA_ARGS__)
641
-
642
- #define TO_STR_58(_var, ...) \
643
- TO_STR_1(_var) \
644
- TO_STR_57(__VA_ARGS__)
645
-
646
- #define TO_STR_59(_var, ...) \
647
- TO_STR_1(_var) \
648
- TO_STR_58(__VA_ARGS__)
649
-
650
- #define TO_STR_60(_var, ...) \
651
- TO_STR_1(_var) \
652
- TO_STR_59(__VA_ARGS__)
653
-
654
- #define TO_STR_61(_var, ...) \
655
- TO_STR_1(_var) \
656
- TO_STR_60(__VA_ARGS__)
657
-
658
- #define TO_STR_62(_var, ...) \
659
- TO_STR_1(_var) \
660
- TO_STR_61(__VA_ARGS__)
661
-
662
- #define TO_STR_63(_var, ...) \
663
- TO_STR_1(_var) \
664
- TO_STR_62(__VA_ARGS__)
665
-
666
- /**
667
- * Create C-string pointer variable(s) from `RedisModuleString` pointer(s).
668
- * If `name` is a pointer to `RedisModuleString` then this macro will define
669
- * symbols `name_str` and `name_len`. `name_str` is a `const char` pointer to
670
- * the C-string representation of `name` and `name_len` is a `size_t` variable
671
- * containing the the length of `name`.
672
- */
673
- #define TO_STR(...) \
674
- CONCATENATE(TO_STR_, UTIL_NARG(__VA_ARGS__))(__VA_ARGS__)