deserializeStruct function

Object deserializeStruct(
  1. Type self,
  2. SerialBuffer buffer, {
  3. SerializerState? state,
  4. dynamic allowExtensions = true,
})

Implementation

Object deserializeStruct(Type self, SerialBuffer buffer, {SerializerState? state, allowExtensions = true}) {
  if (state == null) state = SerializerState();
  try {
    var result;
    if (self.base != null) {
      result = self.base!.deserialize?.call(self.base, buffer, state: state, allowExtensions: allowExtensions);
    } else {
      result = {};
    }
    for (var field in self.fields) {
      if (allowExtensions && field.type!.extensionOf != null && !buffer.haveReadData()) {
        state.skippedBinaryExtension = true;
      } else {
        result[field.name] =
            field.type!.deserialize?.call(field.type, buffer, state: state, allowExtensions: allowExtensions);
      }
    }
    return result;
  } catch (e) {
    throw e;
  }
}