writeMap<K, V> method

void writeMap<K, V>(
  1. Map<K, V> map,
  2. void writeKey(
    1. K
    ),
  3. void writeValue(
    1. V
    )
)

Encodes a map with length prefix

Format: u32 length + (key, value) pairs

Example:

final map = {'a': 1, 'b': 2};
encoder.writeMap(
  map,
  (key) => encoder.writeString(key),
  (value) => encoder.writeU32(value),
);

Implementation

void writeMap<K, V>(
  Map<K, V> map,
  void Function(K) writeKey,
  void Function(V) writeValue,
) {
  writeU32(map.length);
  for (final entry in map.entries) {
    writeKey(entry.key);
    writeValue(entry.value);
  }
}