Descriptors.FieldDescriptor key_field = type.findFieldByName("key");
Descriptors.FieldDescriptor val_field = type.findFieldByName("val");
ITransientMap map = (ITransientMap)OrderedMap.EMPTY.asTransient();
while (iterator.hasNext()) {
DynamicMessage message = (DynamicMessage)iterator.next();
Object k = fromProtoValue(key_field, message.getField(key_field));
Object v = fromProtoValue(val_field, message.getField(val_field));
Object existing = map.valAt(k);
if (existing instanceof PersistentProtocolBufferMap) {
map = map.assoc(k, def.mapValue(field,
(PersistentProtocolBufferMap)existing,
(PersistentProtocolBufferMap)v));
} else if (existing instanceof IPersistentCollection) {
map = map.assoc(k, ((IPersistentCollection)existing).cons(v));
} else {
map = map.assoc(k, v);
}
}
return map.persistent();
} else if (options.getExtension(Extensions.set)) {
Descriptors.Descriptor type = field.getMessageType();
Descriptors.FieldDescriptor item_field = type.findFieldByName("item");
Descriptors.FieldDescriptor exists_field = type.findFieldByName("exists");
ITransientSet set = (ITransientSet)OrderedSet.EMPTY.asTransient();
while (iterator.hasNext()) {
DynamicMessage message = (DynamicMessage)iterator.next();
Object item = fromProtoValue(item_field, message.getField(item_field));
Boolean exists = (Boolean)message.getField(exists_field);
if (exists) {
set = (ITransientSet)set.conj(item);
} else {
try {
set = set.disjoin(item);
} catch (Exception e) {
e.printStackTrace();
}
}
}
return set.persistent();
}
}
List<Object> list = new ArrayList<Object>(values.size());
while (iterator.hasNext()) {
list.add(fromProtoValue(field, iterator.next(), use_extensions));
}
return PersistentVector.create(list);
} else {
switch (field.getJavaType()) {
case ENUM:
Descriptors.EnumValueDescriptor e = (Descriptors.EnumValueDescriptor)value;
if (use_extensions &&
field.getOptions().getExtension(Extensions.nullable) &&
field.getOptions().getExtension(nullExtension(field)).equals(e.getNumber())) {
return null;
} else {
return def.clojureEnumValue(e);
}
case MESSAGE:
Def fieldDef = PersistentProtocolBufferMap.Def.create(field.getMessageType(),
this.def.namingStrategy,
this.def.sizeLimit);
DynamicMessage message = (DynamicMessage)value;
// Total hack because getField() doesn't return an empty array for repeated messages.
if (field.isRepeated() && !message.isInitialized()) {
return fromProtoValue(field, new ArrayList<Object>(), use_extensions);
}
return new PersistentProtocolBufferMap(null, fieldDef, message);
default: