serializeStruct function
void
serializeStruct(
- Type self,
- SerialBuffer buffer,
- dynamic data, {
- SerializerState? state,
- dynamic allowExtensions = true,
Implementation
void serializeStruct(Type self, SerialBuffer buffer, dynamic data, {SerializerState? state, allowExtensions = true}) {
if (state == null) state = SerializerState();
// try {
if (self.base != null) {
self.base!.serialize?.call(self.base, buffer, data, state: state, allowExtensions: allowExtensions);
}
Map dy = data as dynamic;
for (var field in self.fields) {
if (dy.containsKey(field.name)) {
if (state.skippedBinaryExtension) {
throw 'unexpected ' + self.name + '.' + field.name;
}
field.type!.serialize?.call(field.type, buffer, dy[field.name],
state: state, allowExtensions: allowExtensions && field == self.fields[self.fields.length - 1]);
} else {
if (allowExtensions && field.type!.extensionOf != null) {
state.skippedBinaryExtension = true;
} else {
throw 'missing ' + self.name + '.' + field.name + ' (type=' + field.type!.name + ')';
}
}
}
// } catch (e) {
// throw e;
// }
}