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 bindings #559

Open
wants to merge 26 commits into
base: main
Choose a base branch
from
Open

CBOR bindings #559

wants to merge 26 commits into from

Conversation

TingDaoK
Copy link
Contributor

@TingDaoK TingDaoK commented Apr 22, 2024

Issue #, if available:

  • Binding with tests
  • The generic tests for cbor decode, implement them in python since it is a huge pain to do the same thing in C even with genAI :(
  • Move all the arm64 test to codebuild arm64 image, it now takes 3 mins instead of over 30 mins ❤️

Description of changes:

TODO:

  • timestamp support, big number/decimal fraction support
  • documentation

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@TingDaoK TingDaoK marked this pull request as ready for review January 13, 2025 19:04
DmitriyMusatkin
DmitriyMusatkin previously approved these changes Mar 6, 2025
return _awscrt.cbor_encoder_get_encoded_data(self._binding)

def write_int(self, val: int):
# TODO: maybe not support bignum for now. Not needed?
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

smithy currently does not support anything above 64bits afaik so we can probably skip bignum for now

# For negative value, the value to encode is -1 - val.
val_to_encode = -1 - val
bit_len = val_to_encode.bit_length()
if bit_len > 64:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wouldnt python need 65 bits to represent - u64_max? so this logic might be a bit off, since we dont need bignum for - u64_max

Args:
val (int): value to be encoded and written to the encoded data.
"""
assert isinstance(val, int)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for my education, havent we already indicated in function signature htat val is an int? why do we have to check twice


def write_array_start(self, number_entries: int):
"""Add a start of array element.
A legistic with the `number_entries`
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo?

Args:
number_entries (int): number of entries in the array to be written
"""
if number_entries < 0 or number_entries > 2**64:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ugh, cbor spec allows 2^64 entries? not sure we would be able to allocate cbor chunk for that even if all entries are 1 byte. should we consider a lower bound


PyObject *aws_py_cbor_encoder_write_unsigned_int(PyObject *self, PyObject *args) {
PyObject *pylong;
S_ENCODER_METHOD_START("O", &pylong);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the only thing that changes is the last part of s_cbor_encoder_write_pyobject_as? maybe more more of that into macro and let macro just call correct s_cbor_encoder_write_pyobject_as?

having a macro thats just a partial method kinda scares me

for (Py_ssize_t i = 0; i < size; i++) {
PyObject *item = PyList_GetItem(py_list, i);
if (!item) {
return NULL;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we leave it in broken state if element is not valid?

return py_capsule;
}

#define S_GET_DECODER() \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: but im not a big fan of macros inserting random code into functions, can we make macros more like a generic function that returns a value rathere then relying on side effects

return PyErr_AwsLastError();
}
/* TODO: implement those tags */
switch (out_tag_val) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so we currently support no tags? should we be more explcit in doc on what function supports?

@DmitriyMusatkin DmitriyMusatkin dismissed their stale review March 6, 2025 00:36

accidental approve. comments still need to be discussed

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

Successfully merging this pull request may close these issues.

2 participants