msgpack 1.2.10-java → 1.3.0-java
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/msgpack.rb +2 -0
- data/lib/msgpack/msgpack.jar +0 -0
- data/lib/msgpack/time.rb +29 -0
- data/lib/msgpack/timestamp.rb +76 -0
- data/lib/msgpack/version.rb +1 -1
- data/spec/timestamp_spec.rb +117 -0
- metadata +7 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA256:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 50acb5f580ca3bc5003de45dc2348d7461365b6f262bb39d5c06095b31889dd2
         | 
| 4 | 
            +
              data.tar.gz: 4071ce9a089de10c2a3f583c27aaa9f8ca952766d29a9a16fd6112154fa28752
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 9d75669baa1bc0e075909195655dc4c06481ce659d7ad1368b07502279c4f5300e6e9c130ca1d3d1674aaecf2e5c3350b02a1dd5f04c66a374384030ba28680d
         | 
| 7 | 
            +
              data.tar.gz: 7bbaef49fe323be3f172eb961e184608333643a37202ca5ecda86deaa2b3ea01ab3618828e1b88dd617798a79953255bfc83c6cbcad4d347b027ee35825bc0ab
         | 
    
        data/lib/msgpack.rb
    CHANGED
    
    
    
        data/lib/msgpack/msgpack.jar
    CHANGED
    
    | Binary file | 
    
        data/lib/msgpack/time.rb
    ADDED
    
    | @@ -0,0 +1,29 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            # MessagePack extention packer and unpacker for built-in Time class
         | 
| 4 | 
            +
            module MessagePack
         | 
| 5 | 
            +
              module Time
         | 
| 6 | 
            +
                # 3-arg Time.at is available Ruby >= 2.5
         | 
| 7 | 
            +
                TIME_AT_3_AVAILABLE = begin
         | 
| 8 | 
            +
                                        !!::Time.at(0, 0, :nanosecond)
         | 
| 9 | 
            +
                                      rescue ArgumentError
         | 
| 10 | 
            +
                                        false
         | 
| 11 | 
            +
                                      end
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                Unpacker = if TIME_AT_3_AVAILABLE
         | 
| 14 | 
            +
                             lambda do |payload|
         | 
| 15 | 
            +
                               tv = MessagePack::Timestamp.from_msgpack_ext(payload)
         | 
| 16 | 
            +
                               ::Time.at(tv.sec, tv.nsec, :nanosecond)
         | 
| 17 | 
            +
                             end
         | 
| 18 | 
            +
                           else
         | 
| 19 | 
            +
                             lambda do |payload|
         | 
| 20 | 
            +
                               tv = MessagePack::Timestamp.from_msgpack_ext(payload)
         | 
| 21 | 
            +
                               ::Time.at(tv.sec, tv.nsec / 1000.0)
         | 
| 22 | 
            +
                             end
         | 
| 23 | 
            +
                           end
         | 
| 24 | 
            +
             | 
| 25 | 
            +
                Packer = lambda { |time|
         | 
| 26 | 
            +
                  MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec)
         | 
| 27 | 
            +
                }
         | 
| 28 | 
            +
              end
         | 
| 29 | 
            +
            end
         | 
| @@ -0,0 +1,76 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            module MessagePack
         | 
| 4 | 
            +
              class Timestamp # a.k.a. "TimeSpec"
         | 
| 5 | 
            +
                # Because the byte-order of MessagePack is big-endian in,
         | 
| 6 | 
            +
                # pack() and unpack() specifies ">".
         | 
| 7 | 
            +
                # See https://docs.ruby-lang.org/en/trunk/Array.html#method-i-pack for details.
         | 
| 8 | 
            +
             | 
| 9 | 
            +
                # The timestamp extension type defined in the MessagePack spec.
         | 
| 10 | 
            +
                # See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type for details.
         | 
| 11 | 
            +
                TYPE = -1
         | 
| 12 | 
            +
             | 
| 13 | 
            +
                TIMESTAMP32_MAX_SEC = (1 << 32) - 1
         | 
| 14 | 
            +
                TIMESTAMP64_MAX_SEC = (1 << 34) - 1
         | 
| 15 | 
            +
             | 
| 16 | 
            +
                # @return [Integer]
         | 
| 17 | 
            +
                attr_reader :sec
         | 
| 18 | 
            +
             | 
| 19 | 
            +
                # @return [Integer]
         | 
| 20 | 
            +
                attr_reader :nsec
         | 
| 21 | 
            +
             | 
| 22 | 
            +
                # @param [Integer] sec
         | 
| 23 | 
            +
                # @param [Integer] nsec
         | 
| 24 | 
            +
                def initialize(sec, nsec)
         | 
| 25 | 
            +
                  @sec = sec
         | 
| 26 | 
            +
                  @nsec = nsec
         | 
| 27 | 
            +
                end
         | 
| 28 | 
            +
             | 
| 29 | 
            +
                def self.from_msgpack_ext(data)
         | 
| 30 | 
            +
                  case data.length
         | 
| 31 | 
            +
                  when 4
         | 
| 32 | 
            +
                    # timestamp32 (sec: uint32be)
         | 
| 33 | 
            +
                    sec, = data.unpack('L>')
         | 
| 34 | 
            +
                    new(sec, 0)
         | 
| 35 | 
            +
                  when 8
         | 
| 36 | 
            +
                    # timestamp64 (nsec: uint30be, sec: uint34be)
         | 
| 37 | 
            +
                    n, s = data.unpack('L>2')
         | 
| 38 | 
            +
                    sec = ((n & 0b11) << 32) | s
         | 
| 39 | 
            +
                    nsec = n >> 2
         | 
| 40 | 
            +
                    new(sec, nsec)
         | 
| 41 | 
            +
                  when 12
         | 
| 42 | 
            +
                    # timestam96 (nsec: uint32be, sec: int64be)
         | 
| 43 | 
            +
                    nsec, sec = data.unpack('L>q>')
         | 
| 44 | 
            +
                    new(sec, nsec)
         | 
| 45 | 
            +
                  else
         | 
| 46 | 
            +
                    raise MalformedFormatError, "Invalid timestamp data size: #{data.length}"
         | 
| 47 | 
            +
                  end
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                def self.to_msgpack_ext(sec, nsec)
         | 
| 51 | 
            +
                  if sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC
         | 
| 52 | 
            +
                    if nsec === 0 && sec <= TIMESTAMP32_MAX_SEC
         | 
| 53 | 
            +
                      # timestamp32 = (sec: uint32be)
         | 
| 54 | 
            +
                      [sec].pack('L>')
         | 
| 55 | 
            +
                    else
         | 
| 56 | 
            +
                      # timestamp64 (nsec: uint30be, sec: uint34be)
         | 
| 57 | 
            +
                      nsec30 = nsec << 2
         | 
| 58 | 
            +
                      sec_high2 = sec << 32 # high 2 bits (`x & 0b11` is redandunt)
         | 
| 59 | 
            +
                      sec_low32 = sec & 0xffffffff # low 32 bits
         | 
| 60 | 
            +
                      [nsec30 | sec_high2, sec_low32].pack('L>2')
         | 
| 61 | 
            +
                    end
         | 
| 62 | 
            +
                  else
         | 
| 63 | 
            +
                    # timestamp96 (nsec: uint32be, sec: int64be)
         | 
| 64 | 
            +
                    [nsec, sec].pack('L>q>')
         | 
| 65 | 
            +
                  end
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                def to_msgpack_ext
         | 
| 69 | 
            +
                  self.class.to_msgpack_ext(sec, nsec)
         | 
| 70 | 
            +
                end
         | 
| 71 | 
            +
             | 
| 72 | 
            +
                def ==(other)
         | 
| 73 | 
            +
                  other.class == self.class && sec == other.sec && nsec == other.nsec
         | 
| 74 | 
            +
                end
         | 
| 75 | 
            +
              end
         | 
| 76 | 
            +
            end
         | 
    
        data/lib/msgpack/version.rb
    CHANGED
    
    
| @@ -0,0 +1,117 @@ | |
| 1 | 
            +
            # frozen_string_literal: true
         | 
| 2 | 
            +
             | 
| 3 | 
            +
            require 'spec_helper'
         | 
| 4 | 
            +
             | 
| 5 | 
            +
            describe MessagePack::Timestamp do
         | 
| 6 | 
            +
              describe 'malformed format' do
         | 
| 7 | 
            +
                it do
         | 
| 8 | 
            +
                  expect do
         | 
| 9 | 
            +
                    MessagePack::Timestamp.from_msgpack_ext([0xd4, 0x00].pack("C*"))
         | 
| 10 | 
            +
                  end.to raise_error(MessagePack::MalformedFormatError)
         | 
| 11 | 
            +
                end
         | 
| 12 | 
            +
              end
         | 
| 13 | 
            +
             | 
| 14 | 
            +
              describe 'register_type with Time' do
         | 
| 15 | 
            +
                let(:factory) do
         | 
| 16 | 
            +
                  factory = MessagePack::Factory.new
         | 
| 17 | 
            +
                  factory.register_type(
         | 
| 18 | 
            +
                    MessagePack::Timestamp::TYPE,
         | 
| 19 | 
            +
                    Time,
         | 
| 20 | 
            +
                    packer: MessagePack::Time::Packer,
         | 
| 21 | 
            +
                    unpacker: MessagePack::Time::Unpacker
         | 
| 22 | 
            +
                  )
         | 
| 23 | 
            +
                  factory
         | 
| 24 | 
            +
                end
         | 
| 25 | 
            +
             | 
| 26 | 
            +
                let(:time) { Time.local(2019, 6, 17, 1, 2, 3, 123_456_789 / 1000.0) }
         | 
| 27 | 
            +
                it 'serializes and deserializes Time' do
         | 
| 28 | 
            +
                  prefix_fixext8_with_type_id = [0xd7, -1].pack("c*")
         | 
| 29 | 
            +
             | 
| 30 | 
            +
                  packed = factory.pack(time)
         | 
| 31 | 
            +
                  expect(packed).to start_with(prefix_fixext8_with_type_id)
         | 
| 32 | 
            +
                  expect(packed.size).to eq(10)
         | 
| 33 | 
            +
                  unpacked = factory.unpack(packed)
         | 
| 34 | 
            +
                  expect(unpacked.to_i).to eq(time.to_i)
         | 
| 35 | 
            +
                  expect(unpacked.to_f).to eq(time.to_f)
         | 
| 36 | 
            +
                  # expect(unpacked).to eq(time) # we can't do it because of nsec (rational vs float?)
         | 
| 37 | 
            +
                end
         | 
| 38 | 
            +
             | 
| 39 | 
            +
                let(:time_without_nsec) { Time.local(2019, 6, 17, 1, 2, 3, 0) }
         | 
| 40 | 
            +
                it 'serializes time without nanosec as fixext4' do
         | 
| 41 | 
            +
                  prefix_fixext4_with_type_id = [0xd6, -1].pack("c*")
         | 
| 42 | 
            +
             | 
| 43 | 
            +
                  packed = factory.pack(time_without_nsec)
         | 
| 44 | 
            +
                  expect(packed).to start_with(prefix_fixext4_with_type_id)
         | 
| 45 | 
            +
                  expect(packed.size).to eq(6)
         | 
| 46 | 
            +
                  unpacked = factory.unpack(packed)
         | 
| 47 | 
            +
                  expect(unpacked).to eq(time_without_nsec)
         | 
| 48 | 
            +
                end
         | 
| 49 | 
            +
             | 
| 50 | 
            +
                let(:time_after_2514) { Time.at(1 << 34) } # the max num of 34bit int means 2514-05-30 01:53:04 UTC
         | 
| 51 | 
            +
                it 'serializes time after 2038 as ext8' do
         | 
| 52 | 
            +
                  prefix_ext8_with_12bytes_payload_and_type_id = [0xc7, 12, -1].pack("c*")
         | 
| 53 | 
            +
             | 
| 54 | 
            +
                  expect(time_after_2514.to_i).to be > 0xffffffff
         | 
| 55 | 
            +
                  packed = factory.pack(time_after_2514)
         | 
| 56 | 
            +
                  expect(packed).to start_with(prefix_ext8_with_12bytes_payload_and_type_id)
         | 
| 57 | 
            +
                  expect(packed.size).to eq(15)
         | 
| 58 | 
            +
                end
         | 
| 59 | 
            +
              end
         | 
| 60 | 
            +
             | 
| 61 | 
            +
              describe 'register_type with MessagePack::Timestamp' do
         | 
| 62 | 
            +
                let(:factory) do
         | 
| 63 | 
            +
                  factory = MessagePack::Factory.new
         | 
| 64 | 
            +
                  factory.register_type(MessagePack::Timestamp::TYPE, MessagePack::Timestamp)
         | 
| 65 | 
            +
                  factory
         | 
| 66 | 
            +
                end
         | 
| 67 | 
            +
             | 
| 68 | 
            +
                let(:timestamp) { MessagePack::Timestamp.new(Time.now.tv_sec, 123_456_789) }
         | 
| 69 | 
            +
                it 'serializes and deserializes MessagePack::Timestamp' do
         | 
| 70 | 
            +
                  packed = factory.pack(timestamp)
         | 
| 71 | 
            +
                  unpacked = factory.unpack(packed)
         | 
| 72 | 
            +
                  expect(unpacked).to eq(timestamp)
         | 
| 73 | 
            +
                end
         | 
| 74 | 
            +
              end
         | 
| 75 | 
            +
             | 
| 76 | 
            +
              describe 'timestamp32' do
         | 
| 77 | 
            +
                it 'handles [1, 0]' do
         | 
| 78 | 
            +
                  t = MessagePack::Timestamp.new(1, 0)
         | 
| 79 | 
            +
             | 
| 80 | 
            +
                  payload = t.to_msgpack_ext
         | 
| 81 | 
            +
                  unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
         | 
| 82 | 
            +
             | 
| 83 | 
            +
                  expect(unpacked).to eq(t)
         | 
| 84 | 
            +
                end
         | 
| 85 | 
            +
              end
         | 
| 86 | 
            +
             | 
| 87 | 
            +
              describe 'timestamp64' do
         | 
| 88 | 
            +
                it 'handles [1, 1]' do
         | 
| 89 | 
            +
                  t = MessagePack::Timestamp.new(1, 1)
         | 
| 90 | 
            +
             | 
| 91 | 
            +
                  payload = t.to_msgpack_ext
         | 
| 92 | 
            +
                  unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
         | 
| 93 | 
            +
             | 
| 94 | 
            +
                  expect(unpacked).to eq(t)
         | 
| 95 | 
            +
                end
         | 
| 96 | 
            +
              end
         | 
| 97 | 
            +
             | 
| 98 | 
            +
              describe 'timestamp96' do
         | 
| 99 | 
            +
                it 'handles [-1, 0]' do
         | 
| 100 | 
            +
                  t = MessagePack::Timestamp.new(-1, 0)
         | 
| 101 | 
            +
             | 
| 102 | 
            +
                  payload = t.to_msgpack_ext
         | 
| 103 | 
            +
                  unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
         | 
| 104 | 
            +
             | 
| 105 | 
            +
                  expect(unpacked).to eq(t)
         | 
| 106 | 
            +
                end
         | 
| 107 | 
            +
             | 
| 108 | 
            +
                it 'handles [-1, 999_999_999]' do
         | 
| 109 | 
            +
                  t = MessagePack::Timestamp.new(-1, 999_999_999)
         | 
| 110 | 
            +
             | 
| 111 | 
            +
                  payload = t.to_msgpack_ext
         | 
| 112 | 
            +
                  unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
         | 
| 113 | 
            +
             | 
| 114 | 
            +
                  expect(unpacked).to eq(t)
         | 
| 115 | 
            +
                end
         | 
| 116 | 
            +
              end
         | 
| 117 | 
            +
            end
         | 
    
        metadata
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            --- !ruby/object:Gem::Specification
         | 
| 2 2 | 
             
            name: msgpack
         | 
| 3 3 | 
             
            version: !ruby/object:Gem::Version
         | 
| 4 | 
            -
              version: 1. | 
| 4 | 
            +
              version: 1.3.0
         | 
| 5 5 | 
             
            platform: java
         | 
| 6 6 | 
             
            authors:
         | 
| 7 7 | 
             
            - Sadayuki Furuhashi
         | 
| @@ -10,7 +10,7 @@ authors: | |
| 10 10 | 
             
            autorequire:
         | 
| 11 11 | 
             
            bindir: bin
         | 
| 12 12 | 
             
            cert_chain: []
         | 
| 13 | 
            -
            date: 2019- | 
| 13 | 
            +
            date: 2019-06-20 00:00:00.000000000 Z
         | 
| 14 14 | 
             
            dependencies:
         | 
| 15 15 | 
             
            - !ruby/object:Gem::Dependency
         | 
| 16 16 | 
             
              requirement: !ruby/object:Gem::Requirement
         | 
| @@ -113,6 +113,8 @@ files: | |
| 113 113 | 
             
            - lib/msgpack/msgpack.jar
         | 
| 114 114 | 
             
            - lib/msgpack/packer.rb
         | 
| 115 115 | 
             
            - lib/msgpack/symbol.rb
         | 
| 116 | 
            +
            - lib/msgpack/time.rb
         | 
| 117 | 
            +
            - lib/msgpack/timestamp.rb
         | 
| 116 118 | 
             
            - lib/msgpack/unpacker.rb
         | 
| 117 119 | 
             
            - lib/msgpack/version.rb
         | 
| 118 120 | 
             
            - spec/cases.json
         | 
| @@ -136,6 +138,7 @@ files: | |
| 136 138 | 
             
            - spec/packer_spec.rb
         | 
| 137 139 | 
             
            - spec/random_compat.rb
         | 
| 138 140 | 
             
            - spec/spec_helper.rb
         | 
| 141 | 
            +
            - spec/timestamp_spec.rb
         | 
| 139 142 | 
             
            - spec/unpack_spec.rb
         | 
| 140 143 | 
             
            - spec/unpacker_spec.rb
         | 
| 141 144 | 
             
            homepage: http://msgpack.org/
         | 
| @@ -157,8 +160,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement | |
| 157 160 | 
             
                - !ruby/object:Gem::Version
         | 
| 158 161 | 
             
                  version: '0'
         | 
| 159 162 | 
             
            requirements: []
         | 
| 160 | 
            -
             | 
| 161 | 
            -
            rubygems_version: 2.7.6
         | 
| 163 | 
            +
            rubygems_version: 3.0.3
         | 
| 162 164 | 
             
            signing_key:
         | 
| 163 165 | 
             
            specification_version: 4
         | 
| 164 166 | 
             
            summary: MessagePack, a binary-based efficient data interchange format.
         | 
| @@ -184,5 +186,6 @@ test_files: | |
| 184 186 | 
             
            - spec/packer_spec.rb
         | 
| 185 187 | 
             
            - spec/random_compat.rb
         | 
| 186 188 | 
             
            - spec/spec_helper.rb
         | 
| 189 | 
            +
            - spec/timestamp_spec.rb
         | 
| 187 190 | 
             
            - spec/unpack_spec.rb
         | 
| 188 191 | 
             
            - spec/unpacker_spec.rb
         |