parseRecord static method
AsyncReply<IRecord>
parseRecord(
- DC data,
- int offset,
- int length,
- DistributedConnection connection, [
- Guid? classId = null,
Implementation
static AsyncReply<IRecord> parseRecord(
DC data, int offset, int length, DistributedConnection connection,
[Guid? classId = null]) {
var reply = new AsyncReply<IRecord>();
if (classId == null) {
classId = data.getGuid(offset);
offset += 16;
length -= 16;
}
var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record);
if (template != null) {
parseVarArray(data, offset, length, connection).then((ar) {
if (template.definedType != null) {
var record =
Warehouse.createInstance(template.definedType as Type) as IRecord;
Map<String, dynamic> value = {};
for (var i = 0; i < template.properties.length; i++)
value[template.properties[i].name] = ar[i];
record.deserialize(value);
reply.trigger(record);
} else {
var record = new Record();
for (var i = 0; i < template.properties.length; i++)
record.add(template.properties[i].name, ar[i]);
reply.trigger(record);
}
});
} else {
connection.getTemplate(classId)
..then((tmp) {
if (tmp != null) {
parseVarArray(data, offset, length, connection)
..then((ar) {
var record = new Record();
for (var i = 0; i < tmp.properties.length; i++)
record.add(tmp.properties[i].name, ar[i]);
reply.trigger(record);
});
} else {
reply.triggerError(AsyncException(ErrorType.Management,
ExceptionCode.TemplateNotFound.index, null));
}
})
..error((x) => reply.triggerError(x));
}
return reply;
}