Sha256: aa0d0d1db3fa33fee64ae7f5c6686ba1b8812e112228433e384f2db148520179

Contents?: true

Size: 702 Bytes

Versions: 3

Compression:

Stored size: 702 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
          alias_method "#{field.getter}?", field.getter
        end
      end

    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
protobuf-3.4.4 lib/protobuf/field/bool_field.rb
protobuf-3.4.3 lib/protobuf/field/bool_field.rb
protobuf-3.4.2 lib/protobuf/field/bool_field.rb