msgpack 1.2.10 → 1.4.0.pre1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.gitignore +3 -1
- data/.rubocop.yml +4 -1
- data/.travis.yml +5 -9
- data/ChangeLog +16 -0
- data/README.rdoc +16 -0
- data/Rakefile +1 -1
- data/doclib/msgpack/time.rb +22 -0
- data/doclib/msgpack/timestamp.rb +44 -0
- data/ext/msgpack/extconf.rb +12 -0
- data/ext/msgpack/unpacker.c +3 -0
- data/ext/msgpack/unpacker_class.c +0 -3
- data/lib/msgpack.rb +3 -5
- data/lib/msgpack/time.rb +29 -0
- data/lib/msgpack/timestamp.rb +76 -0
- data/lib/msgpack/version.rb +2 -1
- data/msgpack.gemspec +1 -2
- data/spec/spec_helper.rb +11 -0
- data/spec/timestamp_spec.rb +121 -0
- data/spec/unpacker_spec.rb +11 -0
- metadata +16 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: dce37069bf08ffa0b29a76363cee45e3d8e19188236d673dc1c9b4172727738c
|
4
|
+
data.tar.gz: 3c30d3ac0b3a3b4f5432e958935370f2e55d16ce516bf6a91eb12382aad38d8b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 53d062f57dcd7324a04224c16dedbe7aa0188515d595f5a38ca543e0b956db8bbd3906a59cf3faceb5c0fb3b23d10be47bb34d19146c61923818f8f856c0a726
|
7
|
+
data.tar.gz: 408bcb8f9cde8c88ac6a0620a8a64c746e34723b582aa160b53687f7b5206a9cdcf97efb97eafcf6357cee6412ae3d0346a952e97b979f7c4eeffe23150d7ec4
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
@@ -5,6 +5,9 @@
|
|
5
5
|
# Note that changes in the inspected code, or installation of new
|
6
6
|
# versions of RuboCop, may require this file to be generated again.
|
7
7
|
|
8
|
+
AllCops:
|
9
|
+
TargetRubyVersion: 2.4
|
10
|
+
|
8
11
|
# Offense count: 3
|
9
12
|
Lint/AmbiguousOperator:
|
10
13
|
Enabled: false
|
@@ -15,7 +18,7 @@ Lint/AssignmentInCondition:
|
|
15
18
|
Enabled: false
|
16
19
|
|
17
20
|
# Offense count: 1
|
18
|
-
|
21
|
+
Security/Eval:
|
19
22
|
Enabled: false
|
20
23
|
|
21
24
|
# Offense count: 3
|
data/.travis.yml
CHANGED
@@ -1,7 +1,5 @@
|
|
1
1
|
language: ruby
|
2
2
|
|
3
|
-
sudo: false
|
4
|
-
|
5
3
|
branches:
|
6
4
|
only:
|
7
5
|
- master
|
@@ -17,19 +15,17 @@ before_install:
|
|
17
15
|
# http://rubies.travis-ci.org/
|
18
16
|
matrix:
|
19
17
|
include:
|
20
|
-
- rvm: 2.3.8
|
21
|
-
os: linux
|
22
18
|
- rvm: 2.4.5
|
23
19
|
os: linux
|
24
|
-
- rvm: 2.5.
|
20
|
+
- rvm: 2.5.8
|
25
21
|
os: linux
|
26
|
-
- rvm: 2.6.
|
22
|
+
- rvm: 2.6.6
|
27
23
|
os: linux
|
28
|
-
- rvm: 2.6.
|
24
|
+
- rvm: 2.6.6
|
29
25
|
os: osx
|
30
|
-
- rvm:
|
26
|
+
- rvm: 2.7.1
|
31
27
|
os: linux
|
32
|
-
- rvm:
|
28
|
+
- rvm: ruby-head
|
33
29
|
os: linux
|
34
30
|
- rvm: jruby-head
|
35
31
|
os: linux
|
data/ChangeLog
CHANGED
@@ -1,3 +1,19 @@
|
|
1
|
+
2020-02-05 version 1.3.3:
|
2
|
+
|
3
|
+
* Hotfix release for Windows environments: 1.3.2 missed including binaries
|
4
|
+
|
5
|
+
2020-02-04 version 1.3.2:
|
6
|
+
|
7
|
+
* Add Ruby 2.7.0 binary in gem releases for Windows
|
8
|
+
|
9
|
+
2019-08-05 version 1.3.1:
|
10
|
+
|
11
|
+
* Fix timestamp ext type bug about timestamps with seconds larger than 32bit int (after 2106-02-07 06:28:16 UTC)
|
12
|
+
|
13
|
+
2019-06-20 verison 1.3.0:
|
14
|
+
|
15
|
+
* Add timestamp ext type (id:-1) support
|
16
|
+
|
1
17
|
2019-04-19 version 1.2.10:
|
2
18
|
|
3
19
|
* Optimze MessagePack.unpack not to copy source string
|
data/README.rdoc
CHANGED
@@ -121,6 +121,22 @@ being serialized altogether by throwing an exception:
|
|
121
121
|
|
122
122
|
[1, :symbol, 'string'].to_msgpack # => RuntimeError: Serialization of symbols prohibited
|
123
123
|
|
124
|
+
= Serializing and deserializing Time instances
|
125
|
+
|
126
|
+
There are the timestamp extension type in MessagePack,
|
127
|
+
but it is not registered by default.
|
128
|
+
|
129
|
+
To map Ruby's Time to MessagePack's timestamp for the default factory:
|
130
|
+
|
131
|
+
MessagePack::DefaultFactory.register_type(
|
132
|
+
MessagePack::Timestamp::TYPE, # or just -1
|
133
|
+
Time,
|
134
|
+
packer: MessagePack::Time::Packer,
|
135
|
+
unpacker: MessagePack::Time::Unpacker
|
136
|
+
)
|
137
|
+
|
138
|
+
See {API reference}[http://ruby.msgpack.org/] for details.
|
139
|
+
|
124
140
|
= Extension Types
|
125
141
|
|
126
142
|
Packer and Unpacker support {Extension types of MessagePack}[https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type].
|
data/Rakefile
CHANGED
@@ -69,7 +69,7 @@ namespace :build do
|
|
69
69
|
task :windows do
|
70
70
|
require 'rake_compiler_dock'
|
71
71
|
# See RUBY_CC_VERSION in https://github.com/rake-compiler/rake-compiler-dock/blob/master/Dockerfile
|
72
|
-
RakeCompilerDock.sh 'bundle && gem i json && rake cross native gem RUBY_CC_VERSION=2.2.2:2.3.0:2.4.0:2.5.0:2.6.0'
|
72
|
+
RakeCompilerDock.sh 'bundle && gem i json && rake cross native gem RUBY_CC_VERSION=2.2.2:2.3.0:2.4.0:2.5.0:2.6.0:2.7.0'
|
73
73
|
end
|
74
74
|
end
|
75
75
|
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module MessagePack
|
2
|
+
|
3
|
+
# MessagePack::Time provides packer and unpacker functions for a timestamp type.
|
4
|
+
# @example Setup for DefaultFactory
|
5
|
+
# MessagePack::DefaultFactory.register_type(
|
6
|
+
# MessagePack::Timestamp::TYPE,
|
7
|
+
# Time,
|
8
|
+
# packer: MessagePack::Time::Packer,
|
9
|
+
# unpacker: MessagePack::Time::Unpacker
|
10
|
+
# )
|
11
|
+
class Time
|
12
|
+
# A packer function that packs a Time instance to a MessagePack timestamp.
|
13
|
+
Packer = lambda { |payload|
|
14
|
+
# ...
|
15
|
+
}
|
16
|
+
|
17
|
+
# An unpacker function that unpacks a MessagePack timestamp to a Time instance.
|
18
|
+
Unpacker = lambda { |time|
|
19
|
+
# ...
|
20
|
+
}
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module MessagePack
|
2
|
+
# A utility class for MessagePack timestamp type
|
3
|
+
class Timestamp
|
4
|
+
#
|
5
|
+
# The timestamp extension type defined in the MessagePack spec.
|
6
|
+
#
|
7
|
+
# See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type for details.
|
8
|
+
#
|
9
|
+
TYPE = -1
|
10
|
+
|
11
|
+
# @return [Integer] Second part of the timestamp.
|
12
|
+
attr_reader :sec
|
13
|
+
|
14
|
+
# @return [Integer] Nanosecond part of the timestamp.
|
15
|
+
attr_reader :nsec
|
16
|
+
|
17
|
+
# @param [Integer] sec
|
18
|
+
# @param [Integer] nsec
|
19
|
+
def initialize(sec, nsec)
|
20
|
+
end
|
21
|
+
|
22
|
+
# @example An unpacker implementation for the Time class
|
23
|
+
# lambda do |payload|
|
24
|
+
# tv = MessagePack::Timestamp.from_msgpack_ext(payload)
|
25
|
+
# Time.at(tv.sec, tv.nsec, :nanosecond)
|
26
|
+
# end
|
27
|
+
#
|
28
|
+
# @param [String] data
|
29
|
+
# @return [MessagePack::Timestamp]
|
30
|
+
def self.from_msgpack_ext(data)
|
31
|
+
end
|
32
|
+
|
33
|
+
# @example A packer implementation for the Time class
|
34
|
+
# unpacker = lambda do |time|
|
35
|
+
# MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec)
|
36
|
+
# end
|
37
|
+
#
|
38
|
+
# @param [Integer] sec
|
39
|
+
# @param [Integer] nsec
|
40
|
+
# @return [String]
|
41
|
+
def self.to_msgpack_ext(sec, nsec)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/ext/msgpack/extconf.rb
CHANGED
@@ -25,6 +25,18 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE == 'rbx'
|
|
25
25
|
$CFLAGS << %[ -DDISABLE_RMEM]
|
26
26
|
end
|
27
27
|
|
28
|
+
# checking if Hash#[]= (rb_hash_aset) dedupes string keys
|
29
|
+
h = {}
|
30
|
+
x = {}
|
31
|
+
r = rand.to_s
|
32
|
+
h[%W(#{r}).join('')] = :foo
|
33
|
+
x[%W(#{r}).join('')] = :foo
|
34
|
+
if x.keys[0].equal?(h.keys[0])
|
35
|
+
$CFLAGS << ' -DHASH_ASET_DEDUPE=1 '
|
36
|
+
else
|
37
|
+
$CFLAGS << ' -DHASH_ASET_DEDUPE=0 '
|
38
|
+
end
|
39
|
+
|
28
40
|
if warnflags = CONFIG['warnflags']
|
29
41
|
warnflags.slice!(/ -Wdeclaration-after-statement/)
|
30
42
|
end
|
data/ext/msgpack/unpacker.c
CHANGED
@@ -300,9 +300,12 @@ static inline int read_raw_body_begin(msgpack_unpacker_t* uk, int raw_type)
|
|
300
300
|
} else {
|
301
301
|
ret = object_complete_ext(uk, raw_type, string);
|
302
302
|
}
|
303
|
+
|
304
|
+
# if !HASH_ASET_DEDUPE
|
303
305
|
if(will_freeze) {
|
304
306
|
rb_obj_freeze(string);
|
305
307
|
}
|
308
|
+
# endif
|
306
309
|
uk->reading_raw_remaining = 0;
|
307
310
|
return ret;
|
308
311
|
}
|
@@ -77,9 +77,6 @@ VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self)
|
|
77
77
|
VALUE v = argv[0];
|
78
78
|
if(rb_type(v) == T_HASH) {
|
79
79
|
options = v;
|
80
|
-
if(rb_type(options) != T_HASH) {
|
81
|
-
rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options));
|
82
|
-
}
|
83
80
|
} else {
|
84
81
|
io = v;
|
85
82
|
}
|
data/lib/msgpack.rb
CHANGED
@@ -5,11 +5,7 @@ if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" # This is same with `/java/ =
|
|
5
5
|
require "msgpack/msgpack.jar"
|
6
6
|
org.msgpack.jruby.MessagePackLibrary.new.load(JRuby.runtime, false)
|
7
7
|
else
|
8
|
-
|
9
|
-
require "msgpack/#{RUBY_VERSION[/\d+.\d+/]}/msgpack"
|
10
|
-
rescue LoadError
|
11
|
-
require "msgpack/msgpack"
|
12
|
-
end
|
8
|
+
require "msgpack/msgpack"
|
13
9
|
end
|
14
10
|
|
15
11
|
require "msgpack/packer"
|
@@ -17,6 +13,8 @@ require "msgpack/unpacker"
|
|
17
13
|
require "msgpack/factory"
|
18
14
|
require "msgpack/symbol"
|
19
15
|
require "msgpack/core_ext"
|
16
|
+
require "msgpack/timestamp"
|
17
|
+
require "msgpack/time"
|
20
18
|
|
21
19
|
module MessagePack
|
22
20
|
DefaultFactory = MessagePack::Factory.new
|
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
@@ -1,9 +1,10 @@
|
|
1
1
|
module MessagePack
|
2
|
-
VERSION = "1.
|
2
|
+
VERSION = "1.4.0.pre1"
|
3
3
|
|
4
4
|
# NOTE for msgpack-ruby maintainer:
|
5
5
|
# Check these things to release new binaryes for new Ruby versions (especially for Windows):
|
6
6
|
# * versions/supports of rake-compiler & rake-compiler-dock
|
7
|
+
# https://github.com/rake-compiler/rake-compiler-dock/blob/master/History.md
|
7
8
|
# * update RUBY_CC_VERSION in Rakefile
|
8
9
|
# * check Ruby dependency of released mswin gem details
|
9
10
|
end
|
data/msgpack.gemspec
CHANGED
@@ -10,7 +10,6 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.email = ["frsyuki@gmail.com", "theo@iconara.net", "tagomoris@gmail.com"]
|
11
11
|
s.license = "Apache 2.0"
|
12
12
|
s.homepage = "http://msgpack.org/"
|
13
|
-
s.rubyforge_project = "msgpack"
|
14
13
|
s.require_paths = ["lib"]
|
15
14
|
if /java/ =~ RUBY_PLATFORM
|
16
15
|
s.files = Dir['lib/**/*.rb', 'lib/**/*.jar']
|
@@ -26,7 +25,7 @@ Gem::Specification.new do |s|
|
|
26
25
|
s.add_development_dependency 'rake-compiler', ['~> 1.0']
|
27
26
|
if /java/ !~ RUBY_PLATFORM
|
28
27
|
# NOTE: rake-compiler-dock SHOULD be updated for new Ruby versions
|
29
|
-
s.add_development_dependency 'rake-compiler-dock', ['~>
|
28
|
+
s.add_development_dependency 'rake-compiler-dock', ['~> 1.0']
|
30
29
|
end
|
31
30
|
s.add_development_dependency 'rspec', ['~> 3.3']
|
32
31
|
s.add_development_dependency 'yard'
|
data/spec/spec_helper.rb
CHANGED
@@ -19,6 +19,17 @@ def java?
|
|
19
19
|
/java/ =~ RUBY_PLATFORM
|
20
20
|
end
|
21
21
|
|
22
|
+
# checking if Hash#[]= (rb_hash_aset) dedupes string keys
|
23
|
+
def automatic_string_keys_deduplication?
|
24
|
+
h = {}
|
25
|
+
x = {}
|
26
|
+
r = rand.to_s
|
27
|
+
h[%W(#{r}).join('')] = :foo
|
28
|
+
x[%W(#{r}).join('')] = :foo
|
29
|
+
|
30
|
+
x.keys[0].equal?(h.keys[0])
|
31
|
+
end
|
32
|
+
|
22
33
|
if java?
|
23
34
|
RSpec.configure do |c|
|
24
35
|
c.treat_symbols_as_metadata_keys_with_true_values = true
|
@@ -0,0 +1,121 @@
|
|
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
|
+
|
60
|
+
it 'runs correctly (regression)' do
|
61
|
+
expect(factory.unpack(factory.pack(Time.utc(2200)))).to eq(Time.utc(2200))
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
describe 'register_type with MessagePack::Timestamp' do
|
66
|
+
let(:factory) do
|
67
|
+
factory = MessagePack::Factory.new
|
68
|
+
factory.register_type(MessagePack::Timestamp::TYPE, MessagePack::Timestamp)
|
69
|
+
factory
|
70
|
+
end
|
71
|
+
|
72
|
+
let(:timestamp) { MessagePack::Timestamp.new(Time.now.tv_sec, 123_456_789) }
|
73
|
+
it 'serializes and deserializes MessagePack::Timestamp' do
|
74
|
+
packed = factory.pack(timestamp)
|
75
|
+
unpacked = factory.unpack(packed)
|
76
|
+
expect(unpacked).to eq(timestamp)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
describe 'timestamp32' do
|
81
|
+
it 'handles [1, 0]' do
|
82
|
+
t = MessagePack::Timestamp.new(1, 0)
|
83
|
+
|
84
|
+
payload = t.to_msgpack_ext
|
85
|
+
unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
|
86
|
+
|
87
|
+
expect(unpacked).to eq(t)
|
88
|
+
end
|
89
|
+
end
|
90
|
+
|
91
|
+
describe 'timestamp64' do
|
92
|
+
it 'handles [1, 1]' do
|
93
|
+
t = MessagePack::Timestamp.new(1, 1)
|
94
|
+
|
95
|
+
payload = t.to_msgpack_ext
|
96
|
+
unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
|
97
|
+
|
98
|
+
expect(unpacked).to eq(t)
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe 'timestamp96' do
|
103
|
+
it 'handles [-1, 0]' do
|
104
|
+
t = MessagePack::Timestamp.new(-1, 0)
|
105
|
+
|
106
|
+
payload = t.to_msgpack_ext
|
107
|
+
unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
|
108
|
+
|
109
|
+
expect(unpacked).to eq(t)
|
110
|
+
end
|
111
|
+
|
112
|
+
it 'handles [-1, 999_999_999]' do
|
113
|
+
t = MessagePack::Timestamp.new(-1, 999_999_999)
|
114
|
+
|
115
|
+
payload = t.to_msgpack_ext
|
116
|
+
unpacked = MessagePack::Timestamp.from_msgpack_ext(payload)
|
117
|
+
|
118
|
+
expect(unpacked).to eq(t)
|
119
|
+
end
|
120
|
+
end
|
121
|
+
end
|
data/spec/unpacker_spec.rb
CHANGED
@@ -25,6 +25,17 @@ describe MessagePack::Unpacker do
|
|
25
25
|
u2.allow_unknown_ext?.should == true
|
26
26
|
end
|
27
27
|
|
28
|
+
if automatic_string_keys_deduplication?
|
29
|
+
it 'ensure string hash keys are deduplicated' do
|
30
|
+
sample_data = [{"foo" => 1}, {"foo" => 2}]
|
31
|
+
sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
|
32
|
+
unpacker.feed(sample_packed)
|
33
|
+
hashes = nil
|
34
|
+
unpacker.each { |obj| hashes = obj }
|
35
|
+
expect(hashes[0].keys.first).to equal(hashes[1].keys.first)
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
28
39
|
it 'gets IO or object which has #read to read data from it' do
|
29
40
|
sample_data = {"message" => "morning!", "num" => 1}
|
30
41
|
sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
|
metadata
CHANGED
@@ -1,16 +1,16 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: msgpack
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.4.0.pre1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Sadayuki Furuhashi
|
8
8
|
- Theo Hultberg
|
9
9
|
- Satoshi Tagomori
|
10
|
-
autorequire:
|
10
|
+
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2020-09-08 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: bundler
|
@@ -60,14 +60,14 @@ dependencies:
|
|
60
60
|
requirements:
|
61
61
|
- - "~>"
|
62
62
|
- !ruby/object:Gem::Version
|
63
|
-
version:
|
63
|
+
version: '1.0'
|
64
64
|
type: :development
|
65
65
|
prerelease: false
|
66
66
|
version_requirements: !ruby/object:Gem::Requirement
|
67
67
|
requirements:
|
68
68
|
- - "~>"
|
69
69
|
- !ruby/object:Gem::Version
|
70
|
-
version:
|
70
|
+
version: '1.0'
|
71
71
|
- !ruby/object:Gem::Dependency
|
72
72
|
name: rspec
|
73
73
|
requirement: !ruby/object:Gem::Requirement
|
@@ -148,6 +148,8 @@ files:
|
|
148
148
|
- doclib/msgpack/extension_value.rb
|
149
149
|
- doclib/msgpack/factory.rb
|
150
150
|
- doclib/msgpack/packer.rb
|
151
|
+
- doclib/msgpack/time.rb
|
152
|
+
- doclib/msgpack/timestamp.rb
|
151
153
|
- doclib/msgpack/unpacker.rb
|
152
154
|
- ext/java/org/msgpack/jruby/Buffer.java
|
153
155
|
- ext/java/org/msgpack/jruby/Decoder.java
|
@@ -192,6 +194,8 @@ files:
|
|
192
194
|
- lib/msgpack/factory.rb
|
193
195
|
- lib/msgpack/packer.rb
|
194
196
|
- lib/msgpack/symbol.rb
|
197
|
+
- lib/msgpack/time.rb
|
198
|
+
- lib/msgpack/timestamp.rb
|
195
199
|
- lib/msgpack/unpacker.rb
|
196
200
|
- lib/msgpack/version.rb
|
197
201
|
- msgpack.gemspec
|
@@ -217,13 +221,14 @@ files:
|
|
217
221
|
- spec/packer_spec.rb
|
218
222
|
- spec/random_compat.rb
|
219
223
|
- spec/spec_helper.rb
|
224
|
+
- spec/timestamp_spec.rb
|
220
225
|
- spec/unpack_spec.rb
|
221
226
|
- spec/unpacker_spec.rb
|
222
227
|
homepage: http://msgpack.org/
|
223
228
|
licenses:
|
224
229
|
- Apache 2.0
|
225
230
|
metadata: {}
|
226
|
-
post_install_message:
|
231
|
+
post_install_message:
|
227
232
|
rdoc_options: []
|
228
233
|
require_paths:
|
229
234
|
- lib
|
@@ -234,12 +239,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
234
239
|
version: '0'
|
235
240
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
236
241
|
requirements:
|
237
|
-
- - "
|
242
|
+
- - ">"
|
238
243
|
- !ruby/object:Gem::Version
|
239
|
-
version:
|
244
|
+
version: 1.3.1
|
240
245
|
requirements: []
|
241
|
-
rubygems_version: 3.
|
242
|
-
signing_key:
|
246
|
+
rubygems_version: 3.1.2
|
247
|
+
signing_key:
|
243
248
|
specification_version: 4
|
244
249
|
summary: MessagePack, a binary-based efficient data interchange format.
|
245
250
|
test_files:
|
@@ -264,5 +269,6 @@ test_files:
|
|
264
269
|
- spec/packer_spec.rb
|
265
270
|
- spec/random_compat.rb
|
266
271
|
- spec/spec_helper.rb
|
272
|
+
- spec/timestamp_spec.rb
|
267
273
|
- spec/unpack_spec.rb
|
268
274
|
- spec/unpacker_spec.rb
|