Replies: 1 comment
|
Override the import base64
from litestar import Litestar
def encode_bytes(value: bytes) -> dict[str, str]:
return {"__type__": "bytes", "value": base64.b64encode(value).decode("ascii")}
app = Litestar(
route_handlers=[...],
type_encoders={bytes: encode_bytes},
)That gives you the wrapped shape exactly. msgspec calls the encoder when it hits a If you want to read that shape back into One gotcha. If a handler returns raw |
Uh oh!
There was an error while loading. Please reload this page.
I think it would be cool to serialize
byteson the Python side, and automatically have that show up as aUint8Arrayon the JavaScript side. It should be possible in JS with a custom reviver, but can't I figure out how to control serialization ofbytes. I'm trying to get something like this:Is it possible to control how
bytesare serialized? Seems like the defaultmsgspecbehavior is used.All reactions