Skip to content
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

Extension type support #49

Open
michaelmior opened this issue Dec 4, 2015 · 1 comment
Open

Extension type support #49

michaelmior opened this issue Dec 4, 2015 · 1 comment

Comments

@michaelmior
Copy link

Any chance of adding hooks to support extension types? This would basically require an API where callers could specify two callback functions one for encoding and one for decoding. Then mp_encode_lua_type and mp_decode_to_lua_type would call these functions to produce the actual values to be used when serializing.

Examples of two different ways this can be done for msgpack-python are below

https://pypi.python.org/pypi/msgpack-python#packing-unpacking-of-custom-data-type
https://pypi.python.org/pypi/msgpack-python#extended-types

@trulede
Copy link

trulede commented Mar 28, 2021

I'm reading about the EXT type, there are two aspects; EXT with existing MsgPack Types, and EXT with custom types. The R implementation seems to understand this best and uses EXT to encode raw vectors, at least for numeric types (not sure about custom types). The Python implementation IMO is missing that aspect (the existing MsgPack Types).

mp_unpack could likely handle the EXT for existing types without any modification to the interface. For mp_pack it's a bit tricky, exactly how to pass the EXT Type, especially in the case of nested Tables, but also considering an unpack/pack sequence where type should be maintained.

One possibility might be to use a "weak table" (similar to how Lua stores array size: https://www.lua.org/pil/contents.html#17) and place the EXT Type in that table, either during mp_unpack, or explicitly before calling mp_pack. Now, perhaps that same mechanism could be used for decode functions which would open up support for custom types.

That would neatly deal with nested tables as well as custom types.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants