public void write(Packer pk, Map<K,V> target, boolean required) throws IOException {
if (!(target instanceof Map)) {
if (target == null) {
if (required) {
throw new MessageTypeException("Attempted to write null");
}
pk.writeNil();
return;
}
throw new MessageTypeException("Target is not a Map but "+target.getClass());
}
Map<K,V> map = (Map<K,V>) target;
pk.writeMapBegin(map.size());
for (Map.Entry<K,V> pair : map.entrySet()) {
keyTemplate.write(pk, pair.getKey());