map<K, V> function
PayloadType<Map<K, V> >
map<K, V>(
- PayloadType<
K> keyType, - PayloadType<
V> valueType, { - PayloadType<
int> lengthType = uint8,
Store a map of K and V as binary data.
It stores the length of the map first by using the lengthType and then
stores each key value pair in the map by looping through the keys, storing
the key first using keyType and then the value of the key using
valueType.
It has a byte length of:
lengthType.length(map.length) + map.entries.fold(0,
(p, e) => p + keyType.length(e.key) + valueType.length(e.value),
)
Usage:
payload.set(map(string8, uint16), {'1': 1, '2': 2, '3': 3, '4': 4});
Implementation
PayloadType<Map<K, V>> map<K, V>(
PayloadType<K> keyType,
PayloadType<V> valueType, {
PayloadType<int> lengthType = uint8,
}) {
return _Map(keyType, valueType, lengthType);
}