msgpack 0.7.1-x64-mingw32 → 0.7.3-x64-mingw32

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b46f27dcec150475f835906b4189a10fc68df8ae
4
- data.tar.gz: db691798ba819123902666b4bb4f7bbc4bc2147d
3
+ metadata.gz: e3dc98d2ed050350318c82da89581b967419d609
4
+ data.tar.gz: 9e65d5dc4dd80567d5ad2f2143b99d5cd2662f96
5
5
  SHA512:
6
- metadata.gz: 890724483e007a8dc0f8b25e03372fea3ab890cf28d175fa675c27c5c6225dce97e8b69adfd8477fc694037621d52041b720418770373c1637fcee74b0782654
7
- data.tar.gz: f32288661641e89d43d7afd65b7d868c3e85e850b9d92a3410459ef123be4a7114588120df9a75733b45ca12dc65e3f043d65ee97e13aa72446364028615e18c
6
+ metadata.gz: 231ea8acacbe0c03be96dd022a05521241cad93dd21f3b02a2837e13af7fba2d50eeaa905ccc587e74199a341afffc44088c4d84cc0f335557a94bc03a8a1fbe
7
+ data.tar.gz: 718f51c7485dd557345dfaeb2cb9a7ad7ca46da99f601eda4f8081f5ee2f9c45540c7735ebd5a04103e58c5562e84b614a7245b265197291fa239a37127f0bb7
@@ -5,7 +5,6 @@ rvm:
5
5
  - 2.1.6
6
6
  - 2.2.2
7
7
  - ruby-head
8
- - rbx-2
9
8
  - jruby-19mode
10
9
  - jruby-head
11
10
 
@@ -28,3 +27,4 @@ matrix:
28
27
  - rvm: jruby-head
29
28
  - rvm: jruby-19mode
30
29
  os: osx
30
+ - rvm: rbx-2
data/ChangeLog CHANGED
@@ -1,3 +1,12 @@
1
+ 2016-01-07 version 0.7.3:
2
+
3
+ * Add Packer#write_float32 method to pack floating point numbers into FLOAT of messagepack.
4
+
5
+ 2016-01-06 version 0.7.2:
6
+
7
+ * Improved compatibility of Unpacker between CRuby and JRuby to accept stream-like object
8
+ by checking respond_to(:read) in addition to class check
9
+
1
10
  2015-11-20 version 0.7.1:
2
11
 
3
12
  * Fixed bug to pack/unpack ext type objects larger than 256bytes incorrectly.
data/Rakefile CHANGED
@@ -37,14 +37,6 @@ if RUBY_PLATFORM =~ /java/
37
37
  ext.source_version = '1.6'
38
38
  ext.target_version = '1.6'
39
39
  end
40
-
41
- RSpec::Core::RakeTask.new(:spec) do |t|
42
- t.rspec_opts = ["-c", "-f progress"]
43
- t.rspec_opts << "-Ilib"
44
- t.pattern = 'spec/{,jruby/}*_spec.rb'
45
- t.verbose = true
46
- end
47
-
48
40
  else
49
41
  require 'rake/extensiontask'
50
42
 
@@ -55,20 +47,25 @@ else
55
47
  # cross_platform names are of MRI's platform name
56
48
  ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
57
49
  end
50
+ end
58
51
 
59
- RSpec::Core::RakeTask.new(:spec) do |t|
60
- t.rspec_opts = ["-c", "-f progress"]
61
- t.rspec_opts << "-Ilib"
62
- t.pattern = 'spec/{,cruby/}*_spec.rb'
63
- t.verbose = true
64
- end
52
+ test_pattern = case
53
+ when RUBY_PLATFORM =~ /java/ then 'spec/{,jruby/}*_spec.rb'
54
+ when RUBY_ENGINE =~ /rbx/ then 'spec/*_spec.rb'
55
+ else 'spec/{,cruby/}*_spec.rb' # MRI
56
+ end
57
+ RSpec::Core::RakeTask.new(:spec) do |t|
58
+ t.rspec_opts = ["-c", "-f progress"]
59
+ t.rspec_opts << "-Ilib"
60
+ t.pattern = test_pattern
61
+ t.verbose = true
65
62
  end
66
63
 
67
64
  namespace :build do
68
65
  desc 'Build gems for Windows per rake-compiler-dock'
69
66
  task :windows do
70
67
  require 'rake_compiler_dock'
71
- RakeCompilerDock.sh 'bundle && rake cross native gem RUBY_CC_VERSION=1.9.3:2.0.0:2.1.6:2.2.2'
68
+ RakeCompilerDock.sh 'bundle && rake cross native gem RUBY_CC_VERSION=1.9.3:2.0.0:2.1.6:2.2.2:2.3.0'
72
69
  end
73
70
  end
74
71
 
@@ -109,6 +109,18 @@ module MessagePack
109
109
  def write_map_header(n)
110
110
  end
111
111
 
112
+ #
113
+ # Serializes _value_ as 32-bit single precision float into internal buffer.
114
+ # _value_ will be approximated with the nearest possible single precision float, thus
115
+ # being potentially lossy. However, the serialized string will only take up 5 bytes
116
+ # instead of 9 bytes compared to directly serializing a 64-bit double precision Ruby Float.
117
+ #
118
+ # @param value [Numeric]
119
+ # @return [Packer] self
120
+ #
121
+ def write_float32(value)
122
+ end
123
+
112
124
  #
113
125
  # Flushes data in the internal buffer to the internal IO. Same as _buffer.flush.
114
126
  # If internal IO is not set, it does nothing.
@@ -8,6 +8,7 @@ import org.jruby.Ruby;
8
8
  import org.jruby.RubyObject;
9
9
  import org.jruby.RubyNil;
10
10
  import org.jruby.RubyBoolean;
11
+ import org.jruby.RubyNumeric;
11
12
  import org.jruby.RubyBignum;
12
13
  import org.jruby.RubyInteger;
13
14
  import org.jruby.RubyFixnum;
@@ -85,6 +86,11 @@ public class Encoder {
85
86
  return readRubyString();
86
87
  }
87
88
 
89
+ public IRubyObject encodeFloat32(RubyNumeric numeric) {
90
+ appendFloat32(numeric);
91
+ return readRubyString();
92
+ }
93
+
88
94
  private void appendObject(IRubyObject object) {
89
95
  appendObject(object, null);
90
96
  }
@@ -182,8 +188,8 @@ public class Encoder {
182
188
 
183
189
  private void appendFloat(RubyFloat object) {
184
190
  double value = object.getDoubleValue();
185
- float f = (float) value;
186
191
  //TODO: msgpack-ruby original does encode this value as Double, not float
192
+ // float f = (float) value;
187
193
  // if (Double.compare(f, value) == 0) {
188
194
  // ensureRemainingCapacity(5);
189
195
  // buffer.put(FLOAT32);
@@ -195,6 +201,13 @@ public class Encoder {
195
201
  // }
196
202
  }
197
203
 
204
+ private void appendFloat32(RubyNumeric object) {
205
+ float value = (float) object.getDoubleValue();
206
+ ensureRemainingCapacity(5);
207
+ buffer.put(FLOAT32);
208
+ buffer.putFloat(value);
209
+ }
210
+
198
211
  private void appendString(RubyString object) {
199
212
  Encoding encoding = object.getEncoding();
200
213
  boolean binary = !compatibilityMode && encoding == binaryEncoding;
@@ -7,6 +7,7 @@ import org.jruby.RubyObject;
7
7
  import org.jruby.RubyArray;
8
8
  import org.jruby.RubyHash;
9
9
  import org.jruby.RubyIO;
10
+ import org.jruby.RubyNumeric;
10
11
  import org.jruby.RubyInteger;
11
12
  import org.jruby.RubyFixnum;
12
13
  import org.jruby.runtime.Block;
@@ -114,6 +115,16 @@ public class Packer extends RubyObject {
114
115
  return this;
115
116
  }
116
117
 
118
+ @JRubyMethod(name = "write_float32")
119
+ public IRubyObject writeFloat32(ThreadContext ctx, IRubyObject numeric) {
120
+ Ruby runtime = ctx.runtime;
121
+ if (!(numeric instanceof RubyNumeric)) {
122
+ throw runtime.newArgumentError("Expected numeric");
123
+ }
124
+ buffer.write(ctx, encoder.encodeFloat32((RubyNumeric) numeric));
125
+ return this;
126
+ }
127
+
117
128
  @JRubyMethod(name = "write_array_header")
118
129
  public IRubyObject writeArrayHeader(ThreadContext ctx, IRubyObject size) {
119
130
  int s = (int) size.convertToInteger().getLongValue();
@@ -297,6 +297,8 @@ public class Unpacker extends RubyObject {
297
297
  str = stream.callMethod(ctx, "string").asString();
298
298
  } else if (stream instanceof RubyIO) {
299
299
  str = stream.callMethod(ctx, "read").asString();
300
+ } else if (stream.respondsTo("read")) {
301
+ str = stream.callMethod(ctx, "read").asString();
300
302
  } else {
301
303
  throw ctx.getRuntime().newTypeError(stream, "IO");
302
304
  }
@@ -255,6 +255,18 @@ static inline void msgpack_packer_write_u64(msgpack_packer_t* pk, uint64_t v)
255
255
  }
256
256
  }
257
257
 
258
+ static inline void msgpack_packer_write_float(msgpack_packer_t* pk, float v)
259
+ {
260
+ msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5);
261
+ union {
262
+ float f;
263
+ uint32_t u32;
264
+ char mem[4];
265
+ } castbuf = { v };
266
+ castbuf.u32 = _msgpack_be_float(castbuf.u32);
267
+ msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xca, castbuf.mem, 4);
268
+ }
269
+
258
270
  static inline void msgpack_packer_write_double(msgpack_packer_t* pk, double v)
259
271
  {
260
272
  msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9);
@@ -149,6 +149,17 @@ static VALUE Packer_write_map_header(VALUE self, VALUE n)
149
149
  return self;
150
150
  }
151
151
 
152
+ static VALUE Packer_write_float32(VALUE self, VALUE numeric)
153
+ {
154
+ if(!rb_obj_is_kind_of(numeric, rb_cNumeric)) {
155
+ rb_raise(rb_eArgError, "Expected numeric");
156
+ }
157
+
158
+ PACKER(self, pk);
159
+ msgpack_packer_write_float(pk, (float)rb_num2dbl(numeric));
160
+ return self;
161
+ }
162
+
152
163
  static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data)
153
164
  {
154
165
  PACKER(self, pk);
@@ -344,6 +355,7 @@ void MessagePack_Packer_module_init(VALUE mMessagePack)
344
355
  rb_define_method(cMessagePack_Packer, "write_array_header", Packer_write_array_header, 1);
345
356
  rb_define_method(cMessagePack_Packer, "write_map_header", Packer_write_map_header, 1);
346
357
  rb_define_method(cMessagePack_Packer, "write_ext", Packer_write_ext, 2);
358
+ rb_define_method(cMessagePack_Packer, "write_float32", Packer_write_float32, 1);
347
359
  rb_define_method(cMessagePack_Packer, "flush", Packer_flush, 0);
348
360
 
349
361
  /* delegation methods */
@@ -1,3 +1,3 @@
1
1
  module MessagePack
2
- VERSION = "0.7.1"
2
+ VERSION = "0.7.3"
3
3
  end
@@ -26,7 +26,7 @@ Gem::Specification.new do |s|
26
26
  s.add_development_dependency 'rake', ['~> 0.9.2']
27
27
  s.add_development_dependency 'rake-compiler', ['~> 0.9.4']
28
28
  if /java/ !~ RUBY_PLATFORM
29
- s.add_development_dependency 'rake-compiler-dock', ['~> 0.4.3']
29
+ s.add_development_dependency 'rake-compiler-dock', ['~> 0.5.0']
30
30
  end
31
31
  s.add_development_dependency 'rspec', ['~> 3.3']
32
32
  s.add_development_dependency 'yard', ['~> 0.8.2']
@@ -2,6 +2,9 @@
2
2
  require 'spec_helper'
3
3
 
4
4
  require 'stringio'
5
+ require 'tempfile'
6
+ require 'zlib'
7
+
5
8
  if defined?(Encoding)
6
9
  Encoding.default_external = 'ASCII-8BIT'
7
10
  end
@@ -19,6 +22,80 @@ describe MessagePack::Packer do
19
22
  MessagePack::Packer.new(StringIO.new, {})
20
23
  end
21
24
 
25
+ it 'gets IO or object which has #write to write/append data to it' do
26
+ sample_data = {"message" => "morning!", "num" => 1}
27
+ sample_packed = MessagePack.pack(sample_data)
28
+
29
+ Tempfile.open("for_io") do |file|
30
+ file.sync = true
31
+ p1 = MessagePack::Packer.new(file)
32
+ p1.write sample_data
33
+ p1.flush
34
+
35
+ file.rewind
36
+ expect(file.read).to eql(sample_packed)
37
+ file.unlink
38
+ end
39
+
40
+ dio = StringIO.new
41
+ p2 = MessagePack::Packer.new(dio)
42
+ p2.write sample_data
43
+ p2.flush
44
+ dio.rewind
45
+ expect(dio.string).to eql(sample_packed)
46
+
47
+ unless defined? JRUBY_VERSION
48
+ # JRuby seems to have bug not to flush GzipWriter buffer correctly (both of 1.7 and 9.0)
49
+ dio = StringIO.new
50
+ writer = Zlib::GzipWriter.new(dio)
51
+ writer.sync = true
52
+ p3 = MessagePack::Packer.new(writer)
53
+ p3.write sample_data
54
+ p3.flush
55
+ writer.flush(Zlib::FINISH)
56
+ writer.close
57
+ dio.rewind
58
+ compressed = dio.string
59
+ str = Zlib::GzipReader.wrap(StringIO.new(compressed)){|gz| gz.read }
60
+ expect(str).to eql(sample_packed)
61
+ end
62
+
63
+ class DummyIO
64
+ def initialize
65
+ @buf = "".force_encoding('ASCII-8BIT')
66
+ @pos = 0
67
+ end
68
+ def write(val)
69
+ @buf << val.to_s
70
+ end
71
+ def read(length=nil,outbuf="")
72
+ if @pos == @buf.size
73
+ nil
74
+ elsif length.nil?
75
+ val = @buf[@pos..(@buf.size)]
76
+ @pos = @buf.size
77
+ outbuf << val
78
+ outbuf
79
+ else
80
+ val = @buf[@pos..(@pos + length)]
81
+ @pos += val.size
82
+ @pos = @buf.size if @pos > @buf.size
83
+ outbuf << val
84
+ outbuf
85
+ end
86
+ end
87
+ def flush
88
+ # nop
89
+ end
90
+ end
91
+
92
+ dio = DummyIO.new
93
+ p4 = MessagePack::Packer.new(dio)
94
+ p4.write sample_data
95
+ p4.flush
96
+ expect(dio.read).to eql(sample_packed)
97
+ end
98
+
22
99
  it 'gets options to specify how to pack values' do
23
100
  u1 = MessagePack::Packer.new
24
101
  u1.compatibility_mode?.should == false
@@ -57,6 +134,30 @@ describe MessagePack::Packer do
57
134
  packer.to_s.should == "\x81"
58
135
  end
59
136
 
137
+ describe '#write_float32' do
138
+ tests = [
139
+ ['small floats', 3.14, "\xCA\x40\x48\xF5\xC3"],
140
+ ['big floats', Math::PI * 1_000_000_000_000_000_000, "\xCA\x5E\x2E\x64\xB7"],
141
+ ['negative floats', -2.1, "\xCA\xC0\x06\x66\x66"],
142
+ ['integer', 123, "\xCA\x42\xF6\x00\x00"],
143
+ ]
144
+
145
+ tests.each do |ctx, numeric, packed|
146
+ context("with #{ctx}") do
147
+ it("encodes #{numeric} as float32") do
148
+ packer.write_float32(numeric)
149
+ packer.to_s.should == packed
150
+ end
151
+ end
152
+ end
153
+
154
+ context 'with non numeric' do
155
+ it 'raises argument error' do
156
+ expect { packer.write_float32('abc') }.to raise_error(ArgumentError)
157
+ end
158
+ end
159
+ end
160
+
60
161
  it 'flush' do
61
162
  io = StringIO.new
62
163
  pk = MessagePack::Packer.new(io)
@@ -2,6 +2,7 @@
2
2
 
3
3
  require 'stringio'
4
4
  require 'tempfile'
5
+ require 'zlib'
5
6
 
6
7
  require 'spec_helper'
7
8
 
@@ -24,6 +25,73 @@ describe MessagePack::Unpacker do
24
25
  u2.allow_unknown_ext?.should == true
25
26
  end
26
27
 
28
+ it 'gets IO or object which has #read to read data from it' do
29
+ sample_data = {"message" => "morning!", "num" => 1}
30
+ sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT')
31
+
32
+ Tempfile.open("for_io") do |file|
33
+ file.sync = true
34
+ file.write sample_packed
35
+ file.rewind
36
+
37
+ u1 = MessagePack::Unpacker.new(file)
38
+ u1.each do |obj|
39
+ expect(obj).to eql(sample_data)
40
+ end
41
+ file.unlink
42
+ end
43
+
44
+ sio = StringIO.new(sample_packed)
45
+ u2 = MessagePack::Unpacker.new(sio)
46
+ u2.each do |obj|
47
+ expect(obj).to eql(sample_data)
48
+ end
49
+
50
+ dio = StringIO.new
51
+ Zlib::GzipWriter.wrap(dio){|gz| gz.write sample_packed }
52
+ reader = Zlib::GzipReader.new(StringIO.new(dio.string))
53
+ u3 = MessagePack::Unpacker.new(reader)
54
+ u3.each do |obj|
55
+ expect(obj).to eql(sample_data)
56
+ end
57
+
58
+ class DummyIO
59
+ def initialize
60
+ @buf = "".force_encoding('ASCII-8BIT')
61
+ @pos = 0
62
+ end
63
+ def write(val)
64
+ @buf << val.to_s
65
+ end
66
+ def read(length=nil,outbuf="")
67
+ if @pos == @buf.size
68
+ nil
69
+ elsif length.nil?
70
+ val = @buf[@pos..(@buf.size)]
71
+ @pos = @buf.size
72
+ outbuf << val
73
+ outbuf
74
+ else
75
+ val = @buf[@pos..(@pos + length)]
76
+ @pos += val.size
77
+ @pos = @buf.size if @pos > @buf.size
78
+ outbuf << val
79
+ outbuf
80
+ end
81
+ end
82
+ def flush
83
+ # nop
84
+ end
85
+ end
86
+
87
+ dio = DummyIO.new
88
+ dio.write sample_packed
89
+ u4 = MessagePack::Unpacker.new(dio)
90
+ u4.each do |obj|
91
+ expect(obj).to eql(sample_data)
92
+ end
93
+ end
94
+
27
95
  it 'read_array_header succeeds' do
28
96
  unpacker.feed("\x91")
29
97
  unpacker.read_array_header.should == 1
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: 0.7.1
4
+ version: 0.7.3
5
5
  platform: x64-mingw32
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: 2015-11-20 00:00:00.000000000 Z
13
+ date: 2016-01-07 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: 0.4.3
63
+ version: 0.5.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: 0.4.3
70
+ version: 0.5.0
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: rspec
73
73
  requirement: !ruby/object:Gem::Requirement