swift/sajson/sajson-ffi.cpp
/// HACK: This is a re-implemented version of a similar function on
/// sajson::value. We should modify it to either share a common helper, or
/// remove it completely and re-implement the search logic in Swift.
This is a re-implemented version of a similar function on
sajson::value. We should modify it to either share a common helper, or
remove it completely and re-implement the search logic in Swift.
This is a re - implemented version of a similar function on sajson :: value . We should modify it to either share a common helper or remove it completely and re - implement the search logic in Swift .
size_t sajson_find_object_key(
    const size_t* const payload,
    const char* key,
    size_t length,
    const unsigned char* input) {
    auto inputCasted = reinterpret_cast<const char* const>(input);
    sajson::string key_string = sajson::string(key, length);
    size_t value_length = payload[0];
    const sajson::internal::object_key_record* start
        = reinterpret_cast<const sajson::internal::object_key_record*>(
            payload + 1);
    const sajson::internal::object_key_record* end = start + value_length;
    const sajson::internal::object_key_record* i = std::lower_bound(
        start,
        end,
        key_string,
        sajson::internal::object_key_comparator(inputCasted));
    return (i != end && (i->key_end - i->key_start) == key_string.length()
            && memcmp(
                   key_string.data(), input + i->key_start, key_string.length())
                == 0)
        ? i - start
        : value_length;
}
size_t sajson_find_object_key ( const size_t * const payload , const char * key , size_t length , const unsigned char * input ) { auto inputCasted = reinterpret_cast < const char * const > ( input ) ; sajson :: string key_string = sajson :: string ( key , length ) ; size_t value_length = payload [ 0 ] ; const sajson :: internal :: object_key_record * start = reinterpret_cast < const sajson :: internal :: object_key_record * > ( payload + 1 ) ; const sajson :: internal :: object_key_record * end = start + value_length ; const sajson :: internal :: object_key_record * i = std :: lower_bound ( start , end , key_string , sajson :: internal :: object_key_comparator ( inputCasted ) ) ; return ( i != end && ( i -> key_end - i -> key_start ) == key_string . length ( ) && memcmp ( key_string . data ( ) , input + i -> key_start , key_string . length ( ) ) == 0 ) ? i - start : value_length ; }
HACK: This is a re-implemented version of a similar function on
sajson::value.
HACK : This is a re - implemented version of a similar function on sajson :: value .