writeClassEncode method
void
writeClassEncode(
- CppOptions generatorOptions,
- Root root,
- Indent indent,
- Class classDefinition, {
- required String dartPackageName,
override
Writes a single class encode method to indent
.
Implementation
@override
void writeClassEncode(
CppOptions generatorOptions,
Root root,
Indent indent,
Class classDefinition, {
required String dartPackageName,
}) {
_writeFunctionDefinition(indent, 'ToEncodableList',
scope: classDefinition.name,
returnType: 'EncodableList',
isConst: true, body: () {
indent.writeln('EncodableList list;');
indent.writeln('list.reserve(${classDefinition.fields.length});');
for (final NamedType field
in getFieldsInSerializationOrder(classDefinition)) {
final HostDatatype hostDatatype =
getFieldHostDatatype(field, _shortBaseCppTypeForBuiltinDartType);
final String encodableValue = _wrappedHostApiArgumentExpression(
root,
_makeInstanceVariableName(field),
field.type,
hostDatatype,
true,
);
indent.writeln('list.push_back($encodableValue);');
}
indent.writeln('return list;');
});
}