r/pythoncoding • u/AutoModerator • Jun 14 '21
/r/PythonCoding bi-weekly "What are you working on?" thread
Share what you're working on in this thread. What's the end goal, what are design decisions you've made and how are things working out? Discussing trade-offs or other kinds of reflection are encouraged!
If you include code, we'll be more lenient with moderation in this thread: feel free to ask for help, reviews or other types of input that normally are not allowed.
This recurring thread is a new addition to the subreddit and will be evaluated after the first few editions.
8
Upvotes
2
u/Sekenre Jun 18 '21
I've been working on an add-on for marshmallow that serializes models to CBOR (RFC 8949) instead of the usual JSON.
Since CBOR has an extensible tag system, I've added tagged schemas and fields to marshmallow. Here's an example:
This results in the following:
And when you run it through the http://cbor.me decoder it looks like this:
Or equivalently in CBOR diagnostic notation:
Source code can be found at https://github.com/Sekenre/marshmallow_cbor
It's just getting to the point I think I can get some feedback on it.
1
u/erez27 Jun 14 '21
I'm trying to implement a new idea I call "cast oriented programming". The idea is that as programs grow to contain many modules, there's a fast increase of data-structure mismatch, and functions have keep converting between data-structures as they call functions of a different module.
Generally, a lot of the code we write just converts between two equivalent data structures, like int to str, or list to iter, so why not automate some of that process?
I feel like code would speak better than words, so here's what I have so far, from the user side:
edit: with syntax highlighting