-
Notifications
You must be signed in to change notification settings - Fork 187
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
Access to strings by reference #206
Comments
I'm not going to accept your PR. Instead, I'll merge my own implementation, which supports chunked strings too. |
Ah that looks even better with the chunked string support, thanks! |
Please take a look at the API I developed. I still think it's clumsy, so I'd love feedback. CBOR_INLINE_API CborError cbor_value_get_string_chunk_size(const CborValue *value, size_t *len)
CBOR_INLINE_API bool cbor_value_string_iteration_at_end(const CborValue *value)
CBOR_INLINE_API CborError cbor_value_begin_string_iteration(CborValue *value)
CBOR_INLINE_API CborError cbor_value_finish_string_iteration(CborValue *value)
CBOR_INLINE_API CborError cbor_value_get_text_string_chunk(const CborValue *value, const char **bufferptr,
size_t *len, CborValue *next)
CBOR_INLINE_API CborError cbor_value_get_byte_string_chunk(const CborValue *value, const uint8_t **bufferptr,
size_t *len, CborValue *next) API docs: https://github.com/thiagomacieira/tinycbor/blob/dev/src/cborparser.c#L1068-L1147 & https://github.com/thiagomacieira/tinycbor/blob/dev/src/cborparser.c#L1231-L1295 If you have time, the ugliest part of the patch set is the |
I have already ported my code to this api, it is exactly as expected. I used the cbor_value_string_iteration_at_end() to verify that, in our case, we are at the end after reading exactly 1 chunk (required in our case at the moment). The implementation seems straightforward to me, but the internals are not too familiar for me. cbor_parser_init_reader: I see the need if you receive your messages in pieces and have little buffer space. But it looks ok to me if you would want to provide token-by-token input instead of the complete message. |
Wouldn't names like |
Also the functions |
I guess |
Yes, The reason int v;
CborValue str;
cbor_value_enter_string(&it, &str);
cbor_value_get_integer(&str, &v); One way I had considered (but didn't implement) was to have a separate type, a CborStringValue, in which case you can't accidentally pass this iterator into the regular decoders. But then you can't pass it to But there may be another way: CborValue stores the current element type, so that you can't call That sounds like a good plan. Now to have the time to explore it... |
|
I think using Since an indefinite string is made up of a series of fixed-length strings, I think it would be appropriate if |
Hi @thiagomacieira. Is there any reason not to already merge your pending changes at least up to commit 98cb87c ? |
Not really. I will probably merge everything and then design the new API modifying what is in there. The WIP commits are about the delegated streaming API, not the string API anyway. |
Hello, I created #205 as a proposal to allow direct access to the underlying buffer for (large) strings.
We use this to avoid an extra copy when processing a stream of cbor encocded images + metadata.
We use only determinate length strings for these, I have not implemented iteration over the
parts of intedeterminate length strings, as I was not sure whether to use enter/leave for those, or how this
would best fit into the existing API.
The text was updated successfully, but these errors were encountered: