From 944693c44c4cd2de8ed3516c2406c2c1fcec5cbb Mon Sep 17 00:00:00 2001 From: igorpeshansky Date: Tue, 19 Jun 2018 16:26:41 -0400 Subject: Add Google::Protobuf::Any.pack convenience class method. (#4719) --- ruby/lib/google/protobuf/well_known_types.rb | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'ruby/lib') diff --git a/ruby/lib/google/protobuf/well_known_types.rb b/ruby/lib/google/protobuf/well_known_types.rb index 921ddbc0..3e759591 100644 --- a/ruby/lib/google/protobuf/well_known_types.rb +++ b/ruby/lib/google/protobuf/well_known_types.rb @@ -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}" -- cgit v1.2.3