Sha256: 8c4f3c01ee11bfb8666766fe6aef02d229022d9450117840c57824f79e6fab23

Contents?: true

Size: 655 Bytes

Versions: 99

Compression:

Stored size: 655 Bytes

Contents

require 'protobuf/field/varint_field'

module Protobuf
  module Field
    class BoolField < VarintField
      def self.default
        false
      end

      def acceptable?(val)
        [true, false].include?(val)
      end

      def decode(value)
        value == 1
      end

      def define_getter
        super

        field = self
        @message_class.class_eval do
          define_method("#{field.getter_method_name}?") do
            field.warn_if_deprecated
            @values.fetch(field.name, field.default_value)
          end
        end
      end

      def encode(value)
        [value ? 1 : 0].pack('C')
      end
    end
  end
end

Version data entries

99 entries across 99 versions & 1 rubygems

Version Path
protobuf-2.6.5 lib/protobuf/field/bool_field.rb
protobuf-2.6.4-java lib/protobuf/field/bool_field.rb
protobuf-2.6.4 lib/protobuf/field/bool_field.rb
protobuf-2.6.3-java lib/protobuf/field/bool_field.rb
protobuf-2.6.3 lib/protobuf/field/bool_field.rb
protobuf-2.6.2-java lib/protobuf/field/bool_field.rb
protobuf-2.6.2 lib/protobuf/field/bool_field.rb
protobuf-2.6.1-java lib/protobuf/field/bool_field.rb
protobuf-2.6.1 lib/protobuf/field/bool_field.rb
protobuf-2.6.0-java lib/protobuf/field/bool_field.rb
protobuf-2.6.0 lib/protobuf/field/bool_field.rb
protobuf-2.5.5-java lib/protobuf/field/bool_field.rb
protobuf-2.5.5 lib/protobuf/field/bool_field.rb
protobuf-2.5.4-java lib/protobuf/field/bool_field.rb
protobuf-2.5.4 lib/protobuf/field/bool_field.rb
protobuf-2.5.3 lib/protobuf/field/bool_field.rb
protobuf-2.5.2-java lib/protobuf/field/bool_field.rb
protobuf-2.5.2 lib/protobuf/field/bool_field.rb
protobuf-2.5.1 lib/protobuf/field/bool_field.rb
protobuf-2.5.0-java lib/protobuf/field/bool_field.rb