decode<T> static method

Fugue<T> decode<T>(
  1. Object json,
  2. T decodeValue(
    1. Object?
    )
)

Decode a structure produced by encode. decodeValue is the inverse of the encoder passed to encode.

Implementation

static Fugue<T> decode<T>(Object json, T Function(Object?) decodeValue) {
  final map = json as Map;
  final f = Fugue<T>();
  for (final row in map['b'] as List) {
    final r = row as List;
    final start = Dot(r[0] as int, r[1] as String);
    final parent = Dot(r[2] as int, r[3] as String);
    final side = (r[4] as int) == 1 ? Side.right : Side.left;
    final values = <T>[for (final v in r[5] as List) decodeValue(v)];
    final b = _Block<T>(start, parent, side, values);
    final del = r[6] as List;
    for (var i = 0; i + 1 < del.length; i += 2) {
      final s = del[i] as int;
      final len = del[i + 1] as int;
      for (var k = 0; k < len; k++) {
        b.deleted.add(s + k);
      }
    }
    f._index(b);
  }
  return f;
}