serializePerceptionFragment function

Map<String, Object?> serializePerceptionFragment(
  1. Branch root
)

Serializes the perception subtree rooted at root into a JSON-able map.

A StatelessPerception/StatefulPerception root mounts as a ComponentBranch; its built child is unwrapped first, so passing either the component root or a bare Node root works. A root that does not resolve to a NodeElement yields an empty map.

Implementation

Map<String, Object?> serializePerceptionFragment(Branch root) {
  final node = root is ComponentBranch ? root.child : root;
  if (node is! NodeElement) return const <String, Object?>{};
  return _serializeNode(node);
}