Class: Protobuf::Decoder
- Inherits:
-
Object
- Object
- Protobuf::Decoder
- Defined in:
- lib/protobuf/message/decoder.rb
Class Method Summary collapse
Instance Method Summary collapse
- #decode(stream = @stream, message = @message) ⇒ Object
-
#initialize(stream = nil, message = nil) ⇒ Decoder
constructor
A new instance of Decoder.
Constructor Details
#initialize(stream = nil, message = nil) ⇒ Decoder
Returns a new instance of Decoder.
13 14 15 |
# File 'lib/protobuf/message/decoder.rb', line 13 def initialize(stream=nil, =nil) @stream, @message = stream, end |
Class Method Details
.decode(stream, message) ⇒ Object
8 9 10 |
# File 'lib/protobuf/message/decoder.rb', line 8 def decode(stream, ) self.new(stream, ).decode end |
Instance Method Details
#decode(stream = @stream, message = @message) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/protobuf/message/decoder.rb', line 17 def decode(stream=@stream, =@message) until stream.eof? tag, wire_type = read_key stream bytes = case wire_type when WireType::VARINT read_varint stream when WireType::FIXED64 read_fixed64 stream when WireType::LENGTH_DELIMITED read_length_delimited stream when WireType::START_GROUP read_start_group stream when WireType::END_GROUP read_end_group stream when WireType::FIXED32 read_fixed32 stream else raise InvalidWireType.new(wire_type) end .set_field tag, bytes end end |