@@ -50,6 +50,35 @@ def response_bytes
5050 end
5151
5252 Protobuf ::Field ::BaseField . module_eval do
53+ def define_set_method!
54+ end
55+
56+ def set_without_options ( message_instance , bytes )
57+ return message_instance [ name ] = decode ( bytes ) unless repeated?
58+
59+ if map?
60+ hash = message_instance [ name ]
61+ entry = decode ( bytes )
62+ # decoded value could be nil for an
63+ # enum value that is not recognized
64+ hash [ entry . key ] = entry . value unless entry . value . nil?
65+ return hash [ entry . key ]
66+ end
67+
68+ return message_instance [ name ] << decode ( bytes ) unless packed?
69+
70+ array = message_instance [ name ]
71+ stream = StringIO . new ( bytes )
72+
73+ if wire_type == ::Protobuf ::WireType ::VARINT
74+ array << decode ( Varint . decode ( stream ) ) until stream . eof?
75+ elsif wire_type == ::Protobuf ::WireType ::FIXED64
76+ array << decode ( stream . read ( 8 ) ) until stream . eof?
77+ elsif wire_type == ::Protobuf ::WireType ::FIXED32
78+ array << decode ( stream . read ( 4 ) ) until stream . eof?
79+ end
80+ end
81+
5382 # Sets a MessageField that is known to be an option.
5483 # We must allow fields to be set one at a time, as option syntax allows us to
5584 # set each field within the option using a separate "option" line.
@@ -72,6 +101,7 @@ def set_with_options(message_instance, bytes)
72101
73102 set_without_options ( message_instance , bytes )
74103 end
104+ alias_method :set , :set_with_options
75105
76106 def option_set ( message_field , subfield , subvalue )
77107 return unless yield
@@ -85,9 +115,6 @@ def option_set(message_field, subfield, subvalue)
85115 message_field [ subfield . tag ] = subvalue
86116 end
87117 end
88-
89- alias_method :set_without_options , :set
90- alias_method :set , :set_with_options
91118 end
92119 end
93120end
0 commit comments