-
Notifications
You must be signed in to change notification settings - Fork 211
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
Serialize byte objects directly #152
Conversation
Thank you for working on this. I think there are some questions about how this should work. The first use case given was writing base64 |
Ah, I see. So the first issue wants the bytes to be serialized directly as a string rather than to raw JSON. That seems like it'll require a separate option to distinguish the behavior. Yeah, I'll do a bit a of benchmarking to check out it out, and do some testing of invalid JSON. |
Ok, I've added support for the other use case as Added a test case for invalidly formatted JSON, which seems to work without any changes. Same with UTF8 –– I'm not really familiar with creating invalid UTF8, so I just picked a string that Benchmarking:
|
Looking at this it's really not possible to have both options as-is. What happens if I specify I think the way forward for I don't expect you want to spend time implementing the |
I suppose the other simple alternative is to just throw an exception when both options are specified, since that's a unresolvable logical request. Do you have any objections to that? Happy to spend sometime creating another type if so. Yeah, so the existing behavior serialized bytes as an array of byte codes (for example |
Thanks for explaining the serde-json change. I think it's avoidable to allow the user to be in a position where it's possible to specify conflicting options and being hard to misuse is better. To look at it in terms of docs, something like: Fragment
>>> import orjson
>>> orjson.dumps({"data": orjson.Fragment(b"[1,2]")})
b'{"data":[1,2}' This outputs invalid JSON if the input is invalid. The contents are passed through unmodified with no checks. >>> import orjson
>>> orjson.dumps([orjson.Fragment(b"zxc]"), ])
b'[zxc]]'
>>> orjson.loads(_)
orjson.JSONDecodeError: ... |
I'll close because it's inactive but feel free to reopen. |
Sounds good. Been busy lately, but I'll get around to it soonish. |
What reference for PyO3 did you use for writing this library? I've been looking at https://pyo3.rs/v0.13.1/class.html and checked out the docs for v0.12, but the patterns described here seem pretty different from what's in this library. I'm not quite sure how to define a Rust struct for use in Python using just Cython calls. |
You would need to use |
Closes #95.
I'm not very familiar with PyO3 so let me know if this look ok!