commit rubygem-msgpack for openSUSE:Factory
Hello community, here is the log from the commit of package rubygem-msgpack for openSUSE:Factory checked in at 2019-07-08 15:12:44 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/rubygem-msgpack (Old) and /work/SRC/openSUSE:Factory/.rubygem-msgpack.new.4615 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Package is "rubygem-msgpack" Mon Jul 8 15:12:44 2019 rev:10 rq:714009 version:1.3.0 Changes: -------- --- /work/SRC/openSUSE:Factory/rubygem-msgpack/rubygem-msgpack.changes 2019-06-19 21:00:40.614102033 +0200 +++ /work/SRC/openSUSE:Factory/.rubygem-msgpack.new.4615/rubygem-msgpack.changes 2019-07-08 16:41:03.924963363 +0200 @@ -1,0 +2,7 @@ +Mon Jul 8 08:32:18 UTC 2019 - Manuel Schnitzer <mschnitzer@suse.com> + +- updated to version 1.3.0 + + * Add timestamp ext type (id:-1) support + +------------------------------------------------------------------- Old: ---- msgpack-1.2.10.gem New: ---- msgpack-1.3.0.gem ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ rubygem-msgpack.spec ++++++ --- /var/tmp/diff_new_pack.CSI420/_old 2019-07-08 16:41:04.492964169 +0200 +++ /var/tmp/diff_new_pack.CSI420/_new 2019-07-08 16:41:04.496964174 +0200 @@ -24,7 +24,7 @@ # Name: rubygem-msgpack -Version: 1.2.10 +Version: 1.3.0 Release: 0 %define mod_name msgpack %define mod_full_name %{mod_name}-%{version} ++++++ msgpack-1.2.10.gem -> msgpack-1.3.0.gem ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/.rubocop.yml new/.rubocop.yml --- old/.rubocop.yml 2019-04-19 03:15:28.000000000 +0200 +++ new/.rubocop.yml 2019-06-20 09:16:11.000000000 +0200 @@ -5,6 +5,9 @@ # Note that changes in the inspected code, or installation of new # versions of RuboCop, may require this file to be generated again. +AllCops: + TargetRubyVersion: 2.3 + # Offense count: 3 Lint/AmbiguousOperator: Enabled: false diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/ChangeLog new/ChangeLog --- old/ChangeLog 2019-04-19 03:15:28.000000000 +0200 +++ new/ChangeLog 2019-06-20 09:16:11.000000000 +0200 @@ -1,3 +1,7 @@ +2019-06-20 verison 1.3.0: + +* Add timestamp ext type (id:-1) support + 2019-04-19 version 1.2.10: * Optimze MessagePack.unpack not to copy source string diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/README.rdoc new/README.rdoc --- old/README.rdoc 2019-04-19 03:15:28.000000000 +0200 +++ new/README.rdoc 2019-06-20 09:16:11.000000000 +0200 @@ -121,6 +121,22 @@ [1, :symbol, 'string'].to_msgpack # => RuntimeError: Serialization of symbols prohibited += Serializing and deserializing Time instances + +There are the timestamp extension type in MessagePack, +but it is not registered by default. + +To map Ruby's Time to MessagePack's timestamp for the default factory: + + MessagePack::DefaultFactory.register_type( + MessagePack::Timestamp::TYPE, # or just -1 + Time, + packer: MessagePack::Time::Packer, + unpacker: MessagePack::Time::Unpacker + ) + +See {API reference}[http://ruby.msgpack.org/] for details. + = Extension Types Packer and Unpacker support {Extension types of MessagePack}[https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type]. Binary files old/checksums.yaml.gz and new/checksums.yaml.gz differ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/doclib/msgpack/time.rb new/doclib/msgpack/time.rb --- old/doclib/msgpack/time.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/doclib/msgpack/time.rb 2019-06-20 09:16:11.000000000 +0200 @@ -0,0 +1,22 @@ +module MessagePack + + # MessagePack::Time provides packer and unpacker functions for a timestamp type. + # @example Setup for DefaultFactory + # MessagePack::DefaultFactory.register_type( + # MessagePack::Timestamp::TYPE, + # Time, + # packer: MessagePack::Time::Packer, + # unpacker: MessagePack::Time::Unpacker + # ) + class Time + # A packer function that packs a Time instance to a MessagePack timestamp. + Packer = lambda { |payload| + # ... + } + + # An unpacker function that unpacks a MessagePack timestamp to a Time instance. + Unpcker = lambda { |time| + # ... + } + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/doclib/msgpack/timestamp.rb new/doclib/msgpack/timestamp.rb --- old/doclib/msgpack/timestamp.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/doclib/msgpack/timestamp.rb 2019-06-20 09:16:11.000000000 +0200 @@ -0,0 +1,44 @@ +module MessagePack + # A utility class for MessagePack timestamp type + class Timestamp + # + # The timestamp extension type defined in the MessagePack spec. + # + # See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-t... for details. + # + TYPE = -1 + + # @return [Integer] Second part of the timestamp. + attr_reader :sec + + # @return [Integer] Nanosecond part of the timestamp. + attr_reader :nsec + + # @param [Integer] sec + # @param [Integer] nsec + def initialize(sec, nsec) + end + + # @example An unpacker implementation for the Time class + # lambda do |payload| + # tv = MessagePack::Timestamp.from_msgpack_ext(payload) + # Time.at(tv.sec, tv.nsec, :nanosecond) + # end + # + # @param [String] data + # @return [MessagePack::Timestamp] + def self.from_msgpack_ext(data) + end + + # @example A packer implementation for the Time class + # unpacker = lambda do |time| + # MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec) + # end + # + # @param [Integer] sec + # @param [Integer] nsec + # @return [String] + def self.to_msgpack_ext(sec, nsec) + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/msgpack/time.rb new/lib/msgpack/time.rb --- old/lib/msgpack/time.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/msgpack/time.rb 2019-06-20 09:16:11.000000000 +0200 @@ -0,0 +1,29 @@ +# frozen_string_literal: true + +# MessagePack extention packer and unpacker for built-in Time class +module MessagePack + module Time + # 3-arg Time.at is available Ruby >= 2.5 + TIME_AT_3_AVAILABLE = begin + !!::Time.at(0, 0, :nanosecond) + rescue ArgumentError + false + end + + Unpacker = if TIME_AT_3_AVAILABLE + lambda do |payload| + tv = MessagePack::Timestamp.from_msgpack_ext(payload) + ::Time.at(tv.sec, tv.nsec, :nanosecond) + end + else + lambda do |payload| + tv = MessagePack::Timestamp.from_msgpack_ext(payload) + ::Time.at(tv.sec, tv.nsec / 1000.0) + end + end + + Packer = lambda { |time| + MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec) + } + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/msgpack/timestamp.rb new/lib/msgpack/timestamp.rb --- old/lib/msgpack/timestamp.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/lib/msgpack/timestamp.rb 2019-06-20 09:16:11.000000000 +0200 @@ -0,0 +1,76 @@ +# frozen_string_literal: true + +module MessagePack + class Timestamp # a.k.a. "TimeSpec" + # Because the byte-order of MessagePack is big-endian in, + # pack() and unpack() specifies ">". + # See https://docs.ruby-lang.org/en/trunk/Array.html#method-i-pack for details. + + # The timestamp extension type defined in the MessagePack spec. + # See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-t... for details. + TYPE = -1 + + TIMESTAMP32_MAX_SEC = (1 << 32) - 1 + TIMESTAMP64_MAX_SEC = (1 << 34) - 1 + + # @return [Integer] + attr_reader :sec + + # @return [Integer] + attr_reader :nsec + + # @param [Integer] sec + # @param [Integer] nsec + def initialize(sec, nsec) + @sec = sec + @nsec = nsec + end + + def self.from_msgpack_ext(data) + case data.length + when 4 + # timestamp32 (sec: uint32be) + sec, = data.unpack('L>') + new(sec, 0) + when 8 + # timestamp64 (nsec: uint30be, sec: uint34be) + n, s = data.unpack('L>2') + sec = ((n & 0b11) << 32) | s + nsec = n >> 2 + new(sec, nsec) + when 12 + # timestam96 (nsec: uint32be, sec: int64be) + nsec, sec = data.unpack('L>q>') + new(sec, nsec) + else + raise MalformedFormatError, "Invalid timestamp data size: #{data.length}" + end + end + + def self.to_msgpack_ext(sec, nsec) + if sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC + if nsec === 0 && sec <= TIMESTAMP32_MAX_SEC + # timestamp32 = (sec: uint32be) + [sec].pack('L>') + else + # timestamp64 (nsec: uint30be, sec: uint34be) + nsec30 = nsec << 2 + sec_high2 = sec << 32 # high 2 bits (`x & 0b11` is redandunt) + sec_low32 = sec & 0xffffffff # low 32 bits + [nsec30 | sec_high2, sec_low32].pack('L>2') + end + else + # timestamp96 (nsec: uint32be, sec: int64be) + [nsec, sec].pack('L>q>') + end + end + + def to_msgpack_ext + self.class.to_msgpack_ext(sec, nsec) + end + + def ==(other) + other.class == self.class && sec == other.sec && nsec == other.nsec + end + end +end diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/msgpack/version.rb new/lib/msgpack/version.rb --- old/lib/msgpack/version.rb 2019-04-19 03:15:28.000000000 +0200 +++ new/lib/msgpack/version.rb 2019-06-20 09:16:11.000000000 +0200 @@ -1,5 +1,5 @@ module MessagePack - VERSION = "1.2.10" + VERSION = "1.3.0" # NOTE for msgpack-ruby maintainer: # Check these things to release new binaryes for new Ruby versions (especially for Windows): diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/lib/msgpack.rb new/lib/msgpack.rb --- old/lib/msgpack.rb 2019-04-19 03:15:28.000000000 +0200 +++ new/lib/msgpack.rb 2019-06-20 09:16:11.000000000 +0200 @@ -17,6 +17,8 @@ require "msgpack/factory" require "msgpack/symbol" require "msgpack/core_ext" +require "msgpack/timestamp" +require "msgpack/time" module MessagePack DefaultFactory = MessagePack::Factory.new diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/metadata new/metadata --- old/metadata 2019-04-19 03:15:28.000000000 +0200 +++ new/metadata 2019-06-20 09:16:11.000000000 +0200 @@ -1,7 +1,7 @@ --- !ruby/object:Gem::Specification name: msgpack version: !ruby/object:Gem::Version - version: 1.2.10 + version: 1.3.0 platform: ruby authors: - Sadayuki Furuhashi @@ -10,7 +10,7 @@ autorequire: bindir: bin cert_chain: [] -date: 2019-04-19 00:00:00.000000000 Z +date: 2019-06-20 00:00:00.000000000 Z dependencies: - !ruby/object:Gem::Dependency name: bundler @@ -148,6 +148,8 @@ - doclib/msgpack/extension_value.rb - doclib/msgpack/factory.rb - doclib/msgpack/packer.rb +- doclib/msgpack/time.rb +- doclib/msgpack/timestamp.rb - doclib/msgpack/unpacker.rb - ext/java/org/msgpack/jruby/Buffer.java - ext/java/org/msgpack/jruby/Decoder.java @@ -192,6 +194,8 @@ - lib/msgpack/factory.rb - lib/msgpack/packer.rb - lib/msgpack/symbol.rb +- lib/msgpack/time.rb +- lib/msgpack/timestamp.rb - lib/msgpack/unpacker.rb - lib/msgpack/version.rb - msgpack.gemspec @@ -217,6 +221,7 @@ - spec/packer_spec.rb - spec/random_compat.rb - spec/spec_helper.rb +- spec/timestamp_spec.rb - spec/unpack_spec.rb - spec/unpacker_spec.rb homepage: http://msgpack.org/ @@ -264,5 +269,6 @@ - spec/packer_spec.rb - spec/random_compat.rb - spec/spec_helper.rb +- spec/timestamp_spec.rb - spec/unpack_spec.rb - spec/unpacker_spec.rb diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/spec/timestamp_spec.rb new/spec/timestamp_spec.rb --- old/spec/timestamp_spec.rb 1970-01-01 01:00:00.000000000 +0100 +++ new/spec/timestamp_spec.rb 2019-06-20 09:16:11.000000000 +0200 @@ -0,0 +1,117 @@ +# frozen_string_literal: true + +require 'spec_helper' + +describe MessagePack::Timestamp do + describe 'malformed format' do + it do + expect do + MessagePack::Timestamp.from_msgpack_ext([0xd4, 0x00].pack("C*")) + end.to raise_error(MessagePack::MalformedFormatError) + end + end + + describe 'register_type with Time' do + let(:factory) do + factory = MessagePack::Factory.new + factory.register_type( + MessagePack::Timestamp::TYPE, + Time, + packer: MessagePack::Time::Packer, + unpacker: MessagePack::Time::Unpacker + ) + factory + end + + let(:time) { Time.local(2019, 6, 17, 1, 2, 3, 123_456_789 / 1000.0) } + it 'serializes and deserializes Time' do + prefix_fixext8_with_type_id = [0xd7, -1].pack("c*") + + packed = factory.pack(time) + expect(packed).to start_with(prefix_fixext8_with_type_id) + expect(packed.size).to eq(10) + unpacked = factory.unpack(packed) + expect(unpacked.to_i).to eq(time.to_i) + expect(unpacked.to_f).to eq(time.to_f) + # expect(unpacked).to eq(time) # we can't do it because of nsec (rational vs float?) + end + + let(:time_without_nsec) { Time.local(2019, 6, 17, 1, 2, 3, 0) } + it 'serializes time without nanosec as fixext4' do + prefix_fixext4_with_type_id = [0xd6, -1].pack("c*") + + packed = factory.pack(time_without_nsec) + expect(packed).to start_with(prefix_fixext4_with_type_id) + expect(packed.size).to eq(6) + unpacked = factory.unpack(packed) + expect(unpacked).to eq(time_without_nsec) + end + + let(:time_after_2514) { Time.at(1 << 34) } # the max num of 34bit int means 2514-05-30 01:53:04 UTC + it 'serializes time after 2038 as ext8' do + prefix_ext8_with_12bytes_payload_and_type_id = [0xc7, 12, -1].pack("c*") + + expect(time_after_2514.to_i).to be > 0xffffffff + packed = factory.pack(time_after_2514) + expect(packed).to start_with(prefix_ext8_with_12bytes_payload_and_type_id) + expect(packed.size).to eq(15) + end + end + + describe 'register_type with MessagePack::Timestamp' do + let(:factory) do + factory = MessagePack::Factory.new + factory.register_type(MessagePack::Timestamp::TYPE, MessagePack::Timestamp) + factory + end + + let(:timestamp) { MessagePack::Timestamp.new(Time.now.tv_sec, 123_456_789) } + it 'serializes and deserializes MessagePack::Timestamp' do + packed = factory.pack(timestamp) + unpacked = factory.unpack(packed) + expect(unpacked).to eq(timestamp) + end + end + + describe 'timestamp32' do + it 'handles [1, 0]' do + t = MessagePack::Timestamp.new(1, 0) + + payload = t.to_msgpack_ext + unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) + + expect(unpacked).to eq(t) + end + end + + describe 'timestamp64' do + it 'handles [1, 1]' do + t = MessagePack::Timestamp.new(1, 1) + + payload = t.to_msgpack_ext + unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) + + expect(unpacked).to eq(t) + end + end + + describe 'timestamp96' do + it 'handles [-1, 0]' do + t = MessagePack::Timestamp.new(-1, 0) + + payload = t.to_msgpack_ext + unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) + + expect(unpacked).to eq(t) + end + + it 'handles [-1, 999_999_999]' do + t = MessagePack::Timestamp.new(-1, 999_999_999) + + payload = t.to_msgpack_ext + unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) + + expect(unpacked).to eq(t) + end + end +end
participants (1)
-
root