estimateSerializedNodeSize function

int estimateSerializedNodeSize(
  1. Node node
)

The estimated size in bytes of node serialised as JSON (decides whether a listen sends a compound hash).

Implementation

int estimateSerializedNodeSize(Node node) {
  if (node.isEmpty) {
    return 4; // null
  }
  if (node.isLeafNode) {
    return _estimateLeafNodeSize(node as LeafNode);
  }
  int sum = 1; // opening bracket
  node.forEachChild(keyIndex, (ChildKey key, Node child) {
    sum += key.name.length; // key
    sum += 4; // quotes around the key, colon, and comma or closing bracket
    sum += estimateSerializedNodeSize(child);
    return false;
  });
  final Node priority = node.priority;
  if (!priority.isEmpty) {
    sum += 12; // ".priority" key, colon and comma
    sum += _estimateLeafNodeSize(priority as LeafNode);
  }
  return sum;
}