protobuf-ruby / beefcake

A sane Google Protocol Buffers library for Ruby
MIT License
276 stars 46 forks source link

Buffer.wire_for doesn't cope with packed+repeated fields #61

Open systemed opened 9 years ago

systemed commented 9 years ago

The wire type for packed, repeated fields is 2 (reference).

Currently, Buffer.wire_for parses the field type only, regardless of whether the field is packed+repeated. It'll therefore fail when decoding a packed+repeated field.

Quick fix is to add an extra line to Decode.decode in beefcake.rb:

      exp = Buffer.wire_for(fld.type)
      if fld.rule == :repeated && fld.opts[:packed] then exp = 2 end
systemed commented 9 years ago

A similar fix also needs to be applied to Encode.encode which, again, currently encodes as 0 when it should encode as 2.