msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

Add support for having multiple `tag_fields`

Open serozhenka opened this issue 1 year ago • 0 comments

Description

It would be beneficial to differentiate struct uniqueness by multiple fields. A good use case example is message versioning. You might have multiple message types and multiple versions associated with it.

Usage example:

class MessageType1V1(Struct, tag=("type1", "v1"), tag_field=("type", "version")):
     foo: int
     bar: str

... multiple message type1 versions

class MessageType2V1(Struct, tag=("type2", "v1"), tag_field=("type", "version")):
     some_other_foo: int
     some_other_bar: str

... multiple message type2 versions

Adding to this it would be good to add an option to preserve tag fields after decoding, so we can differentiate messages based on their attributes (type and version in this case) instead of a type.

serozhenka avatar Dec 06 '23 11:12 serozhenka