capnproto / pycapnp

Cap'n Proto serialization/RPC system - Python bindings
BSD 2-Clause "Simplified" License
468 stars 124 forks source link

Add json support with binary fields via base64 encoding #351

Open dominikandreas opened 8 months ago

dominikandreas commented 8 months ago

My use-case requires capnp messages to (also) be serialized to json and deserialized from json. This PR adds support for this by converting binary data to a base64 encoded string, which is compatible with json.

The implementation is non-breaking, the previous behavior stays the same, but can be controlled via a msg.to_dict(encode_binary_as_base64=True).

I realize this might be a rare use-case but doesn't hurt to have it as a feature and at least in my case it's useful to have json as a fallback solution in the communication stack for debugging purposes.