map static method

CustomLayout map(
  1. Layout keyLayout,
  2. Layout valueLayout, {
  3. String? property,
})

map values

Implementation

static CustomLayout map(Layout keyLayout, Layout valueLayout,
    {String? property}) {
  final length = u32('length');
  final layout = struct([
    length,
    seq(
      MapEntryLayout(
          keyLayout: keyLayout, valueLayout: valueLayout, property: ""),
      offset(length, -length.span),
      property: 'values',
    ),
  ]);
  return CustomLayout<Map<String, dynamic>, Map<dynamic, dynamic>>(
    layout: layout,
    decoder: (data) {
      final List<MapEntry<dynamic, dynamic>> values =
          (data['values'] as List).cast();
      return Map.fromEntries(values);
    },
    encoder: (values) => {'values': values.entries.toList()},
    property: property,
  );
}