Sha256: f5bcbc11977f3ba28cb4758a237799eb23b05510d95bb92905ecd0d803496d92

Contents?: true

Size: 498 Bytes

Versions: 24

Compression:

Stored size: 498 Bytes

Contents

require 'protobuf/field/varint_field'

module Protobuf
  module Field
    class IntegerField < VarintField

      ##
      # Public Instance Methods
      #

      def decode(value)
        value -= 0x1_0000_0000_0000_0000 if (value & 0x8000_0000_0000_0000).nonzero?
        value
      end

      def encode(value)
        # original Google's library uses 64bits integer for negative value
        ::Protobuf::Field::VarintField.encode(value & 0xffff_ffff_ffff_ffff)
      end

    end
  end
end

Version data entries

24 entries across 24 versions & 2 rubygems

Version Path
protobuffy-3.6.0 lib/protobuf/field/integer_field.rb
protobuffy-3.5.1 lib/protobuf/field/integer_field.rb
protobuffy-3.4.0 lib/protobuf/field/integer_field.rb
protobuffy-3.3.0 lib/protobuf/field/integer_field.rb
protobuffy-3.2.0 lib/protobuf/field/integer_field.rb
protobuffy-3.1.0 lib/protobuf/field/integer_field.rb
protobuf-3.3.6 lib/protobuf/field/integer_field.rb
protobuf-3.3.5 lib/protobuf/field/integer_field.rb
protobuf-3.3.4 lib/protobuf/field/integer_field.rb
protobuf-3.3.3 lib/protobuf/field/integer_field.rb
protobuf-3.3.2 lib/protobuf/field/integer_field.rb
protobuf-3.3.1 lib/protobuf/field/integer_field.rb
protobuf-3.3.0 lib/protobuf/field/integer_field.rb
protobuf-3.2.1 lib/protobuf/field/integer_field.rb
protobuf-3.2.0 lib/protobuf/field/integer_field.rb
protobuf-3.1.0 lib/protobuf/field/integer_field.rb
protobuf-3.0.5 lib/protobuf/field/integer_field.rb
protobuf-3.0.4 lib/protobuf/field/integer_field.rb
protobuf-3.0.3 lib/protobuf/field/integer_field.rb
protobuf-3.0.2 lib/protobuf/field/integer_field.rb