msgspec icon indicating copy to clipboard operation
msgspec copied to clipboard

question: array of different types?

Open scarf005 opened this issue 3 years ago • 0 comments

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?

scarf005 avatar Oct 22 '22 06:10 scarf005