Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Detect whether a field has an extension #60

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 11 additions & 14 deletions src/flatland/protobuf/PersistentProtocolBufferMap.java
Original file line number Diff line number Diff line change
Expand Up @@ -389,17 +389,14 @@ public DynamicMessage.Builder builder() {
}
}

protected Object fromProtoValue(Descriptors.FieldDescriptor field, Object value) {
return fromProtoValue(field, value, true);
}

static Keyword k_key = Keyword.intern("key");
static Keyword k_val = Keyword.intern("val");
static Keyword k_item = Keyword.intern("item");
static Keyword k_exists = Keyword.intern("exists");

protected Object fromProtoValue(Descriptors.FieldDescriptor field, Object value,
boolean use_extensions) {
protected Object fromProtoValue(Descriptors.FieldDescriptor field, Object value) {
boolean use_extensions = field.toProto().hasExtendee();

if (value instanceof List) {
List<?> values = (List<?>)value;
Iterator<?> iterator = values.iterator();
Expand Down Expand Up @@ -474,7 +471,7 @@ protected Object fromProtoValue(Descriptors.FieldDescriptor field, Object value,
}
List<Object> list = new ArrayList<Object>(values.size());
while (iterator.hasNext()) {
list.add(fromProtoValue(field, iterator.next(), use_extensions));
list.add(fromProtoValue(field, iterator.next()));
}
return PersistentVector.create(list);
} else {
Expand All @@ -496,7 +493,7 @@ protected Object fromProtoValue(Descriptors.FieldDescriptor field, Object 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 fromProtoValue(field, new ArrayList<Object>());
}

return new PersistentProtocolBufferMap(null, fieldDef, message);
Expand Down Expand Up @@ -710,23 +707,23 @@ public IMapEntry entryAt(Object key) {

@Override
public Object valAt(Object key) {
return getValAt(key, true);
return getValAt(key);
}

@Override
public Object valAt(Object key, Object notFound) {
return getValAt(key, notFound, true);
return getValAt(key, notFound);
}

public Object getValAt(Object key, boolean use_extensions) {
Object val = getValAt(key, sentinel, use_extensions);
public Object getValAt(Object key) {
Object val = getValAt(key, sentinel);
return (val == sentinel) ? null : val;
}

public Object getValAt(Object key, Object notFound, boolean use_extensions) {
public Object getValAt(Object key, Object notFound) {
Descriptors.FieldDescriptor field = def.fieldDescriptor(key);
if (protoContainsKey(key)) {
return fromProtoValue(field, message().getField(field), use_extensions);
return fromProtoValue(field, message().getField(field));
} else {
return RT.get(ext, key, notFound);
}
Expand Down