deserialize method

  1. @override
String? deserialize({
  1. required bool fromIDL,
  2. bool nullable = false,
})
override

Implementation

@override
String? deserialize({required bool fromIDL, bool nullable = false}) {
  if (isUint8List) {
    const deser = '${IDLType.ph} is Uint8List '
        '? ${IDLType.ph} '
        ': Uint8List.fromList((${IDLType.ph} as List).cast())';
    return nullable ? '${IDLType.ph} == null ? null : $deser' : deser;
  }
  final isOpt = ctx.parent?.parent is OptTypeContext;
  String? d = child.deserialize(fromIDL: fromIDL, nullable: false);
  if (d != null && d != IDLType.ph) {
    if (nullable) {
      if (fromIDL || !isOpt) {
        d = "(${IDLType.ph} as List?)?.map((e) { return ${d.replaceAll(IDLType.ph, "e")}; }).toList()";
      } else {
        d = '${IDLType.ph} != null ? $d : null';
      }
    } else {
      if (fromIDL) {
        d = "(${IDLType.ph} as List).map((e) { return ${d.replaceAll(IDLType.ph, "e")}; }).toList()";
      } else if (!isOpt ||
          (child.child is! IdType && child.child is! RecordType)) {
        d = '(${IDLType.ph} as List).cast()';
      }
    }
  } else if (d == null || d == IDLType.ph) {
    final castType = child.dartType(nullable: nullable);
    if (nullable) {
      if (fromIDL) {
        d = '(${IDLType.ph} as List?)?.cast<$castType>()';
      } else {
        d = '${IDLType.ph} != null ? $d : null';
      }
    } else {
      if (fromIDL) {
        d = '(${IDLType.ph} as List).cast<$castType>()';
      } else if (ctx.parent?.parent is OptTypeContext) {
        d = '$d as $castType';
      }
    }
  }
  return d;
}