-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
ASF: implement CBOR parser and serializer #13103
Changes from all commits
8693ae6
b127f6d
c5e557c
4d8fc19
bb38005
50b5d6b
517902f
9f9d5c0
2ecf131
9641d9a
a2853d1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,5 +1,23 @@ | ||
| { | ||
| "tests/unit/aws/protocol/test_parser.py::test_json_cbor_blob_parsing_w_timestamp": { | ||
| "last_validated_date": "2024-06-21T13:58:29+00:00" | ||
| }, | ||
| "tests/unit/aws/protocol/test_parser.py::test_json_cbor_blob_parsing_w_timestamp[CBORRequestParser]": { | ||
| "last_validated_date": "2025-09-04T18:32:21+00:00", | ||
| "durations_in_seconds": { | ||
| "setup": 0.0, | ||
| "call": 0.01, | ||
| "teardown": 0.0, | ||
| "total": 0.01 | ||
| } | ||
| }, | ||
| "tests/unit/aws/protocol/test_parser.py::test_json_cbor_blob_parsing_w_timestamp[create_parser]": { | ||
| "last_validated_date": "2025-09-04T18:32:21+00:00", | ||
| "durations_in_seconds": { | ||
| "setup": 0.0, | ||
| "call": 0.0, | ||
| "teardown": 0.0, | ||
| "total": 0.0 | ||
| } | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -38,6 +38,7 @@ | |
| ) | ||
| from localstack.aws.api.sts import Credentials, GetSessionTokenResponse | ||
| from localstack.aws.protocol.serializer import ( | ||
| CBORResponseSerializer, | ||
| ProtocolSerializerError, | ||
| QueryResponseSerializer, | ||
| UnknownSerializerError, | ||
|
|
@@ -248,6 +249,10 @@ def _botocore_event_streaming_test( | |
| assert actual_events == expected_events | ||
|
|
||
|
|
||
| def _cbor_serializer_factory(service): | ||
| return CBORResponseSerializer() | ||
|
|
||
|
|
||
| def test_rest_xml_serializer_cloudfront_with_botocore(): | ||
| parameters = { | ||
| "TestResult": { | ||
|
|
@@ -1844,9 +1849,11 @@ def test_query_protocol_json_serialization(headers_dict): | |
| "headers_dict", | ||
| [{"Content-Type": "application/cbor"}, {"Accept": "application/cbor"}], | ||
| ) | ||
| def test_json_protocol_cbor_serialization(headers_dict): | ||
| @pytest.mark.parametrize("serializer_factory", [create_serializer, _cbor_serializer_factory]) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. praise: Nice way to test the serialization for both ways! 💯 |
||
| def test_json_protocol_cbor_serialization(headers_dict, serializer_factory): | ||
| # TODO: test datetime serialization format for Kinesis manually | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. question: Why does this have to be tested manually? Can we maybe extend this test to use an operation which has a datetime in the spec?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think because right now, Botocore is unable to parse/serialize CBOR data for Kinesis, so I would need to write a manual test somehow to verify what AWS is returning "raw" and compare it. Sorry, when I meant manually, I meant we need to verify against AWS the raw response and put it in a unit test, not "fully manual" There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. context: Kinesis' CBOR is a different wire format than Smithy RPC v2 CBOR, and you're accurate in botocore not supporting it. The AWS SDK for Java has a working implementation to reference if you want to pursue it.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Thank you, I think we will park Kinesis CBOR support as its "own" protocol for now, as we rely on botocore internals, and will continue to treat it as a sub-part/different serialization format of the |
||
| service = load_service("kinesis") | ||
| response_serializer = create_serializer(service) | ||
| response_serializer = serializer_factory(service) | ||
| headers = Headers(headers_dict) | ||
| response_data = GetRecordsOutput( | ||
| Records=[ | ||
|
|
||
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.
praise: Nice! This will hopefully also help us in the future to remove the dependency on and patching of
cbor2🤩