| 650 | } |
| 651 | |
| 652 | napi_value findByteFromAPI(napi_env env, napi_callback_info info) { |
| 653 | size_t argc = 2; |
| 654 | napi_value args[2]; |
| 655 | napi_get_cb_info(env, info, &argc, args, NULL, NULL); |
| 656 | |
| 657 | // Get buffer info for haystack (zero-copy) |
| 658 | void *haystack_data; |
| 659 | size_t haystack_length; |
| 660 | napi_status status = napi_get_buffer_info(env, args[0], &haystack_data, &haystack_length); |
| 661 | if (status != napi_ok) { |
| 662 | napi_throw_error(env, NULL, "First argument must be a Buffer"); |
| 663 | return NULL; |
| 664 | } |
| 665 | |
| 666 | // Get buffer info for allowed bytes (zero-copy) |
| 667 | void *allowed_data; |
| 668 | size_t allowed_length; |
| 669 | status = napi_get_buffer_info(env, args[1], &allowed_data, &allowed_length); |
| 670 | if (status != napi_ok) { |
| 671 | napi_throw_error(env, NULL, "Second argument must be a Buffer"); |
| 672 | return NULL; |
| 673 | } |
| 674 | |
| 675 | // Find first byte that is in the allowed set using sz_find_byteset |
| 676 | sz_byteset_t byteset; |
| 677 | sz_byteset_init(&byteset); |
| 678 | for (size_t i = 0; i < allowed_length; i++) { sz_byteset_add_u8(&byteset, ((sz_u8_t *)allowed_data)[i]); } |
| 679 | sz_cptr_t result = sz_find_byteset((sz_cptr_t)haystack_data, haystack_length, &byteset); |
| 680 | |
| 681 | // Convert the result to JavaScript BigInt and return |
| 682 | napi_value js_result; |
| 683 | if (result == NULL) { napi_create_bigint_int64(env, -1, &js_result); } |
| 684 | else { napi_create_bigint_uint64(env, result - (sz_cptr_t)haystack_data, &js_result); } |
| 685 | |
| 686 | return js_result; |
| 687 | } |
| 688 | |
| 689 | napi_value findLastByteFromAPI(napi_env env, napi_callback_info info) { |
| 690 | size_t argc = 2; |
nothing calls this directly
no test coverage detected
searching dependent graphs…