expandLogicType function

List<TypeFieldNode> expandLogicType(
  1. Map<String, dynamic>? logicType, {
  2. String? parentBinaryValue,
})

Expand a logic_type metadata map into a tree of TypeFieldNodes.

If parentBinaryValue is provided (as a binary string, MSB-first), sub-field values are extracted via bit-slicing.

The logic_type format for structs:

{"typeName": "FloatingPoint", "fields": [
  {"name": "mantissa", "width": 4, "bits": [0,1,2,3]},
  {"name": "exponent", "width": 4, "bits": [4,5,6,7]},
  {"name": "sign", "width": 1, "bits": [8]}
]}

For arrays:

{"width": 80, "arrayDims": [10], "elementWidth": 8}

Implementation

List<TypeFieldNode> expandLogicType(
  Map<String, dynamic>? logicType, {
  String? parentBinaryValue,
}) {
  if (logicType == null) {
    return const [];
  }

  // Struct case
  final fields = logicType['fields'] as List<dynamic>?;
  if (fields != null) {
    return _expandStructFields(fields, parentBinaryValue);
  }

  // Array case
  final arrayDims = logicType['arrayDims'] as List<dynamic>?;
  if (arrayDims != null) {
    final elementWidth = (logicType['elementWidth'] as int?) ?? 1;
    final elementType = logicType['elementType'] as Map<String, dynamic>?;
    return _expandArrayElements(
      arrayDims.cast<int>(),
      elementWidth,
      elementType,
      parentBinaryValue,
    );
  }

  return const [];
}