| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
|
ja: JSONの中にJSONをネストするにはエスケープが必要になりますが、msgpackの中にmsgpackをネストして格納する場合はエスケープが必要ありません。 ja: そのため、このようなハックが有効になるようなデータを扱う場合は、msgpackをネストすることが良いプラクティスになります。 ja: それでもこの機能が必要だと思うのであれば、同様の機能を実装している他のmsgpack実装を複数紹介してください。少なくとも1つはPython以外の言語用のライブラリを選んでください。 ja: もし他にこの機能を実装しているmsgpack実装が見つからず、それでもこの機能が本当に必要なんだと強く確信しているのであれば、その確信を私に伝えるための十分な根拠を提供してください。 en: If you cannot find any other msgpack implementations that have this feature, and you are still strongly convinced that this feature is truly necessary, please provide sufficient evidence to convince me of your conviction. |
Sorry, something went wrong.
|
Hi! Sorry for the time it took me to reply. Here are some use cases (and below I left some msgpack packages that do similar things):
Note that just placing the serialized msgpack as a bin (or using an extension type for that) also increases:
The Bypass class allows for flattening this object payload into the main payload, in a fast and safe (if you know it is valid msgpack) way. The resulting payload is byte-for-byte identical to serializing the object inline, so Bypass is fully transparent to the decoding side (any language / any msgpack library, it does not even need to know Bypass was used), while the raw binary (or extension type) changes the output format and forces every consumer to know the convention (possibly recursive if there are many steps). I resorted to Bypass here because the current implementation does not provide a stream where you can write freely, but some of the example packages below do provide a stream, so it is a way to avoid the Bypass class (and another option if you want to go that way, but that would change the current default param or introduce a new one, e.g., streamed_default or something similar, which would increase implementation complexity / time). Concatenating packb outputs externally does work, but one would need to assemble every enclosing container by hand (pack_array_header / pack_map_header, then concatenate, which could turn into O(n^2) complexity if done wrong): a Bypass value can be placed anywhere inside a Python structure (deep inside dicts and/or lists passed to packb), which manual concatenation cannot achieve without reimplementing the packer's container logic. Here are some examples of msgpack packages outside Python that allow doing something similar:
Extra cases:Other msgpack packages in PythonInside Python, msgspec (which also implements msgpack) has a Raw type that does exactly this (from its docs: "Raw objects wrap pre-encoded messages. These can be added as components of larger messages without having to pay the cost of decoding and re-encoding them"). Note that Raw also appears on the decoding side, but only as a type annotation: a field annotated as Raw is kept undecoded (as a view into the original message, to be decoded later by the user); regular decoding does not produce Raw objects from Raw-encoded instances. On CBORThe same passthrough also exists in CBOR (a binary format very similar to msgpack), for example:
About the name: Raw would follow msgspec's Raw and Go's / fxamacker's RawMessage, but it could be confused with the bin format, so I avoided it. Maybe a better name for the Bypass class would be Passthrough or Flatten, but I am not sure if any of them is better. I am always open to suggestions. Note: I have updated my branch of the repository to include the latest commits and add some basic Bypass tests. |
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
This is a very useful feature for when you have a class that know how to convert its structure to msgpack (specially from compiled modules) and you don't want to have its contents converted to the binary object by returning the converted msgpack from default.
As an example, orjson has a similar feature, which they call Fragment.
Some use cases include, but are not limited to:
PS: Sorry for closing and reopening it, I had some failed linter tests and wanted to fix them, but ended up pushing a version without any changes, which triggered GitHub's auto close feature.