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
944693c4
Commit
944693c4
authored
Jun 19, 2018
by
igorpeshansky
Committed by
Paul Yang
Jun 19, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Google::Protobuf::Any.pack convenience class method. (#4719)
parent
0c3db026
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
13 additions
and
1 deletion
+13
-1
well_known_types.rb
ruby/lib/google/protobuf/well_known_types.rb
+6
-0
well_known_types_test.rb
ruby/tests/well_known_types_test.rb
+7
-1
No files found.
ruby/lib/google/protobuf/well_known_types.rb
View file @
944693c4
...
...
@@ -39,6 +39,12 @@ module Google
module
Protobuf
Any
.
class_eval
do
def
self
.
pack
(
msg
,
type_url_prefix
=
'type.googleapis.com/'
)
any
=
self
.
new
any
.
pack
(
msg
,
type_url_prefix
)
any
end
def
pack
(
msg
,
type_url_prefix
=
'type.googleapis.com/'
)
if
type_url_prefix
.
empty?
or
type_url_prefix
[
-
1
]
!=
'/'
then
self
.
type_url
=
"
#{
type_url_prefix
}
/
#{
msg
.
class
.
descriptor
.
name
}
"
...
...
ruby/tests/well_known_types_test.rb
View file @
944693c4
...
...
@@ -120,11 +120,17 @@ class TestWellKnownTypes < Test::Unit::TestCase
end
def
test_any
any
=
Google
::
Protobuf
::
Any
.
new
ts
=
Google
::
Protobuf
::
Timestamp
.
new
(
seconds:
12345
,
nanos:
6789
)
any
=
Google
::
Protobuf
::
Any
.
new
any
.
pack
(
ts
)
assert
any
.
is
(
Google
::
Protobuf
::
Timestamp
)
assert_equal
ts
,
any
.
unpack
(
Google
::
Protobuf
::
Timestamp
)
any
=
Google
::
Protobuf
::
Any
.
pack
(
ts
)
assert
any
.
is
(
Google
::
Protobuf
::
Timestamp
)
assert_equal
ts
,
any
.
unpack
(
Google
::
Protobuf
::
Timestamp
)
end
end
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