diff options
author | Adam Greene <adam.greene@gmail.com> | 2015-05-02 13:48:23 -0700 |
---|---|---|
committer | Adam Greene <adam.greene@gmail.com> | 2015-05-02 13:48:23 -0700 |
commit | 64678265c5ae28998d031900c2de52419a8ed7e4 (patch) | |
tree | 077e1dc1ded48dde7216d11255b1b3c30ea071d4 /ruby/src/main/java/com | |
parent | 4b2a6328bd2fe6a1d58bbe536c512c566a2673d3 (diff) | |
download | protobuf-64678265c5ae28998d031900c2de52419a8ed7e4.tar.gz protobuf-64678265c5ae28998d031900c2de52419a8ed7e4.tar.bz2 protobuf-64678265c5ae28998d031900c2de52419a8ed7e4.zip |
allow a message field to be unset
Diffstat (limited to 'ruby/src/main/java/com')
-rw-r--r-- | ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java | 15 |
1 files changed, 10 insertions, 5 deletions
diff --git a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java index 04bc0b76..9ddadfcd 100644 --- a/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java +++ b/ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java @@ -659,14 +659,14 @@ public class RubyMessage extends RubyObject { } else { Descriptors.FieldDescriptor.Type fieldType = fieldDescriptor.getType(); IRubyObject typeClass = context.runtime.getObject(); + boolean addValue = true; if (fieldType == Descriptors.FieldDescriptor.Type.MESSAGE) { typeClass = ((RubyDescriptor) getDescriptorForField(context, fieldDescriptor)).msgclass(context); + if (value.isNil()){ + addValue = false; + } } else if (fieldType == Descriptors.FieldDescriptor.Type.ENUM) { typeClass = ((RubyEnumDescriptor) getDescriptorForField(context, fieldDescriptor)).enummodule(context); - } - Utils.checkType(context, fieldType, value, (RubyModule) typeClass); - // Convert integer enum to symbol - if (fieldType == Descriptors.FieldDescriptor.Type.ENUM) { Descriptors.EnumDescriptor enumDescriptor = fieldDescriptor.getEnumType(); if (Utils.isRubyNum(value)) { Descriptors.EnumValueDescriptor val = @@ -674,7 +674,12 @@ public class RubyMessage extends RubyObject { if (val.getIndex() != -1) value = context.runtime.newSymbol(val.getName()); } } - this.fields.put(fieldDescriptor, value); + if (addValue) { + Utils.checkType(context, fieldType, value, (RubyModule) typeClass); + this.fields.put(fieldDescriptor, value); + } else { + this.fields.remove(fieldDescriptor); + } } } return context.runtime.getNil(); |