Decoder<T> typedef

Decoder<T> = T Function(ConstantReader constantReader)

Typedef of a function with return type T and an input argument of type ConstantReader.

Functions of this type may be registered as decoders with the (singleton) instance of GenericReader.


class CustomType{
 const CustomType({,});
 final int id;
 final String name;

final reader = GenericReader();
reader.addDecoder<CustomType>((constantReader) {
  // Read constructor arguments.
  final id = constantReader.peek('id').intValue;
  final name = constantReader.peek('name').stringValue;
  // Return an instance of CustomType
  return CustomType(id: id, name: name);


typedef Decoder<T> = T Function(ConstantReader constantReader);