msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Use array_like for third-party types that I can't control

Open michaeleisel opened this issue 2 years ago • 1 comments

Description

I want to (de)serialize instances of classes that are defined in third-party modules that I can't edit. I'd still like to use array_like for the performance and file size benefits that it brings, but I can't add that to the class's definition. Is there any way to get msgspec to do array encoding without being able to edit the class?

michaeleisel avatar Sep 22 '23 19:09 michaeleisel

I'd add that this use-case also valid for first party types as well. E.g. I use msgpack-ed classes for inter-process communication (dispatcher-worker architecture) - I'd like to optimize the performance and the size of the "message", there is no need to encode keys. But I also pass serialized messages to "external" systems (front-end and others) where keys are necessary.

I'd love to have array_like a parameter of a decoder and the Struct kwarg become just a default

mishamsk avatar Jan 10 '24 16:01 mishamsk