Support encoding indefinite containers#256
Conversation
b473365 to
b672722
Compare
|
How are the tests passing for you locally? |
b672722 to
088d68b
Compare
|
I'm getting all sorts of |
088d68b to
597fc86
Compare
This message indicates that the C extension is unavailable. So likely it didn't compile successfully, or you didn't do it in the first place. How are you running the tests? |
|
I was just running |
597fc86 to
b8b0d89
Compare
|
WOOHOO! Passes the tests now :) |
|
That's odd. Try setting |
|
That |
|
From a cursory look, only minor code style issues remain. In Python code, I prefer a blank line after a control block if the code continues on the same level. In C code, I prefer a space between |
|
No problem with doing these changes, but wouldn't these styling issues be better resolved by a pre-commit formatter hook? |
|
If you can point me to a Ruff rule (or a rule in another linter) that can enforce these, I would be most grateful! |
|
Don't know about the Python part, but I am quite positive there is an option for the ifs in ClangFormat. There seems to be no autoformatting for the C code set up at the moment. |
|
Something occurred to me: couldn't we simply wrap indefinite containers to mark them to be encoded as such? |
|
You mean that you would need to use a specific class other than the |
|
Alright, I'll take that under advisement. Reviewing this is still on my to-do list, but I don't expect any trouble from that. |
source/encoder.c
Outdated
| { | ||
| uint8_t major_tag; | ||
| uint64_t length; | ||
| uint64_t length = -1; |
There was a problem hiding this comment.
Yes, -1 becomes a very large integer.
I did this because I was too lazy to set up a custom structure for the uint64_or_none that would be required for PyArg_ParseTuple. It would be cleaner to have it distinct, yes. It is somewhat dirty, so I didn't want to bring this approach to other places.
Should I remake it?
There was a problem hiding this comment.
Well, I just thought that if using -1 was acceptable, why not just use it directly in encode_length()?
There was a problem hiding this comment.
I guess I can - if you accept that solution, I can make it that way.
There was a problem hiding this comment.
Do you see any downsides when compared to the current code in this PR?
There was a problem hiding this comment.
At the current state of the code, probably not.
|
Hello, no updates from you for quite some time |
|
Ah...sorry, I've taken a look at this a few times but my attention span wasn't quite long enough to determine what I want here. I'll reply in the ongoing convo. |
|
Okay, so apparently in the tests you are trying to encode the maximum length (u64-1) on a few places, which is now producing invalid results - so we need that discernation. I will revert the changes (and make the uint64_t_or_none proper) |
I think that'd be for the best. I sometimes lose sleep over details like this :) |
Add the indefinite_containers parameter to the encoder functions. If the parameter is set to True, containers (maps and arrays) are encoded an indefinite containers.
aba28eb to
5996066
Compare
|
All right, done. Sorry about the mess. I have squashed things up because I felt like it's way too much. (Also I was too lazy to remember how to run tests on my local machine, but I've done that now as well) |
|
I'm too attention deficient to wrangle any more about this, so I just merged it. |
|
Okay, thanks :D |
|
Hello, we've just open-sourced the project I needed this for: https://github.com/prusa3d/OpenPrintTag So, thanks again for your cooperation :) |
Changes
indefinite_containersparameter to the encoder functions. If the parameter is set to True, containers (maps and arrays) are encoded an indefinite containers.I am using this library to for unittesting a C++ CBOR generator, for which case I needed to generate structures with indefinite containers to be able to do 1:1 byte checks.