writeClassDecode method

  1. @override
void writeClassDecode(
  1. ObjcOptions generatorOptions,
  2. Root root,
  3. Indent indent,
  4. Class klass,
  5. Set<String> customClassNames,
  6. Set<String> customEnumNames, {
  7. required String dartPackageName,
})
override

Writes a single class decode method to indent.

Implementation

@override
void writeClassDecode(
  ObjcOptions generatorOptions,
  Root root,
  Indent indent,
  Class klass,
  Set<String> customClassNames,
  Set<String> customEnumNames, {
  required String dartPackageName,
}) {
  final String className = _className(generatorOptions.prefix, klass.name);
  indent.write('+ ($className *)fromList:(NSArray *)list ');
  indent.addScoped('{', '}', () {
    const String resultName = 'pigeonResult';
    indent.writeln('$className *$resultName = [[$className alloc] init];');
    enumerate(getFieldsInSerializationOrder(klass),
        (int index, final NamedType field) {
      if (customEnumNames.contains(field.type.baseName)) {
        indent.writeln(
            '$resultName.${field.name} = [${_listGetter(customClassNames, 'list', field, index, generatorOptions.prefix)} integerValue];');
      } else {
        indent.writeln(
            '$resultName.${field.name} = ${_listGetter(customClassNames, 'list', field, index, generatorOptions.prefix)};');
        if (!field.type.isNullable) {
          indent.writeln('NSAssert($resultName.${field.name} != nil, @"");');
        }
      }
    });
    indent.writeln('return $resultName;');
  });

  indent.write('+ (nullable $className *)nullableFromList:(NSArray *)list ');
  indent.addScoped('{', '}', () {
    indent.writeln('return (list) ? [$className fromList:list] : nil;');
  });
}