-
Notifications
You must be signed in to change notification settings - Fork 169
Libcbor integrate #1101
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
Libcbor integrate #1101
Conversation
This reverts commit 43ac8e5.
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## cbor-main #1101 +/- ##
=============================================
+ Coverage 83.12% 83.46% +0.33%
=============================================
Files 56 57 +1
Lines 5755 5982 +227
=============================================
+ Hits 4784 4993 +209
- Misses 971 989 +18 ☔ View full report in Codecov by Sentry. |
graebm
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I only looked at the encoder part of the public header. Apologies for naive comments, since I haven't looked at the decoder yet, or any implementation details...
| * @return AWS_OP_SUCCESS successfully consumed the next element and get the result, otherwise AWS_OP_ERR. | ||
| */ | ||
| AWS_COMMON_API | ||
| int aws_cbor_decoder_pop_next_array_start(struct aws_cbor_decoder *decoder, uint64_t *out_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
how does this handle indefinite length? document it
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still curious
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thought we talked about it.
AWS_CBOR_TYPE_INDEF_BYTES_START,
AWS_CBOR_TYPE_INDEF_TEXT_START,
AWS_CBOR_TYPE_INDEF_ARRAY_START,
AWS_CBOR_TYPE_INDEF_MAP_START,
We have separate types for the indef types. I can add notes to the documents.
include/aws/common/cbor.h
Outdated
| * - 31 - AWS_CBOR_TYPE_BREAK | ||
| * - result of value not supported. | ||
| */ | ||
| enum aws_cbor_element_type { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe just simple enum aws_cbor_type, since all the actual values are just like "AWS_CBOR_TYPE_UINT" anyway and don't bother with the term "element"
| * @return AWS_OP_SUCCESS successfully consumed the next element and get the result, otherwise AWS_OP_ERR. | ||
| */ | ||
| AWS_COMMON_API | ||
| int aws_cbor_decoder_pop_next_array_start(struct aws_cbor_decoder *decoder, uint64_t *out_size); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
still curious
source/cbor.c
Outdated
| int aws_cbor_decoder_consume_next_element(struct aws_cbor_decoder *decoder) { | ||
| enum aws_cbor_element_type out_type = 0; | ||
| if (aws_cbor_decoder_peek_type(decoder, &out_type)) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should we be checking decoder->error_code first thing? or is that always handled first-thing by the helper functions?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
aws_cbor_decoder_peek_type will check the error code as the first thing.
source/cbor.c
Outdated
| /* TODO: How to check overflow? */ | ||
| double ms_double = timestamp_secs * 1000.0; | ||
| /* Round it up instead of type cast incase of overflow */ | ||
| int64_t timestamp_ms = llround(ms_double); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know off the top of my head the right way to check, but here's the docs:
https://en.cppreference.com/w/c/numeric/math/round
source/cbor.c
Outdated
| break; | ||
| } | ||
| default: | ||
| AWS_LOGF_ERROR(AWS_LS_COMMON_CBOR, "The cbor data is malformed to decode."); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
better error message about how the type isn't expected in a timestamp
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same as the encoding function, I am currently more leaning towards on removing this helper.
source/cbor.c
Outdated
| switch (decoder->cached_context.type) { | ||
| case AWS_CBOR_TYPE_TAG: | ||
| /* Read the next data item */ | ||
| /* TODO: error check for the tag content?? */ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we do this before commit, or will there be a follow-up?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
arguably... It's complicate to 100% ensure the tag value is legal.
https://www.rfc-editor.org/rfc/rfc8949.html#tags
We need to check for all those tag values and check those data as well, but we are not even reading those data. Not sure it's worth the effort to ensure we just want to ignores the data item.
eg: if someone sends a bigfloat with an array with 2 string.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I have a notes here, maybe I'll just remove this TODO.
Issue #, if available:
Description of changes:
Integrate with libcbor to provide a cbor encode/decode interface based on aws-c-common. Major decision made:
Debatable: have the cbor in aws-c-common or aws-c-sdkutils, I put it in aws-c-common mostly for:
TODO:
Conversion from double to float is tricky, numbers like "1.1" cannot be represented by double or float.Tags, should we be helpful to convert the tag value of timestamp (probably big number in the future) for the user? Or, let user to read the tag value and decide what to do with it??Error handling. Error code, logging, documentation, etc.Fuzz test from our side as well to make sure not undefined behaviorBy submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.