Sha256: bd7c0bff01039245284c8be0bc9a818aa13b25353aa76a6f1fbf434e1bb4921f

Contents?: true

Size: 816 Bytes

Versions: 16

Compression:

Stored size: 816 Bytes

Contents

require 'protobuf/field/varint_field'

module Protobuf
  module Field
    class BoolField < VarintField

      ##
      # Class Methods
      #

      def self.default
        false
      end


      ##
      # Public Instance Methods
      # #

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

      def decode(value)
        value == 1
      end

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

      private

      ##
      # Private Instance Methods
      #

      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

    end
  end
end

Version data entries

16 entries across 16 versions & 2 rubygems

Version Path
protobuffy-3.6.0 lib/protobuf/field/bool_field.rb
protobuffy-3.5.1 lib/protobuf/field/bool_field.rb
protobuffy-3.4.0 lib/protobuf/field/bool_field.rb
protobuffy-3.3.0 lib/protobuf/field/bool_field.rb
protobuffy-3.2.0 lib/protobuf/field/bool_field.rb
protobuffy-3.1.0 lib/protobuf/field/bool_field.rb
protobuf-3.2.0 lib/protobuf/field/bool_field.rb
protobuf-3.1.0 lib/protobuf/field/bool_field.rb
protobuf-3.0.5 lib/protobuf/field/bool_field.rb
protobuf-3.0.4 lib/protobuf/field/bool_field.rb
protobuf-3.0.3 lib/protobuf/field/bool_field.rb
protobuf-3.0.2 lib/protobuf/field/bool_field.rb
protobuf-3.0.1 lib/protobuf/field/bool_field.rb
protobuf-3.0.0 lib/protobuf/field/bool_field.rb
protobuf-3.0.0.rc2 lib/protobuf/field/bool_field.rb
protobuf-3.0.0.rc1 lib/protobuf/field/bool_field.rb