Skip to content
Projects
Groups
Snippets
Help
Loading...
Sign in / Register
Toggle navigation
P
protobuf
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Packages
Packages
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
submodule
protobuf
Commits
64678265
Commit
64678265
authored
May 02, 2015
by
Adam Greene
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
allow a message field to be unset
parent
4b2a6328
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
6 deletions
+15
-6
storage.c
ruby/ext/google/protobuf_c/storage.c
+3
-1
pom.xml
ruby/pom.xml
+1
-1
RubyMessage.java
.../src/main/java/com/google/protobuf/jruby/RubyMessage.java
+9
-4
basic.rb
ruby/tests/basic.rb
+2
-0
No files found.
ruby/ext/google/protobuf_c/storage.c
View file @
64678265
...
...
@@ -155,7 +155,9 @@ void native_slot_set_value_and_case(upb_fieldtype_t type, VALUE type_class,
break
;
}
case
UPB_TYPE_MESSAGE
:
{
if
(
CLASS_OF
(
value
)
!=
type_class
)
{
if
(
CLASS_OF
(
value
)
==
CLASS_OF
(
Qnil
))
{
value
=
Qnil
;
}
else
if
(
CLASS_OF
(
value
)
!=
type_class
)
{
rb_raise
(
rb_eTypeError
,
"Invalid type %s to assign to submessage field."
,
rb_class2name
(
CLASS_OF
(
value
)));
...
...
ruby/pom.xml
View file @
64678265
...
...
@@ -78,7 +78,7 @@
<dependency>
<groupId>
com.google.protobuf
</groupId>
<artifactId>
protobuf-java
</artifactId>
<version>
3.0.0-pre
</version>
<version>
3.0.0-
alpha-3-
pre
</version>
</dependency>
</dependencies>
</project>
ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
View file @
64678265
...
...
@@ -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
());
}
}
if
(
addValue
)
{
Utils
.
checkType
(
context
,
fieldType
,
value
,
(
RubyModule
)
typeClass
);
this
.
fields
.
put
(
fieldDescriptor
,
value
);
}
else
{
this
.
fields
.
remove
(
fieldDescriptor
);
}
}
}
return
context
.
runtime
.
getNil
();
...
...
ruby/tests/basic.rb
View file @
64678265
...
...
@@ -154,6 +154,8 @@ module BasicTest
assert
m
.
optional_bytes
==
"world"
m
.
optional_msg
=
TestMessage2
.
new
(
:foo
=>
42
)
assert
m
.
optional_msg
==
TestMessage2
.
new
(
:foo
=>
42
)
m
.
optional_msg
=
nil
assert
m
.
optional_msg
==
nil
end
def
test_ctor_args
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment