You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Tiled "serializers" are functions which take a Python data structure as input and produce bytes as output, for transport over the network. The serializers currently look like this:
I propose changing the signature to add mimetype as the first argument.
deff(mimetype, array, metadata):
...
This is a common pattern in callback registries. (We adopted the same pattern in caproto.) It enables the same callback to be subscribed to multiple channels and easily distinguish which one of them is calling. I see two use cases:
Serializers that can handle many types but need to do different things (like PIL). We currently handle this with a convenience function.
Support for mimetype parameters, such as text/csv;header=present and text/csv;header=absent. It would be convenient for serializer_csv to be called in both cases, and to be able to adjust its output correctly.
Also, in support of (2), I think this the registry should be tweaked to support optional mimetype parameters, such as text/csv;header=present. When the registry is passed a mimetype with parameters, it should perform dispatch based on the type without arguments (text/csv) but it should pass the full mimetype with arguments to the serializer, which can then parse the mimetype and do what it likes with the arguments.
The text was updated successfully, but these errors were encountered:
danielballan
changed the title
Pass mimetype to serializres, and support mimetype parameters in registry
Pass mimetype to serializers, and support mimetype parameters in registry
Mar 7, 2025
Tiled "serializers" are functions which take a Python data structure as input and produce bytes as output, for transport over the network. The serializers currently look like this:
tiled/tiled/serialization/array.py
Lines 38 to 43 in 48bb130
These get registered to a mimetype, potentially multiple of them.
tiled/tiled/serialization/array.py
Lines 46 to 48 in 48bb130
I propose changing the signature to add
mimetype
as the first argument.This is a common pattern in callback registries. (We adopted the same pattern in caproto.) It enables the same callback to be subscribed to multiple channels and easily distinguish which one of them is calling. I see two use cases:
text/csv;header=present
andtext/csv;header=absent
. It would be convenient forserializer_csv
to be called in both cases, and to be able to adjust its output correctly.Also, in support of (2), I think this the registry should be tweaked to support optional mimetype parameters, such as
text/csv;header=present
. When the registry is passed a mimetype with parameters, it should perform dispatch based on the type without arguments (text/csv
) but it should pass the full mimetype with arguments to the serializer, which can then parse the mimetype and do what it likes with the arguments.The text was updated successfully, but these errors were encountered: