ffi-msgpack 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/.gemtest ADDED
File without changes
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --colour --format documentation
data/ChangeLog.md CHANGED
@@ -1,3 +1,17 @@
1
+ ### 0.2.0 / 2011-02-18
2
+
3
+ * Added {FFI::MsgPack::MsgObject#set!}.
4
+ * Added {FFI::MsgPack::MsgObject#set_nil!}.
5
+ * Added {FFI::MsgPack::MsgObject#set_boolean!}.
6
+ * Added {FFI::MsgPack::MsgObject#set_integer!}.
7
+ * Added {FFI::MsgPack::MsgObject#set_double!}.
8
+ * Added {FFI::MsgPack::MsgObject#set_float!}.
9
+ * Added {FFI::MsgPack::MsgObject#set_raw!}.
10
+ * Added {FFI::MsgPack::MsgObject#set_array!}.
11
+ * Added {FFI::MsgPack::MsgObject#set_map!}.
12
+ * Fixed a major bug, where newly created buffers holding Msg Raws, Arrays
13
+ or Maps, were getting GCed and then overwritten.
14
+
1
15
  ### 0.1.4 / 2010-08-12
2
16
 
3
17
  * Added {FFI::MsgPack.version}.
data/LICENSE.txt CHANGED
@@ -1,7 +1,4 @@
1
-
2
- The MIT License
3
-
4
- Copyright (c) 2010 Hal Brodigan
1
+ Copyright (c) 2010-2011 Hal Brodigan
5
2
 
6
3
  Permission is hereby granted, free of charge, to any person obtaining
7
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,12 +1,14 @@
1
1
  # ffi-msgpack
2
2
 
3
- * [github.com/postmodern/ffi-msgpack](http://github.com/postmodern/ffi-msgpack/)
4
- * [github.com/postmodern/ffi-msgpack/issues](http://github.com/postmodern/ffi-msgpack/issues)
5
- * Postmodern (postmodern.mod3 at gmail.com)
3
+ * [Source](http://github.com/postmodern/ffi-msgpack/)
4
+ * [Issues](http://github.com/postmodern/ffi-msgpack/issues)
5
+ * [Documentation](http://rubydoc.info/ffi-msgpack)
6
+ * [Email](mailto:postmodern.mod3 at gmail.com)
6
7
 
7
8
  ## Description
8
9
 
9
- Ruby FFI bindings for the [msgpack](http://msgpack.sourceforge.net/) library.
10
+ Ruby FFI bindings for the [msgpack](http://msgpack.sourceforge.net/)
11
+ library.
10
12
 
11
13
  ## Features
12
14
 
@@ -79,7 +81,7 @@ Enumerates over each unpacked Object from a stream:
79
81
  ## Requirements
80
82
 
81
83
  * [libmsgpack](http://msgpack.sourceforge.net/) >= 0.5.0
82
- * [ffi](http://github.com/ffi/ffi) ~> 0.6.0
84
+ * [ffi](http://github.com/ffi/ffi) >= 0.6.0, <= 1.1.0
83
85
 
84
86
  ## Install
85
87
 
@@ -87,5 +89,6 @@ Enumerates over each unpacked Object from a stream:
87
89
 
88
90
  ## License
89
91
 
90
- See {file:LICENSE.txt} for license information.
92
+ Copyright (c) 2010-2011 Hal Brodigan
91
93
 
94
+ See {file:LICENSE.txt} for license information.
data/Rakefile CHANGED
@@ -1,38 +1,36 @@
1
1
  require 'rubygems'
2
- require 'bundler'
2
+ require 'rake'
3
3
 
4
4
  begin
5
- Bundler.setup(:development, :doc)
6
- rescue Bundler::BundlerError => e
5
+ gem 'ore-tasks', '~> 0.4'
6
+ require 'ore/tasks'
7
+
8
+ Ore::Tasks.new
9
+ rescue LoadError => e
7
10
  STDERR.puts e.message
8
- STDERR.puts "Run `bundle install` to install missing gems"
9
- exit e.status_code
11
+ STDERR.puts "Run `gem install ore-tasks` to install 'ore/tasks'."
10
12
  end
11
13
 
12
- require 'rake'
13
- require 'jeweler'
14
+ begin
15
+ gem 'rspec', '~> 2.4'
16
+ require 'rspec/core/rake_task'
14
17
 
15
- Jeweler::Tasks.new do |gem|
16
- gem.name = 'ffi-msgpack'
17
- gem.licenses = ['MIT']
18
- gem.summary = %Q{FFI bindings for msgpack}
19
- gem.description = %Q{Ruby FFI bindings for the msgpack library.}
20
- gem.email = 'postmodern.mod3@gmail.com'
21
- gem.homepage = %Q{http://github.com/postmodern/ffi-msgpack}
22
- gem.authors = ['Postmodern']
23
- gem.requirements = ['libmsgpack, 0.5.0 or greater']
24
- gem.has_rdoc = 'yard'
18
+ RSpec::Core::RakeTask.new
19
+ rescue LoadError => e
20
+ task :spec do
21
+ abort "Please run `gem install rspec` to install RSpec."
22
+ end
25
23
  end
24
+ task :test => :spec
25
+ task :default => :spec
26
26
 
27
- require 'spec/rake/spectask'
27
+ begin
28
+ gem 'yard', '~> 0.6.0'
29
+ require 'yard'
28
30
 
29
- desc "Run all specifications"
30
- Spec::Rake::SpecTask.new(:spec) do |spec|
31
- spec.libs += ['lib', 'spec']
32
- spec.spec_files = FileList['spec/**/*_spec.rb']
33
- spec.spec_opts = ['--options', '.specopts']
31
+ YARD::Rake::YardocTask.new
32
+ rescue LoadError => e
33
+ task :yard do
34
+ abort "Please run `gem install yard` to install YARD."
35
+ end
34
36
  end
35
- task :default => :spec
36
-
37
- require 'yard'
38
- YARD::Rake::YardocTask.new
data/ffi-msgpack.gemspec CHANGED
@@ -1,118 +1,15 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
4
1
  # -*- encoding: utf-8 -*-
5
2
 
6
- Gem::Specification.new do |s|
7
- s.name = %q{ffi-msgpack}
8
- s.version = "0.1.4"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Postmodern"]
12
- s.date = %q{2010-08-12}
13
- s.description = %q{Ruby FFI bindings for the msgpack library.}
14
- s.email = %q{postmodern.mod3@gmail.com}
15
- s.extra_rdoc_files = [
16
- "ChangeLog.md",
17
- "LICENSE.txt",
18
- "README.md"
19
- ]
20
- s.files = [
21
- ".gitignore",
22
- ".specopts",
23
- ".yardopts",
24
- "ChangeLog.md",
25
- "Gemfile",
26
- "Gemfile.lock",
27
- "LICENSE.txt",
28
- "README.md",
29
- "Rakefile",
30
- "VERSION",
31
- "ffi-msgpack.gemspec",
32
- "lib/ffi/msgpack.rb",
33
- "lib/ffi/msgpack/exceptions/parse_error.rb",
34
- "lib/ffi/msgpack/extensions.rb",
35
- "lib/ffi/msgpack/extensions/array.rb",
36
- "lib/ffi/msgpack/extensions/false_class.rb",
37
- "lib/ffi/msgpack/extensions/float.rb",
38
- "lib/ffi/msgpack/extensions/hash.rb",
39
- "lib/ffi/msgpack/extensions/integer.rb",
40
- "lib/ffi/msgpack/extensions/nil_class.rb",
41
- "lib/ffi/msgpack/extensions/string.rb",
42
- "lib/ffi/msgpack/extensions/true_class.rb",
43
- "lib/ffi/msgpack/msg_array.rb",
44
- "lib/ffi/msgpack/msg_key_value.rb",
45
- "lib/ffi/msgpack/msg_map.rb",
46
- "lib/ffi/msgpack/msg_object.rb",
47
- "lib/ffi/msgpack/msg_object_union.rb",
48
- "lib/ffi/msgpack/msg_raw.rb",
49
- "lib/ffi/msgpack/msgpack.rb",
50
- "lib/ffi/msgpack/packable.rb",
51
- "lib/ffi/msgpack/packer.rb",
52
- "lib/ffi/msgpack/types.rb",
53
- "lib/ffi/msgpack/unpacker.rb",
54
- "lib/ffi/msgpack/zone.rb",
55
- "lib/ffi/msgpack/zone_chunk_list.rb",
56
- "lib/ffi/msgpack/zone_finalizer.rb",
57
- "lib/ffi/msgpack/zone_finalizer_array.rb",
58
- "spec/extensions/array_spec.rb",
59
- "spec/extensions/false_class_spec.rb",
60
- "spec/extensions/float_spec.rb",
61
- "spec/extensions/hash_spec.rb",
62
- "spec/extensions/integer_spec.rb",
63
- "spec/extensions/nil_class_spec.rb",
64
- "spec/extensions/string_spec.rb",
65
- "spec/extensions/true_class_spec.rb",
66
- "spec/msg_object_spec.rb",
67
- "spec/packer_spec.rb",
68
- "spec/spec_helper.rb",
69
- "spec/unpacker_spec.rb"
70
- ]
71
- s.has_rdoc = %q{yard}
72
- s.homepage = %q{http://github.com/postmodern/ffi-msgpack}
73
- s.licenses = ["MIT"]
74
- s.require_paths = ["lib"]
75
- s.requirements = ["libmsgpack, 0.5.0 or greater"]
76
- s.rubygems_version = %q{1.3.7}
77
- s.summary = %q{FFI bindings for msgpack}
78
- s.test_files = [
79
- "spec/extensions/array_spec.rb",
80
- "spec/extensions/false_class_spec.rb",
81
- "spec/extensions/float_spec.rb",
82
- "spec/extensions/hash_spec.rb",
83
- "spec/extensions/integer_spec.rb",
84
- "spec/extensions/nil_class_spec.rb",
85
- "spec/extensions/string_spec.rb",
86
- "spec/extensions/true_class_spec.rb",
87
- "spec/msg_object_spec.rb",
88
- "spec/packer_spec.rb",
89
- "spec/spec_helper.rb",
90
- "spec/unpacker_spec.rb"
91
- ]
92
-
93
- if s.respond_to? :specification_version then
94
- current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
95
- s.specification_version = 3
96
-
97
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
98
- s.add_runtime_dependency(%q<ffi>, ["~> 0.6.0"])
99
- s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
100
- s.add_development_dependency(%q<rake>, ["~> 0.8.7"])
101
- s.add_development_dependency(%q<jeweler>, ["~> 1.4.0"])
102
- s.add_development_dependency(%q<rspec>, ["~> 1.3.0"])
103
- else
104
- s.add_dependency(%q<ffi>, ["~> 0.6.0"])
105
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
106
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
107
- s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
108
- s.add_dependency(%q<rspec>, ["~> 1.3.0"])
109
- end
110
- else
111
- s.add_dependency(%q<ffi>, ["~> 0.6.0"])
112
- s.add_dependency(%q<bundler>, ["~> 1.0.0"])
113
- s.add_dependency(%q<rake>, ["~> 0.8.7"])
114
- s.add_dependency(%q<jeweler>, ["~> 1.4.0"])
115
- s.add_dependency(%q<rspec>, ["~> 1.3.0"])
3
+ begin
4
+ Ore::Specification.new do |gemspec|
5
+ # custom logic here
6
+ end
7
+ rescue NameError
8
+ begin
9
+ require 'ore/specification'
10
+ retry
11
+ rescue LoadError
12
+ STDERR.puts "The 'ffi-msgpack.gemspec' file requires Ore."
13
+ STDERR.puts "Run `gem install ore-core` to install Ore."
116
14
  end
117
15
  end
118
-
data/gemspec.yml ADDED
@@ -0,0 +1,19 @@
1
+ name: ffi-msgpack
2
+ version: 0.2.0
3
+ summary: FFI bindings for msgpack
4
+ description: Ruby FFI bindings for the msgpack library.
5
+ license: MIT
6
+ authors: Postmodern
7
+ email: postmodern.mod3@gmail.com
8
+ homepage: http://github.com/postmodern/ffi-msgpack
9
+ has_yard: true
10
+
11
+ requirements: libmsgpack >= 0.5.0
12
+
13
+ dependencies:
14
+ ffi: >= 0.6.0, <= 1.1.0
15
+
16
+ development_dependencies:
17
+ ore-tasks: ~> 0.4
18
+ rspec: ~> 2.4
19
+ yard: ~> 0.6.0
@@ -0,0 +1,7 @@
1
+ require 'ffi/msgpack/packable'
2
+
3
+ class Symbol
4
+
5
+ include FFI::MsgPack::Packable
6
+
7
+ end
@@ -4,5 +4,6 @@ require 'ffi/msgpack/extensions/false_class'
4
4
  require 'ffi/msgpack/extensions/integer'
5
5
  require 'ffi/msgpack/extensions/float'
6
6
  require 'ffi/msgpack/extensions/string'
7
+ require 'ffi/msgpack/extensions/symbol'
7
8
  require 'ffi/msgpack/extensions/array'
8
9
  require 'ffi/msgpack/extensions/hash'
@@ -20,6 +20,9 @@ module FFI
20
20
  else
21
21
  super()
22
22
  end
23
+
24
+ @object = nil
25
+ @memory = nil
23
26
  end
24
27
 
25
28
  #
@@ -33,8 +36,7 @@ module FFI
33
36
  #
34
37
  def MsgObject.new_nil(ptr=nil)
35
38
  obj = MsgObject.new(ptr)
36
- obj[:type] = :nil
37
-
39
+ obj.set_nil!
38
40
  return obj
39
41
  end
40
42
 
@@ -52,13 +54,7 @@ module FFI
52
54
  #
53
55
  def MsgObject.new_boolean(value,ptr=nil)
54
56
  obj = MsgObject.new(ptr)
55
- obj[:type] = :boolean
56
- obj[:values][:boolean] = if value
57
- 1
58
- else
59
- 0
60
- end
61
-
57
+ obj.set_boolean!(value)
62
58
  return obj
63
59
  end
64
60
 
@@ -76,15 +72,7 @@ module FFI
76
72
  #
77
73
  def MsgObject.new_integer(value,ptr=nil)
78
74
  obj = MsgObject.new(ptr)
79
-
80
- if value < 0
81
- obj[:type] = :negative_integer
82
- obj[:values][:i64] = value
83
- else
84
- obj[:type] = :positive_integer
85
- obj[:values][:u64] = value
86
- end
87
-
75
+ obj.set_integer!(value)
88
76
  return obj
89
77
  end
90
78
 
@@ -102,9 +90,7 @@ module FFI
102
90
  #
103
91
  def MsgObject.new_double(value,ptr=nil)
104
92
  obj = MsgObject.new(ptr)
105
- obj[:type] = :double
106
- obj[:values][:dec] = value
107
-
93
+ obj.set_double!(value)
108
94
  return obj
109
95
  end
110
96
 
@@ -112,7 +98,9 @@ module FFI
112
98
  # @see MsgObject.new_double
113
99
  #
114
100
  def MsgObject.new_float(value,ptr=nil)
115
- MsgObject.new_double(value,ptr)
101
+ obj = MsgObject.new(ptr)
102
+ obj.set_double!(value)
103
+ return obj
116
104
  end
117
105
 
118
106
  #
@@ -128,14 +116,8 @@ module FFI
128
116
  # The raw Msg Object.
129
117
  #
130
118
  def MsgObject.new_raw(data,ptr=nil)
131
- buffer = FFI::MemoryPointer.new(:uchar, data.length)
132
- buffer.put_bytes(0,data)
133
-
134
119
  obj = MsgObject.new(ptr)
135
- obj[:type] = :raw
136
- obj[:values][:raw][:size] = data.length
137
- obj[:values][:raw][:ptr] = buffer
138
-
120
+ obj.set_raw!(data)
139
121
  return obj
140
122
  end
141
123
 
@@ -152,17 +134,8 @@ module FFI
152
134
  # The array Msg Object.
153
135
  #
154
136
  def MsgObject.new_array(values,ptr=nil)
155
- entries = FFI::MemoryPointer.new(MsgObject,values.length)
156
-
157
- values.each_with_index do |value,index|
158
- MsgObject.new_object(value,entries[index])
159
- end
160
-
161
137
  obj = MsgObject.new(ptr)
162
- obj[:type] = :array
163
- obj[:values][:array][:size] = values.length
164
- obj[:values][:array][:ptr] = entries
165
-
138
+ obj.set_array!(values)
166
139
  return obj
167
140
  end
168
141
 
@@ -179,20 +152,8 @@ module FFI
179
152
  # The map Msg Object.
180
153
  #
181
154
  def MsgObject.new_map(values,ptr=nil)
182
- entries = FFI::MemoryPointer.new(MsgKeyValue,values.length)
183
-
184
- values.each_with_index do |(key,value),index|
185
- pair = MsgKeyValue.new(entries[index])
186
-
187
- MsgObject.new_object(key,pair[:key].to_ptr)
188
- MsgObject.new_object(value,pair[:value].to_ptr)
189
- end
190
-
191
- obj = MsgObject.new
192
- obj[:type] = :map
193
- obj[:values][:map][:size] = values.length
194
- obj[:values][:map][:ptr] = entries
195
-
155
+ obj = MsgObject.new(ptr)
156
+ obj.set_map!(values)
196
157
  return obj
197
158
  end
198
159
 
@@ -209,24 +170,191 @@ module FFI
209
170
  # The new Msg Object.
210
171
  #
211
172
  def MsgObject.new_object(value,ptr=nil)
173
+ obj = MsgObject.new(ptr)
174
+ obj.set!(value)
175
+ return obj
176
+ end
177
+
178
+ #
179
+ # Sets the Msg Objects value to nil.
180
+ #
181
+ # @since 0.2.0
182
+ #
183
+ def set_nil!
184
+ @objects = nil
185
+ @memory = nil
186
+
187
+ self[:type] = :nil
188
+ end
189
+
190
+ #
191
+ # Sets the Msg Objects value to a Boolean value.
192
+ #
193
+ # @param [Boolean] value
194
+ # The Boolean value.
195
+ #
196
+ # @since 0.2.0
197
+ #
198
+ def set_boolean!(value)
199
+ @objects = nil
200
+ @memory = nil
201
+
202
+ self[:type] = :boolean
203
+ self[:values][:boolean] = if value
204
+ 1
205
+ else
206
+ 0
207
+ end
208
+ end
209
+
210
+ #
211
+ # Sets the Msg Objects value to an Integer value.
212
+ #
213
+ # @param [Integer] value
214
+ # The Integer value.
215
+ #
216
+ # @since 0.2.0
217
+ #
218
+ def set_integer!(value)
219
+ @objects = nil
220
+ @memory = nil
221
+
222
+ if value < 0
223
+ self[:type] = :negative_integer
224
+ self[:values][:i64] = value
225
+ else
226
+ self[:type] = :positive_integer
227
+ self[:values][:u64] = value
228
+ end
229
+ end
230
+
231
+ #
232
+ # Sets the Msg Objects value to a Floating Point value.
233
+ #
234
+ # @param [Float] value
235
+ # The Floating Point value.
236
+ #
237
+ # @since 0.2.0
238
+ #
239
+ def set_double!(value)
240
+ @objects = nil
241
+ @memory = nil
242
+
243
+ self[:type] = :double
244
+ self[:values][:dec] = value
245
+ end
246
+
247
+ alias set_float! set_double!
248
+
249
+ #
250
+ # Sets the Msg Objects value to a String value.
251
+ #
252
+ # @param [String, Symbol] value
253
+ # The String value.
254
+ #
255
+ # @since 0.2.0
256
+ #
257
+ def set_raw!(value)
258
+ value = value.to_s
259
+
260
+ @objects = nil
261
+ @memory = FFI::MemoryPointer.new(:uchar, value.length)
262
+ @memory.put_bytes(0,value)
263
+
264
+ self[:type] = :raw
265
+
266
+ raw = self[:values][:raw]
267
+ raw[:size] = value.length
268
+ raw[:ptr] = @memory
269
+ end
270
+
271
+ #
272
+ # Sets the Msg Objects value to an Array value.
273
+ #
274
+ # @param [Array] value
275
+ # The Array value.
276
+ #
277
+ # @since 0.2.0
278
+ #
279
+ def set_array!(values)
280
+ @objects = []
281
+ @memory = FFI::MemoryPointer.new(MsgObject,values.length)
282
+
283
+ values.each_with_index do |value,index|
284
+ @objects << MsgObject.new_object(value,@memory[index])
285
+ end
286
+
287
+ self[:type] = :array
288
+
289
+ array = self[:values][:array]
290
+ array[:size] = values.length
291
+ array[:ptr] = @memory
292
+ end
293
+
294
+ #
295
+ # Sets the Msg Objects value to a Map value.
296
+ #
297
+ # @param [Hash] value
298
+ # The Map value.
299
+ #
300
+ # @since 0.2.0
301
+ #
302
+ def set_map!(values)
303
+ @objects = {}
304
+ @memory = FFI::MemoryPointer.new(MsgKeyValue,values.length)
305
+
306
+ values.each_with_index do |(key,value),index|
307
+ pair = MsgKeyValue.new(@memory[index])
308
+
309
+ key_obj = MsgObject.new_object(key,pair[:key].to_ptr)
310
+ value_obj = MsgObject.new_object(value,pair[:value].to_ptr)
311
+
312
+ @objects[key_obj] = value_obj
313
+ end
314
+
315
+ self[:type] = :map
316
+
317
+ map = self[:values][:map]
318
+ map[:size] = values.length
319
+ map[:ptr] = @memory
320
+ end
321
+
322
+ #
323
+ # Sets the contents of the Msg Object using a Ruby Object.
324
+ #
325
+ # @param [Object] value
326
+ # The Ruby object.
327
+ #
328
+ # @return [MsgObject]
329
+ # The new Msg Object.
330
+ #
331
+ # @raise [ArgumentError]
332
+ # The object was not a {Hash}, {Array}, {String}, {Symbol}, {Float},
333
+ # {Integer}, `true`, `false` or `nil`.
334
+ #
335
+ # @since 0.2.0
336
+ #
337
+ def set!(value)
212
338
  case value
213
339
  when Hash
214
- MsgObject.new_map(value,ptr)
340
+ set_map!(value)
215
341
  when Array
216
- MsgObject.new_array(value,ptr)
342
+ set_array!(value)
217
343
  when String, Symbol
218
- MsgObject.new_raw(value.to_s,ptr)
344
+ set_raw!(value)
219
345
  when Float
220
- MsgObject.new_double(value,ptr)
346
+ set_double!(value)
221
347
  when Integer
222
- MsgObject.new_integer(value,ptr)
348
+ set_integer!(value)
223
349
  when TrueClass, FalseClass
224
- MsgObject.new_boolean(value,ptr)
350
+ set_boolean!(value)
225
351
  when NilClass
226
- MsgObject.new_nil(ptr)
352
+ set_nil!
227
353
  else
228
- raise(ArgumentError,"ambigious object to create MsgObject from: #{value.inspect}",caller)
354
+ raise(ArgumentError,"ambigious object to create MsgObject from: #{value.inspect}")
229
355
  end
356
+
357
+ return value
230
358
  end
231
359
 
232
360
  #
@@ -281,7 +409,7 @@ module FFI
281
409
  when :map
282
410
  self[:values][:map].to_hash
283
411
  else
284
- raise(RuntimeError,"unknown msgpack object type",caller)
412
+ raise("unknown msgpack object type")
285
413
  end
286
414
  end
287
415
 
@@ -20,14 +20,16 @@ module FFI
20
20
  #
21
21
  # The version of libmsgpack.
22
22
  #
23
- # @return [String, nil]
23
+ # @return [Gem::Version, nil]
24
24
  # The version of `libmsgpack`. `nil` will be returned if the version
25
25
  # of `libmsgpack` is <= 0.5.1.
26
26
  #
27
27
  # @since 0.1.4
28
28
  #
29
29
  def MsgPack.version
30
- MsgPack.msgpack_version if MsgPack.respond_to?(:msgpack_version)
30
+ if MsgPack.respond_to?(:msgpack_version)
31
+ @version ||= Gem::Version.new(MsgPack.msgpack_version)
32
+ end
31
33
  end
32
34
 
33
35
  attach_function :msgpack_object_print, [:pointer, MsgObject.by_value], :void
@@ -62,6 +62,24 @@ module FFI
62
62
  return packer
63
63
  end
64
64
 
65
+ #
66
+ # Creates a new {Packer}.
67
+ #
68
+ # @param [FFI::Pointer] ptr
69
+ # An optional pointer to an existing packer.
70
+ #
71
+ # @since 0.2.0
72
+ #
73
+ def initialize(ptr=nil)
74
+ if ptr
75
+ super(ptr)
76
+ else
77
+ super()
78
+ end
79
+
80
+ @object = MsgObject.new
81
+ end
82
+
65
83
  #
66
84
  # Sets the write callback for the packer.
67
85
  #
@@ -117,7 +135,9 @@ module FFI
117
135
  # The packer.
118
136
  #
119
137
  def <<(value)
120
- pack(MsgObject.new_object(value))
138
+ @object.set!(value)
139
+
140
+ pack(@object)
121
141
  return self
122
142
  end
123
143
 
@@ -209,7 +209,7 @@ module FFI
209
209
  end
210
210
 
211
211
  #
212
- # Consums space in the buffer.
212
+ # Consumes space in the buffer.
213
213
  #
214
214
  # @param [Integer] size
215
215
  # The number of bytes to be consumed.
@@ -0,0 +1,14 @@
1
+ require 'spec_helper'
2
+ require 'ffi/msgpack/extensions/symbol'
3
+
4
+ describe Symbol do
5
+ subject { :hello }
6
+
7
+ it "should be packable" do
8
+ should be_kind_of(FFI::MsgPack::Packable)
9
+ end
10
+
11
+ it "should pack to a msg" do
12
+ subject.to_msgpack.should == "\xA5hello"
13
+ end
14
+ end
@@ -190,4 +190,41 @@ describe MsgPack::MsgObject do
190
190
  @obj.to_ruby.should == @hash
191
191
  end
192
192
  end
193
+
194
+ it "should create highly nested Msg Objects" do
195
+ obj = MsgPack::MsgObject.new_object({'one' => {2 => [3.0]}})
196
+
197
+ obj[:type].should == :map
198
+ map = obj[:values][:map]
199
+ map[:size].should == 1
200
+
201
+ pair = MsgPack::MsgKeyValue.new(map[:ptr])
202
+
203
+ key = pair[:key]
204
+ key[:type].should == :raw
205
+
206
+ raw = key[:values][:raw]
207
+ raw[:ptr].get_bytes(0,raw[:size]).should == 'one'
208
+
209
+ value = pair[:value]
210
+ value[:type].should == :map
211
+
212
+ map = value[:values][:map]
213
+ map[:size].should == 1
214
+
215
+ pair = MsgPack::MsgKeyValue.new(map[:ptr])
216
+ key = pair[:key]
217
+ key[:type].should == :positive_integer
218
+ key[:values][:i64].should == 2
219
+
220
+ value = pair[:value]
221
+ value[:type].should == :array
222
+
223
+ array = value[:values][:array]
224
+ array[:size].should == 1
225
+
226
+ value = MsgPack::MsgObject.new(array[:ptr])
227
+ value[:type].should == :double
228
+ value[:values][:dec].should == 3.0
229
+ end
193
230
  end
data/spec/spec_helper.rb CHANGED
@@ -1,15 +1,5 @@
1
- require 'rubygems'
2
- require 'bundler'
1
+ gem 'rspec', '~> 2.4'
2
+ require 'rspec'
3
3
 
4
- begin
5
- Bundler.setup(:runtime, :test)
6
- rescue Bundler::BundlerError => e
7
- STDERR.puts e.message
8
- STDERR.puts "Run `bundle install` to install missing gems"
9
- exit e.status_code
10
- end
11
-
12
- require 'spec'
13
4
  require 'ffi'
14
-
15
5
  include FFI
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ffi-msgpack
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 1
8
- - 4
9
- version: 0.1.4
4
+ prerelease:
5
+ version: 0.2.0
10
6
  platform: ruby
11
7
  authors:
12
8
  - Postmodern
@@ -14,106 +10,75 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-08-12 00:00:00 -07:00
13
+ date: 2011-02-18 00:00:00 -08:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
21
17
  name: ffi
18
+ prerelease: false
22
19
  requirement: &id001 !ruby/object:Gem::Requirement
23
20
  none: false
24
21
  requirements:
25
- - - ~>
22
+ - - ">="
26
23
  - !ruby/object:Gem::Version
27
- segments:
28
- - 0
29
- - 6
30
- - 0
31
24
  version: 0.6.0
25
+ - - <=
26
+ - !ruby/object:Gem::Version
27
+ version: 1.1.0
32
28
  type: :runtime
33
- prerelease: false
34
29
  version_requirements: *id001
35
30
  - !ruby/object:Gem::Dependency
36
- name: bundler
31
+ name: ore-tasks
32
+ prerelease: false
37
33
  requirement: &id002 !ruby/object:Gem::Requirement
38
34
  none: false
39
35
  requirements:
40
36
  - - ~>
41
37
  - !ruby/object:Gem::Version
42
- segments:
43
- - 1
44
- - 0
45
- - 0
46
- version: 1.0.0
38
+ version: "0.4"
47
39
  type: :development
48
- prerelease: false
49
40
  version_requirements: *id002
50
41
  - !ruby/object:Gem::Dependency
51
- name: rake
42
+ name: rspec
43
+ prerelease: false
52
44
  requirement: &id003 !ruby/object:Gem::Requirement
53
45
  none: false
54
46
  requirements:
55
47
  - - ~>
56
48
  - !ruby/object:Gem::Version
57
- segments:
58
- - 0
59
- - 8
60
- - 7
61
- version: 0.8.7
49
+ version: "2.4"
62
50
  type: :development
63
- prerelease: false
64
51
  version_requirements: *id003
65
52
  - !ruby/object:Gem::Dependency
66
- name: jeweler
53
+ name: yard
54
+ prerelease: false
67
55
  requirement: &id004 !ruby/object:Gem::Requirement
68
56
  none: false
69
57
  requirements:
70
58
  - - ~>
71
59
  - !ruby/object:Gem::Version
72
- segments:
73
- - 1
74
- - 4
75
- - 0
76
- version: 1.4.0
60
+ version: 0.6.0
77
61
  type: :development
78
- prerelease: false
79
62
  version_requirements: *id004
80
- - !ruby/object:Gem::Dependency
81
- name: rspec
82
- requirement: &id005 !ruby/object:Gem::Requirement
83
- none: false
84
- requirements:
85
- - - ~>
86
- - !ruby/object:Gem::Version
87
- segments:
88
- - 1
89
- - 3
90
- - 0
91
- version: 1.3.0
92
- type: :development
93
- prerelease: false
94
- version_requirements: *id005
95
63
  description: Ruby FFI bindings for the msgpack library.
96
- email: postmodern.mod3@gmail.com
64
+ email:
65
+ - postmodern.mod3@gmail.com
97
66
  executables: []
98
67
 
99
68
  extensions: []
100
69
 
101
70
  extra_rdoc_files:
102
- - ChangeLog.md
103
- - LICENSE.txt
104
71
  - README.md
105
72
  files:
106
- - .gitignore
107
- - .specopts
73
+ - .gemtest
74
+ - .rspec
108
75
  - .yardopts
109
76
  - ChangeLog.md
110
- - Gemfile
111
- - Gemfile.lock
112
77
  - LICENSE.txt
113
78
  - README.md
114
79
  - Rakefile
115
- - VERSION
116
80
  - ffi-msgpack.gemspec
81
+ - gemspec.yml
117
82
  - lib/ffi/msgpack.rb
118
83
  - lib/ffi/msgpack/exceptions/parse_error.rb
119
84
  - lib/ffi/msgpack/extensions.rb
@@ -124,6 +89,7 @@ files:
124
89
  - lib/ffi/msgpack/extensions/integer.rb
125
90
  - lib/ffi/msgpack/extensions/nil_class.rb
126
91
  - lib/ffi/msgpack/extensions/string.rb
92
+ - lib/ffi/msgpack/extensions/symbol.rb
127
93
  - lib/ffi/msgpack/extensions/true_class.rb
128
94
  - lib/ffi/msgpack/msg_array.rb
129
95
  - lib/ffi/msgpack/msg_key_value.rb
@@ -147,12 +113,13 @@ files:
147
113
  - spec/extensions/integer_spec.rb
148
114
  - spec/extensions/nil_class_spec.rb
149
115
  - spec/extensions/string_spec.rb
116
+ - spec/extensions/symbol_spec.rb
150
117
  - spec/extensions/true_class_spec.rb
151
118
  - spec/msg_object_spec.rb
152
119
  - spec/packer_spec.rb
153
120
  - spec/spec_helper.rb
154
121
  - spec/unpacker_spec.rb
155
- has_rdoc: yard
122
+ has_rdoc: true
156
123
  homepage: http://github.com/postmodern/ffi-msgpack
157
124
  licenses:
158
125
  - MIT
@@ -166,35 +133,30 @@ required_ruby_version: !ruby/object:Gem::Requirement
166
133
  requirements:
167
134
  - - ">="
168
135
  - !ruby/object:Gem::Version
169
- hash: 1626239469308121946
170
- segments:
171
- - 0
172
136
  version: "0"
173
137
  required_rubygems_version: !ruby/object:Gem::Requirement
174
138
  none: false
175
139
  requirements:
176
140
  - - ">="
177
141
  - !ruby/object:Gem::Version
178
- segments:
179
- - 0
180
142
  version: "0"
181
143
  requirements:
182
- - libmsgpack, 0.5.0 or greater
183
- rubyforge_project:
184
- rubygems_version: 1.3.7
144
+ - libmsgpack >= 0.5.0
145
+ rubyforge_project: ffi-msgpack
146
+ rubygems_version: 1.5.0
185
147
  signing_key:
186
148
  specification_version: 3
187
149
  summary: FFI bindings for msgpack
188
150
  test_files:
151
+ - spec/msg_object_spec.rb
152
+ - spec/packer_spec.rb
153
+ - spec/unpacker_spec.rb
154
+ - spec/extensions/integer_spec.rb
155
+ - spec/extensions/true_class_spec.rb
189
156
  - spec/extensions/array_spec.rb
190
157
  - spec/extensions/false_class_spec.rb
191
158
  - spec/extensions/float_spec.rb
192
- - spec/extensions/hash_spec.rb
193
- - spec/extensions/integer_spec.rb
194
- - spec/extensions/nil_class_spec.rb
159
+ - spec/extensions/symbol_spec.rb
195
160
  - spec/extensions/string_spec.rb
196
- - spec/extensions/true_class_spec.rb
197
- - spec/msg_object_spec.rb
198
- - spec/packer_spec.rb
199
- - spec/spec_helper.rb
200
- - spec/unpacker_spec.rb
161
+ - spec/extensions/nil_class_spec.rb
162
+ - spec/extensions/hash_spec.rb
data/.gitignore DELETED
@@ -1,4 +0,0 @@
1
- doc
2
- pkg
3
- .bundle
4
- .yardoc
data/.specopts DELETED
@@ -1 +0,0 @@
1
- --colour --format specdoc
data/Gemfile DELETED
@@ -1,24 +0,0 @@
1
- source 'https://rubygems.org'
2
-
3
- group(:runtime) do
4
- gem 'ffi', '~> 0.6.0'
5
- end
6
-
7
- group(:development) do
8
- gem 'bundler', '~> 1.0.0'
9
- gem 'rake', '~> 0.8.7'
10
- gem 'jeweler', '~> 1.4.0', :git => 'git://github.com/technicalpickles/jeweler.git'
11
- end
12
-
13
- group(:doc) do
14
- case RUBY_PLATFORM
15
- when 'java'
16
- gem 'maruku', '~> 0.6.0'
17
- else
18
- gem 'rdiscount', '~> 1.6.3'
19
- end
20
-
21
- gem 'yard', '~> 0.5.3'
22
- end
23
-
24
- gem 'rspec', '~> 1.3.0', :group => [:development, :test]
data/Gemfile.lock DELETED
@@ -1,33 +0,0 @@
1
- GIT
2
- remote: git://github.com/technicalpickles/jeweler.git
3
- revision: b996854
4
- specs:
5
- jeweler (1.4.0)
6
- bundler (>= 0.9.5)
7
- gemcutter (>= 0.1.0)
8
- git (>= 1.2.5)
9
- rake
10
-
11
- GEM
12
- remote: https://rubygems.org/
13
- specs:
14
- ffi (0.6.3)
15
- rake (>= 0.8.7)
16
- gemcutter (0.6.1)
17
- git (1.2.5)
18
- rake (0.8.7)
19
- rdiscount (1.6.5)
20
- rspec (1.3.0)
21
- yard (0.5.8)
22
-
23
- PLATFORMS
24
- ruby
25
-
26
- DEPENDENCIES
27
- bundler (~> 1.0.0)
28
- ffi (~> 0.6.0)
29
- jeweler (~> 1.4.0)!
30
- rake (~> 0.8.7)
31
- rdiscount (~> 1.6.3)
32
- rspec (~> 1.3.0)
33
- yard (~> 0.5.3)
data/VERSION DELETED
@@ -1 +0,0 @@
1
- 0.1.4