bcsVector<T> static method

CustomLayout<Map<String, dynamic>, List<T>> bcsVector<T>(
  1. Layout<T> elementLayout, {
  2. String? property,
})

Serializes and deserializes a vector (list) of elements using the provided elementLayout.

The vector layout includes:

  • Length prefix (using bcsOffset).
  • Serialized list of elements (values).

T is the type of elements in the list. property is optional for nested mapping.

Implementation

static CustomLayout<Map<String, dynamic>, List<T>> bcsVector<T>(
    Layout<T> elementLayout,
    {String? property}) {
  final layout = LayoutConst.struct(
      [LayoutConst.seq(elementLayout, bcsOffset(), property: 'values')]);
  return CustomLayout<Map<String, dynamic>, List<T>>(
      layout: layout,
      encoder: (data) => {"values": data},
      decoder: (data) => (data["values"] as List).cast<T>(),
      property: property);
}