fromWire method

Object? fromWire(
  1. Object? raw
)

The inverse of toWire; a missing or unreadable value is the default.

A byHand row never reaches either direction — the wire carries a style as its own fields and a node's arguments as their own map — so both switches leave those two kinds alone.

Implementation

Object? fromWire(Object? raw) => switch (kind) {
  ScenePropKind.style || ScenePropKind.args => raw,
  ScenePropKind.number => raw is num ? raw.toDouble() : defaultValue,
  ScenePropKind.integer => raw is num ? raw.toInt() : null,
  ScenePropKind.string => raw is String ? raw : defaultValue,
  ScenePropKind.boolean => raw is bool ? raw : defaultValue,
  ScenePropKind.color => raw is num ? SceneColor(raw.toInt()) : defaultValue,
  ScenePropKind.size => sizeFromWire(raw),
  ScenePropKind.sizes => switch (raw) {
    List l => [for (var c in l) sizeFromWire(c)],
    _ => <double?>[],
  },
  ScenePropKind.layers => switch (raw) {
    List l => [for (var e in l) ?TextLayer.fromWire(e)],
    _ => <TextLayer>[],
  },
  ScenePropKind.axes => switch (raw) {
    Map m => {
      for (var e in m.entries)
        if (e.value case num v) '${e.key}': v.toDouble(),
    },
    _ => <String, double>{},
  },
  ScenePropKind.edges => quad!(raw),
  ScenePropKind.choice => switch (raw) {
    String name => choices!.valueOf(name) ?? defaultValue,
    // Older payloads carried the index.
    num i when i >= 0 && i < choices!.values.length =>
      choices!.values[i.toInt()],
    _ => defaultValue,
  },
};