protobuf-ruby / beefcake

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

Problem with boolean required default value #58

Closed lephyrius closed 10 years ago

lephyrius commented 10 years ago

I have this code:

require 'beefcake'

class TestFalse
  include Beefcake::Message
  required :processed, :bool, 1, default: false

end

class TestTrue
  include Beefcake::Message
  required :processed, :bool, 1, default: true

end

puts TestTrue.new.encode

puts TestFalse.new.encode

This results in both getting: Beefcake::Message::RequiredFieldNotSetError: Field processed is required but nil They should just store the default value true and false.

bkerley commented 10 years ago

This is expected behavior. Default values are used when de-serializing an optional field. See https://developers.google.com/protocol-buffers/docs/proto#optional