Snapshot.fromJson constructor

Snapshot.fromJson(
  1. Map<String, dynamic> m
)

Construct Snapshot object from the given JSON object.

Implementation

factory Snapshot.fromJson(Map<String, dynamic> m) {
  // Extract meta information first.
  final meta = Meta._fromJson(m['snapshot']['meta']);

  final nodes = (m['nodes'] as List<dynamic>).cast<int>();

  // Build an array of starting indexes of edges for each node.
  final edgesStartIndexForNode = <int>[0];
  int nextStartIndex = 0;
  for (var i = meta.nodeEdgeCountIndex;
      i < nodes.length;
      i += meta.nodeFieldCount) {
    nextStartIndex += nodes[i];
    edgesStartIndexForNode.add(nextStartIndex);
  }

  return Snapshot._(
      meta,
      m['snapshot']['node_count'],
      m['snapshot']['edge_count'],
      m['nodes'],
      m['edges'],
      m['strings'],
      edgesStartIndexForNode);
}