Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cbor_value_byte_string_equals ? #223

Open
jeremyherbert opened this issue Aug 19, 2022 · 0 comments
Open

cbor_value_byte_string_equals ? #223

jeremyherbert opened this issue Aug 19, 2022 · 0 comments

Comments

@jeremyherbert
Copy link

Hi,

There is a function in cborparser.c: cbor_value_text_string_equals which checks if a char array is equal to the cbor value string. It would be helpful to also have this for a byte string, ie:

CborError cbor_value_byte_string_equals(const CborValue *value, const char *string, size_t len, bool *result)
{
    CborValue copy = *value;
    CborError err = cbor_value_skip_tag(&copy);
    if (err)
        return err;
    if (!cbor_value_is_byte_string(&copy)) {
        *result = false;
        return CborNoError;
    }

    return iterate_string_chunks(&copy, CONST_CAST(char *, string), &len, result, NULL, iterate_memcmp);
}

This can't easily be implemented outside of the cborparser.c file because iterate_string_chunks is a static method contained to just this file.

I am happy to create a PR with this if that would help (I'm also happy to have someone else add it too), but I just wanted to check if this would be accepted?

Thanks.

qtprojectorg pushed a commit to qt/qtbase that referenced this issue Nov 28, 2023
That way we don't need to decode to QString in order to compare to
"Keys". There's no avoiding the conversion to it when inserting in the
map for top-level elements, but use of moc's -M option is extremely
rare.

Ideally, we'd simply ask QCborStreamReader to perform a comparison to a
string of ours, so we didn't have to memcpy from the stream in the first
place. But TinyCBOR has no API for that (it's been pending as
intel/tinycbor#223 for a while).

Change-Id: I8bd6bb457b9c42218247fffd1797607f75b153f4
Reviewed-by: Eirik Aavitsland <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant