transform<T2, Input2> method

BcsType<T2, Input2> transform<T2, Input2>({
  1. String? name,
  2. required Input input(
    1. Input2
    ),
  3. required T2 output(
    1. T
    ),
  4. void validate(
    1. Input2
    )?,
})

Implementation

BcsType<T2, Input2> transform<T2, Input2>({
  String? name,
  required Input Function(Input2) input,
  required T2 Function(T) output,
  void Function(Input2)? validate,
}) {
  return BcsType<T2, Input2>(
    name: name ?? this.name,
    read: (reader) => output(this.read(reader)),
    write: (value, writer) => this._write(input(value), writer),
    serializedSize: (value, {BcsWriterOptions? options}) => this.serializedSize(input(value)),
    serialize: (value, {options}) => this._serialize(input(value), options: options),
    validate: (value) {
      validate?.call(value);
      this.validate(input(value));
    },
  );
}