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.8.0.beta6 lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta5-java lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta5 lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta4-java lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta4 lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta3-java lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta3 lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta2-java lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta2 lib/protobuf/field/bool_field.rb
protobuf-2.7.11-java lib/protobuf/field/bool_field.rb
protobuf-2.7.11 lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta1-java lib/protobuf/field/bool_field.rb
protobuf-2.8.0.beta1 lib/protobuf/field/bool_field.rb
protobuf-2.7.10-java lib/protobuf/field/bool_field.rb
protobuf-2.7.10 lib/protobuf/field/bool_field.rb
protobuf-2.7.9-java lib/protobuf/field/bool_field.rb
protobuf-2.7.9 lib/protobuf/field/bool_field.rb
protobuf-2.7.8-java lib/protobuf/field/bool_field.rb
protobuf-2.7.8 lib/protobuf/field/bool_field.rb
protobuf-2.7.7-java lib/protobuf/field/bool_field.rb