dynamicSizeBcsType<T, Input> function

BcsType<T, Input> dynamicSizeBcsType<T, Input>({
  1. required String name,
  2. required T read(
    1. BcsReader
    ),
  3. required Uint8List serialize(
    1. Input, {
    2. BcsWriterOptions? options,
    }),
  4. void validate(
    1. Input
    )?,
})

Implementation

BcsType<T, Input> dynamicSizeBcsType<T, Input>({
  required String name,
  required T Function(BcsReader) read,
  required Uint8List Function(Input, {BcsWriterOptions? options}) serialize,
  void Function(Input)? validate,
}) {
  final type = BcsType<T, Input>(
    name: name,
    read: read,
    write: (value, writer) {
      for (final byte in serialize(value).toList()) {
        writer.write8(byte);
      }
    },
    serialize: serialize,
    validate: validate,
  );
  return type;
}