|
|
@ -62,6 +62,9 @@ import java.util.List; |
|
|
|
import java.util.Map; |
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
public class RubyMessage extends RubyObject { |
|
|
|
public class RubyMessage extends RubyObject { |
|
|
|
|
|
|
|
private final String DEFAULT_VALUE = "google.protobuf.FieldDescriptorProto.default_value"; |
|
|
|
|
|
|
|
private final String TYPE = "type"; |
|
|
|
|
|
|
|
|
|
|
|
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) { |
|
|
|
public RubyMessage(Ruby runtime, RubyClass klazz, Descriptor descriptor) { |
|
|
|
super(runtime, klazz); |
|
|
|
super(runtime, klazz); |
|
|
|
|
|
|
|
|
|
|
@ -677,6 +680,8 @@ public class RubyMessage extends RubyObject { |
|
|
|
throw context.runtime.newRuntimeError("Recursion limit exceeded during encoding."); |
|
|
|
throw context.runtime.newRuntimeError("Recursion limit exceeded during encoding."); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
RubySymbol typeBytesSymbol = RubySymbol.newSymbol(context.runtime, "TYPE_BYTES"); |
|
|
|
|
|
|
|
|
|
|
|
// Handle the typical case where the fields.keySet contain the fieldDescriptors
|
|
|
|
// Handle the typical case where the fields.keySet contain the fieldDescriptors
|
|
|
|
for (FieldDescriptor fieldDescriptor : fields.keySet()) { |
|
|
|
for (FieldDescriptor fieldDescriptor : fields.keySet()) { |
|
|
|
IRubyObject value = fields.get(fieldDescriptor); |
|
|
|
IRubyObject value = fields.get(fieldDescriptor); |
|
|
@ -707,14 +712,13 @@ public class RubyMessage extends RubyObject { |
|
|
|
* stringDefaultValue}. |
|
|
|
* stringDefaultValue}. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
boolean isDefaultStringForBytes = false; |
|
|
|
boolean isDefaultStringForBytes = false; |
|
|
|
|
|
|
|
if (DEFAULT_VALUE.equals(fieldDescriptor.getFullName())) { |
|
|
|
FieldDescriptor enumFieldDescriptorForType = |
|
|
|
FieldDescriptor enumFieldDescriptorForType = |
|
|
|
this.builder.getDescriptorForType().findFieldByName("type"); |
|
|
|
this.builder.getDescriptorForType().findFieldByName(TYPE); |
|
|
|
String type = enumFieldDescriptorForType == null ? |
|
|
|
if (typeBytesSymbol.equals(fields.get(enumFieldDescriptorForType))) { |
|
|
|
null : fields.get(enumFieldDescriptorForType).toString(); |
|
|
|
|
|
|
|
if (type != null && type.equals("TYPE_BYTES") && |
|
|
|
|
|
|
|
fieldDescriptor.getFullName().equals("google.protobuf.FieldDescriptorProto.default_value")) { |
|
|
|
|
|
|
|
isDefaultStringForBytes = true; |
|
|
|
isDefaultStringForBytes = true; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth, recursionLimit, isDefaultStringForBytes)); |
|
|
|
builder.setField(fieldDescriptor, convert(context, fieldDescriptor, value, depth, recursionLimit, isDefaultStringForBytes)); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|