lazyBcsType<T, Input> function

BcsType<T, Input> lazyBcsType<T, Input>(
  1. BcsType<T, Input> cb()
)

Implementation

BcsType<T, Input> lazyBcsType<T, Input>(BcsType<T, Input> Function() cb) {
  BcsType<T, Input>? lazyType;
  BcsType<T, Input> getType() {
    lazyType ??= cb();
    return lazyType!;
  }

  return BcsType<T, Input>(
    name: 'lazy',
    read: (data) => getType().read(data),
    serializedSize: (value, {BcsWriterOptions? options}) => getType().serializedSize(value),
    write: (value, writer) => getType().write(value, writer),
    serialize: (value, {options}) => getType().serialize(value, options: options).toBytes(),
  );
}