msgspec
msgspec copied to clipboard
question: array of different types?
Case 1
[
{ "height": 10, "width": 10 }, // <- type 'A'
{ "ASCIITiles.png": { "//": "indices 0 to 79" } }, // <- type 'B'
{ "fallback.png": { "fallback": true } }
...
]
it's guaranteed that the array will be shaped like [A, B, B, ...]. I'm not sure how to make msgspec understand that only first element has different type.
Case 2
[
{ "id": "lighting_hidden" },
{
"id": "explosion_weak",
"multitile": true,
"additional_tiles": "(...)"
}
]
the first and second element only differs in multitile and additional_tiles.
additional_tiles only exist when multiile exists and is true. I wasn't able to turn both objects into tagged unions.
could you help me to to correctly distinguish both objects?