transform<T2, Input2> method
BcsType<T2, Input2>
transform<T2, Input2>({
- String? name,
- required Input input(
- Input2
- required T2 output(
- T
- void validate(
- 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));
},
);
}