readRuntimeObject<T extends Core<CoreContext>> function

T readRuntimeObject<T extends Core<CoreContext>>(
  1. BinaryReader reader,
  2. [T instance]
)

Implementation

T readRuntimeObject<T extends Core<CoreContext>>(BinaryReader reader,
    [T instance]) {
  int coreObjectKey = reader.readVarUint();

  var object = instance ?? RiveCoreContext.makeCoreInstance(coreObjectKey);
  if (object is! T) {
    return null;
  }

  while (true) {
    int propertyKey = reader.readVarUint();
    if (propertyKey == 0) {
      // Terminator. https://media.giphy.com/media/7TtvTUMm9mp20/giphy.gif
      break;
    }

    var fieldType = RiveCoreContext.coreType(propertyKey);
    if (fieldType == null) {
      throw UnsupportedError('Unsupported property key $propertyKey. '
          'A new runtime is likely necessary to play this file.');
    }

    RiveCoreContext.setObjectProperty(
        object, propertyKey, fieldType.deserialize(reader));
  }
  return object as T;
}