|
29 | 29 | // Create a .cc file for your extension: |
30 | 30 | // |
31 | 31 | // #include <villagesql/extension.h> |
| 32 | +// using namespace villagesql; |
32 | 33 | // |
33 | 34 | // // Implement your function |
34 | | -// void add_impl(vef_context_t* ctx, |
35 | | -// vef_invalue_t* a, vef_invalue_t* b, |
36 | | -// vef_vdf_result_t* result) { |
37 | | -// result->int_value = a->int_value + b->int_value; |
38 | | -// result->type = VEF_RESULT_VALUE; |
| 35 | +// void add_impl(IntArg a, IntArg b, IntResult out) { |
| 36 | +// if (a.is_null() || b.is_null()) { out.set_null(); return; } |
| 37 | +// out.set(a.value() + b.value()); |
39 | 38 | // } |
40 | 39 | // |
41 | 40 | // // Register the extension with inline function definitions |
|
79 | 78 | // out.set_length(src.size()); |
80 | 79 | // } |
81 | 80 | // |
82 | | -// DEFINING FUNCTIONS (deprecated, will be removed) |
| 81 | +// DEFINING FUNCTIONS |
83 | 82 | // ------------------ |
84 | 83 | // |
85 | 84 | // Functions are defined using make_func<&impl>("name") and chained builder |
|
173 | 172 | // |
174 | 173 | // #include <villagesql/extension.h> |
175 | 174 | // #include <cstring> |
| 175 | +// using namespace villagesql; |
176 | 176 | // |
177 | 177 | // static const size_t kBytearrayLen = 8; |
178 | 178 | // constexpr const char* BYTEARRAY = "bytearray"; |
|
206 | 206 | // } |
207 | 207 | // |
208 | 208 | // // ROT13: apply ROT13 cipher to ASCII letters in a bytearray |
209 | | -// void rot13_impl(vef_context_t* ctx, |
210 | | -// vef_invalue_t* input, vef_vdf_result_t* result) { |
211 | | -// if (input->is_null) { result->type = VEF_RESULT_NULL; return; } |
| 209 | +// void rot13_impl(BinaryArg input, BinaryResult out) { |
| 210 | +// if (input.is_null()) { out.set_null(); return; } |
| 211 | +// auto src = input.value(); // villagesql::Span<const unsigned char> |
| 212 | +// auto dst = out.buffer(); // villagesql::Span<unsigned char> |
212 | 213 | // for (size_t i = 0; i < kBytearrayLen; i++) { |
213 | | -// unsigned char c = input->bin_value[i]; |
| 214 | +// unsigned char c = src[i]; |
214 | 215 | // if (c >= 'A' && c <= 'Z') c = 'A' + ((c - 'A' + 13) % 26); |
215 | 216 | // else if (c >= 'a' && c <= 'z') c = 'a' + ((c - 'a' + 13) % 26); |
216 | | -// result->bin_buf[i] = c; |
| 217 | +// dst[i] = c; |
217 | 218 | // } |
218 | | -// result->type = VEF_RESULT_VALUE; |
219 | | -// result->actual_len = kBytearrayLen; |
| 219 | +// out.set_length(kBytearrayLen); |
220 | 220 | // } |
221 | 221 | // |
222 | 222 | // // Register everything inline |
|
0 commit comments