From 6e679385535e6e80f29096b185fd75d0242ecd7b Mon Sep 17 00:00:00 2001 From: Ahmed Zamil Date: Tue, 17 Dec 2024 14:12:42 +0300 Subject: [PATCH] RecordParser --- lib/src/Data/DataDeserializer.dart | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/lib/src/Data/DataDeserializer.dart b/lib/src/Data/DataDeserializer.dart index 0adb6a2..1d83e98 100644 --- a/lib/src/Data/DataDeserializer.dart +++ b/lib/src/Data/DataDeserializer.dart @@ -161,11 +161,19 @@ class DataDeserializer { var template = Warehouse.getTemplateByClassId(classId, TemplateType.Record); - var initRecord = (TypeTemplate template) => + var initRecord = (TypeTemplate? template) => listParser(data, offset, length, connection, requestSequence).then((r) { var ar = r as List; IRecord record; + if (template == null) { + reply.triggerError(AsyncException( + ErrorType.Management, + ExceptionCode.TemplateNotFound.index, + "Template not found for record.")); + return; + } + if (template.definedType != null) { record = Warehouse.createInstance(template.definedType!) as IRecord; } else { @@ -184,19 +192,12 @@ class DataDeserializer { if (template != null) { initRecord(template); - } else { - if (connection == null) - throw Exception("Can't parse record with no connection"); - + } else if (connection != null) { connection.getTemplate(classId).then((tmp) { - if (tmp == null) - reply.triggerError(AsyncException( - ErrorType.Management, - ExceptionCode.TemplateNotFound.index, - "Template not found for record.")); - else - initRecord(tmp); + initRecord(tmp); }).error((x) => reply.triggerError(x)); + } else { + initRecord(null); } return reply; @@ -322,10 +323,10 @@ class DataDeserializer { offset += valueRep.size; length -= valueRep.size; - var keyRuntimeType = keyRep.type.getRuntimeType(); - var map = keyRuntimeType == null ? Map() : Warehouse.createMap(keyRuntimeType); + var map = + keyRuntimeType == null ? Map() : Warehouse.createMap(keyRuntimeType); var rt = new AsyncReply(); var results = new AsyncBag();