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
70544627
Commit
70544627
authored
Jun 27, 2018
by
Zachary Anker
Committed by
Paul Yang
Jun 27, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
When initializing a message, skip a field if value is nil (#3693)
parent
74f8e242
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
15 additions
and
0 deletions
+15
-0
message.c
ruby/ext/google/protobuf_c/message.c
+4
-0
RubyMessage.java
.../src/main/java/com/google/protobuf/jruby/RubyMessage.java
+2
-0
basic.rb
ruby/tests/basic.rb
+9
-0
No files found.
ruby/ext/google/protobuf_c/message.c
View file @
70544627
...
...
@@ -256,6 +256,10 @@ int Message_initialize_kwarg(VALUE key, VALUE val, VALUE _self) {
"Unknown field name '%s' in initialization map entry."
,
name
);
}
if
(
TYPE
(
val
)
==
T_NIL
)
{
return
0
;
}
if
(
is_map_field
(
f
))
{
VALUE
map
;
...
...
ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
View file @
70544627
...
...
@@ -86,6 +86,8 @@ public class RubyMessage extends RubyObject {
throw
runtime
.
newTypeError
(
"Expected string or symbols as hash keys in initialization map."
);
final
Descriptors
.
FieldDescriptor
fieldDescriptor
=
findField
(
context
,
key
);
if
(
value
.
isNil
())
return
;
if
(
Utils
.
isMapEntry
(
fieldDescriptor
))
{
if
(!(
value
instanceof
RubyHash
))
throw
runtime
.
newArgumentError
(
"Expected Hash object as initializer value for map field '"
+
key
.
asJavaString
()
+
"'."
);
...
...
ruby/tests/basic.rb
View file @
70544627
...
...
@@ -212,6 +212,15 @@ module BasicTest
assert_equal
[
'foo'
,
'bar'
],
m
.
repeated_string
end
def
test_ctor_nil_args
m
=
TestMessage
.
new
(
:optional_enum
=>
nil
,
:optional_int32
=>
nil
,
:optional_string
=>
nil
,
:optional_msg
=>
nil
)
assert_equal
:Default
,
m
.
optional_enum
assert_equal
0
,
m
.
optional_int32
assert_equal
""
,
m
.
optional_string
assert_nil
m
.
optional_msg
end
def
test_embeddedmsg_hash_init
m
=
TestEmbeddedMessageParent
.
new
(
:child_msg
=>
{
sub_child:
{
optional_int32:
1
}},
:number
=>
2
,
...
...
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