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
2d514ce2
Commit
2d514ce2
authored
May 18, 2016
by
Josh Haberman
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed oneof behavior for enums and fixed JRuby.
parent
545527e8
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
24 additions
and
11 deletions
+24
-11
storage.c
ruby/ext/google/protobuf_c/storage.c
+11
-2
RubyMessage.java
.../src/main/java/com/google/protobuf/jruby/RubyMessage.java
+8
-4
basic.rb
ruby/tests/basic.rb
+5
-5
No files found.
ruby/ext/google/protobuf_c/storage.c
View file @
2d514ce2
...
...
@@ -57,14 +57,23 @@ size_t native_slot_size(upb_fieldtype_t type) {
}
}
VALUE
value_from_default
(
const
upb_fielddef
*
field
)
{
static
VALUE
value_from_default
(
const
upb_fielddef
*
field
)
{
switch
(
upb_fielddef_type
(
field
))
{
case
UPB_TYPE_FLOAT
:
return
DBL2NUM
(
upb_fielddef_defaultfloat
(
field
));
case
UPB_TYPE_DOUBLE
:
return
DBL2NUM
(
upb_fielddef_defaultdouble
(
field
));
case
UPB_TYPE_BOOL
:
return
upb_fielddef_defaultbool
(
field
)
?
Qtrue
:
Qfalse
;
case
UPB_TYPE_MESSAGE
:
return
Qnil
;
case
UPB_TYPE_ENUM
:
return
INT2NUM
(
upb_fielddef_defaultint32
(
field
));
case
UPB_TYPE_ENUM
:
{
const
upb_enumdef
*
enumdef
=
upb_fielddef_enumsubdef
(
field
);
int32_t
num
=
upb_fielddef_defaultint32
(
field
);
const
char
*
label
=
upb_enumdef_iton
(
enumdef
,
num
);
if
(
label
)
{
return
ID2SYM
(
rb_intern
(
label
));
}
else
{
return
INT2NUM
(
num
);
}
}
case
UPB_TYPE_INT32
:
return
INT2NUM
(
upb_fielddef_defaultint32
(
field
));
case
UPB_TYPE_INT64
:
return
LL2NUM
(
upb_fielddef_defaultint64
(
field
));;
case
UPB_TYPE_UINT32
:
return
UINT2NUM
(
upb_fielddef_defaultuint32
(
field
));
...
...
ruby/src/main/java/com/google/protobuf/jruby/RubyMessage.java
View file @
2d514ce2
...
...
@@ -592,13 +592,17 @@ public class RubyMessage extends RubyObject {
protected
IRubyObject
getField
(
ThreadContext
context
,
Descriptors
.
FieldDescriptor
fieldDescriptor
)
{
Descriptors
.
OneofDescriptor
oneofDescriptor
=
fieldDescriptor
.
getContainingOneof
();
if
(
oneofDescriptor
!=
null
)
{
if
(
oneofCases
.
containsKey
(
oneofDescriptor
))
{
if
(
oneofCases
.
get
(
oneofDescriptor
)
!=
fieldDescriptor
)
return
context
.
runtime
.
getNil
();
if
(
oneofCases
.
get
(
oneofDescriptor
)
==
fieldDescriptor
)
{
return
fields
.
get
(
fieldDescriptor
);
}
else
{
Descriptors
.
FieldDescriptor
oneofCase
=
builder
.
getOneofFieldDescriptor
(
oneofDescriptor
);
if
(
oneofCase
!=
fieldDescriptor
)
return
context
.
runtime
.
getNil
();
if
(
oneofCase
!=
fieldDescriptor
)
{
if
(
fieldDescriptor
.
getType
()
==
Descriptors
.
FieldDescriptor
.
Type
.
MESSAGE
)
{
return
context
.
runtime
.
getNil
();
}
else
{
return
wrapField
(
context
,
fieldDescriptor
,
fieldDescriptor
.
getDefaultValue
());
}
}
IRubyObject
value
=
wrapField
(
context
,
oneofCase
,
builder
.
getField
(
oneofCase
));
fields
.
put
(
fieldDescriptor
,
value
);
return
value
;
...
...
ruby/tests/basic.rb
View file @
2d514ce2
...
...
@@ -706,28 +706,28 @@ module BasicTest
assert
d
.
a
==
""
assert
d
.
b
==
0
assert
d
.
c
==
nil
assert
d
.
d
==
0
assert
d
.
d
==
:Default
assert
d
.
my_oneof
==
nil
d
.
a
=
"hi"
assert
d
.
a
==
"hi"
assert
d
.
b
==
0
assert
d
.
c
==
nil
assert
d
.
d
==
0
assert
d
.
d
==
:Default
assert
d
.
my_oneof
==
:a
d
.
b
=
42
assert
d
.
a
==
""
assert
d
.
b
==
42
assert
d
.
c
==
nil
assert
d
.
d
==
0
assert
d
.
d
==
:Default
assert
d
.
my_oneof
==
:b
d
.
c
=
TestMessage2
.
new
(
:foo
=>
100
)
assert
d
.
a
==
""
assert
d
.
b
==
0
assert
d
.
c
.
foo
==
100
assert
d
.
d
==
0
assert
d
.
d
==
:Default
assert
d
.
my_oneof
==
:c
d
.
d
=
:C
...
...
@@ -759,7 +759,7 @@ module BasicTest
assert
d4
.
a
==
""
assert
d4
.
b
==
0
assert
d4
.
c
.
foo
==
1
assert
d4
.
d
==
0
assert
d4
.
d
==
:Default
d5
=
OneofMessage
.
new
(
:a
=>
"hello"
)
assert
d5
.
a
==
"hello"
...
...
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