Sha256: d20fb9367c8003873bed6b9e3e1e37ca085e0fee3c085c39c54e5c3332417ca4

Contents?: true

Size: 927 Bytes

Versions: 7

Compression:

Stored size: 927 Bytes

Contents

require 'protobuf/wire_type'
require 'protobuf/exceptions'

module Protobuf
  class Decoder

    # Read bytes from +stream+ and pass to +message+ object.
    def self.decode_each_field(stream)
      until stream.eof?
        bits = Varint.decode(stream)
        wire_type = bits & 0x07
        tag = bits >> 3

        bytes = if wire_type == ::Protobuf::WireType::VARINT
                  Varint.decode(stream)
                elsif wire_type == ::Protobuf::WireType::LENGTH_DELIMITED
                  value_length = Varint.decode(stream)
                  stream.read(value_length)
                elsif wire_type == ::Protobuf::WireType::FIXED64
                  stream.read(8)
                elsif wire_type == ::Protobuf::WireType::FIXED32
                  stream.read(4)
                else
                  fail InvalidWireType, wire_type
                end

        yield(tag, bytes)
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
protobuf-3.6.12 lib/protobuf/decoder.rb
protobuf-3.6.11 lib/protobuf/decoder.rb
protobuf-3.6.10 lib/protobuf/decoder.rb
protobuf-3.6.9 lib/protobuf/decoder.rb
protobuf-3.7.0.pre0 lib/protobuf/decoder.rb
protobuf-3.6.7 lib/protobuf/decoder.rb
protobuf-3.6.6 lib/protobuf/decoder.rb