BcsType<T, Input> constructor

BcsType<T, Input>({
  1. required String name,
  2. required T read(
    1. BcsReader
    ),
  3. required void write(
    1. Input,
    2. BcsWriter
    ),
  4. Uint8List serialize(
    1. Input, {
    2. BcsWriterOptions? options,
    })?,
  5. int? serializedSize(
    1. Input, {
    2. BcsWriterOptions? options,
    })?,
  6. void validate(
    1. Input
    )?,
})

Implementation

BcsType({
  required this.name,
  required this.read,
  required void Function(Input, BcsWriter) write,
  Uint8List Function(Input, {BcsWriterOptions? options})? serialize,
  int? Function(Input, {BcsWriterOptions? options})? serializedSize,
  void Function(Input)? validate,
}) :
  this.serializedSize = serializedSize ?? ((_, {BcsWriterOptions? options}) => null),
  this._write = write,
  this._serialize = serialize ?? ((value, {options}) {
    final writer = BcsWriter(
      size: options?.size ?? serializedSize?.call(value) ?? 1024,
      maxSize: options?.maxSize,
      allocateSize: options?.allocateSize ?? 1024
    );
    write(value, writer);
    return writer.toBytes();
  }),
  this.validate = validate ?? ((_) {});