hx_cbor 2021.8.20

Sign up to get free protection for your applications and to get access to all the features.
Files changed (59) hide show
  1. checksums.yaml +7 -0
  2. data/.gitignore +30 -0
  3. data/.travis.yml +24 -0
  4. data/ChangeLog +106 -0
  5. data/Gemfile +11 -0
  6. data/README.rdoc +191 -0
  7. data/Rakefile +97 -0
  8. data/doclib/cbor.rb +80 -0
  9. data/doclib/cbor/buffer.rb +193 -0
  10. data/doclib/cbor/core_ext.rb +133 -0
  11. data/doclib/cbor/error.rb +14 -0
  12. data/doclib/cbor/packer.rb +133 -0
  13. data/doclib/cbor/simple.rb +15 -0
  14. data/doclib/cbor/tagged.rb +16 -0
  15. data/doclib/cbor/unpacker.rb +138 -0
  16. data/ext/cbor/3424.i.rb +29 -0
  17. data/ext/cbor/buffer.c +693 -0
  18. data/ext/cbor/buffer.h +484 -0
  19. data/ext/cbor/buffer_class.c +516 -0
  20. data/ext/cbor/buffer_class.h +41 -0
  21. data/ext/cbor/cbor.h +69 -0
  22. data/ext/cbor/compat.h +147 -0
  23. data/ext/cbor/core_ext.c +201 -0
  24. data/ext/cbor/core_ext.h +35 -0
  25. data/ext/cbor/example.rb +10 -0
  26. data/ext/cbor/extconf.rb +29 -0
  27. data/ext/cbor/install.sh +1 -0
  28. data/ext/cbor/packer.c +169 -0
  29. data/ext/cbor/packer.h +362 -0
  30. data/ext/cbor/packer_class.c +304 -0
  31. data/ext/cbor/packer_class.h +39 -0
  32. data/ext/cbor/rbinit.c +51 -0
  33. data/ext/cbor/renamer.h +56 -0
  34. data/ext/cbor/rmem.c +103 -0
  35. data/ext/cbor/rmem.h +118 -0
  36. data/ext/cbor/sysdep.h +139 -0
  37. data/ext/cbor/sysdep_endian.h +59 -0
  38. data/ext/cbor/sysdep_types.h +55 -0
  39. data/ext/cbor/unpacker.c +784 -0
  40. data/ext/cbor/unpacker.h +135 -0
  41. data/ext/cbor/unpacker_class.c +439 -0
  42. data/ext/cbor/unpacker_class.h +39 -0
  43. data/hx_cbor.gemspec +25 -0
  44. data/lib/cbor.rb +6 -0
  45. data/lib/cbor/version.rb +3 -0
  46. data/spec/buffer_io_spec.rb +260 -0
  47. data/spec/buffer_spec.rb +576 -0
  48. data/spec/cases.cbor +0 -0
  49. data/spec/cases.cbor_stream +0 -0
  50. data/spec/cases.json +1 -0
  51. data/spec/cases.msg +0 -0
  52. data/spec/cases_compact.msg +0 -0
  53. data/spec/cases_spec.rb +39 -0
  54. data/spec/format_spec.rb +540 -0
  55. data/spec/packer_spec.rb +127 -0
  56. data/spec/random_compat.rb +24 -0
  57. data/spec/spec_helper.rb +68 -0
  58. data/spec/unpacker_spec.rb +260 -0
  59. metadata +198 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 20b2a1c98e3d92ad1045bfef47cb5de48075082dd845044c6ba4a22125f59ba8
4
+ data.tar.gz: 4c3175e68f8a7b82eafe846d23347b403c8b0796c542078c2b9e4896d8b71e01
5
+ SHA512:
6
+ metadata.gz: ab71bb54d7ae983c7f1946c36b07dab68e12ac70980af7b093fee7dee2267683326699f281db135361fd39f590b5b0ef41059973642b91602b78201acf30f8e8
7
+ data.tar.gz: ff2aab16ae8e19a9823746c8ebe5daed5d5517433594ff40ae8c8095ae574c80e22d7b86b89e68c078f572375b5037a94203e7bfa2fbadfbccbac2c4e49017bd
data/.gitignore ADDED
@@ -0,0 +1,30 @@
1
+ *.o
2
+ *.so
3
+ *.gem
4
+ *.class
5
+ .bundle
6
+ Gemfile.lock
7
+ pkg
8
+ test/debug.log
9
+ *~
10
+ /rdoc
11
+ tmp
12
+ .classpath
13
+ .project
14
+ .settings
15
+ /nbproject/private/
16
+ ext/java/build
17
+ ext/java/msgpack.jar
18
+ spec/bench*
19
+ lib/cbor/cbor.bundle
20
+ TAGS
21
+ .yardoc
22
+ doc
23
+ ext/cbor/Makefile
24
+ ext/cbor/cbor.cflags
25
+ ext/cbor/cbor.config
26
+ ext/cbor/cbor.creator
27
+ ext/cbor/cbor.cxxflags
28
+ ext/cbor/cbor.files
29
+ ext/cbor/cbor.includes
30
+ ext/cbor/mkmf.log
data/.travis.yml ADDED
@@ -0,0 +1,24 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.0.0
4
+ - 2.1.10
5
+ - 2.2.10
6
+ - 2.3.8
7
+ - 2.4.6
8
+ - 2.5.5
9
+ - 2.6.3
10
+ - ruby-head
11
+ matrix:
12
+ allow_failures:
13
+ - rvm: 2.0.0
14
+ - rvm: 2.1.10
15
+ - rvm: 2.2.10
16
+ - rvm: ruby-head
17
+
18
+ gemfile:
19
+ - Gemfile
20
+
21
+ script: "bundle exec rake spec"
22
+
23
+ notifications:
24
+ irc: "irc.freenode.org#coap"
data/ChangeLog ADDED
@@ -0,0 +1,106 @@
1
+ 2016-04-11 Carsten Bormann <cabo@tzi.org>
2
+
3
+ * 0.5.9.1: Fix WIN32 problem inherited from upstream
4
+
5
+ 2014-12-13 Carsten Bormann <cabo@tzi.org>
6
+
7
+ * 0.5.9.0: Upstream fixes; prepare for Ruby 2.2 (use GC-able
8
+ symbols for :keys_as_symbols, use rb_integer_pack if available)
9
+
10
+ 2014-12-12 Carsten Bormann <cabo@tzi.org>
11
+
12
+ * 0.5.8.0: Upstream fixes (including {symbolize_keys: true} as an
13
+ alternative for :keys_as_symbols); README updates.
14
+
15
+ 2014-02-09 Carsten Bormann <cabo@tzi.org>
16
+
17
+ * 0.5.6.4: Add more checking for bare indefinite breaks and
18
+ non-strings inside indefinite strings.
19
+
20
+ 2013-08-17 Carsten Bormann <cabo@tzi.org>
21
+
22
+ * First version of CBOR variant of this code.
23
+
24
+ 2013-09-23 version 0.5.6:
25
+
26
+ * Fixed "can't modify frozen String" exception in Unpacker with ruby 2.1.0-dev
27
+ * Getting work with Ruby v2.0 on Windows (Thank you @thegreendroid)
28
+ * Fixed EOFError handling in Unpacker
29
+
30
+
31
+ 2013-05-12 version 0.5.5:
32
+
33
+ * Fixed SEGV problem in to_msgpack
34
+ * Fixed a possible race condition in MessagePack.load when it loads data from IO
35
+ * mingw32 package includes binary for ruby-2.0.0
36
+
37
+
38
+ 2013-03-15 version 0.5.4:
39
+
40
+ * Added missing MessagePack::Unpacker#reset method
41
+
42
+
43
+ 2013-02-14 version 0.5.3:
44
+
45
+ * Fixed segfault problem on Buffer#clear (reuse rmem internal fragment optimization)
46
+ * Fixed segfault problem on Buffer (rmem free code)
47
+
48
+
49
+ 2013-02-07 version 0.5.2:
50
+
51
+ * Fixed invalid pack/unpack on 32bit architecture such as Win32
52
+ * Disable rmem on Rubinius because rmem is not thread safe
53
+
54
+
55
+ 2012-12-23 version 0.5.1:
56
+
57
+ * Fixed compile error with Rubinius 2.0.0-dev
58
+ * Optimized msgpack_packer_write_hash for Rubinius
59
+
60
+
61
+ 2012-12-20 version 0.5.0:
62
+
63
+ * Rewrote all code and improved performance significantly
64
+ * Added MessagePack::Buffer class
65
+ * Added MessagePack::Packer class
66
+ * Added Packer#buffer and Unpacker#buffer accessors which return MessagePack::Buffer
67
+ * Added Packer#write_{array,map}_header and Unpacker#read_{array,map}_header methods
68
+ * Added Packer#write_nil and Unpacker#skip_nil methods
69
+ * Added Packer#write -> #pack alias and Unpacker#read method
70
+ * Added exception classes - UnpackError, MalformedFormatError, StackError and TypeError
71
+ * Added MessagePack.dup -> .pack and MessagePack.load -> .unpack aliases
72
+ * Added Packer#empty?, #size and #clear methods
73
+ * Added Packer#write_to(io) method to flush serialized data to IO efficiently
74
+ * Added Unpacker#skip method to skip an object efficiently
75
+ * Removed obsoleted Unpacker#fill, #execute, #execute_limit, #finished? and #data methods
76
+ * Removed obsoleted Unapcker#stream and #stream= methods. Use unpacker.buffer.io instead
77
+
78
+
79
+ 2012-05-05 version 0.4.7:
80
+
81
+ * Fixed serialization of double values on ARM OABI architectures
82
+ * Fixed byteorder problem on big-endian platforms
83
+ * Don't use MRI internals in the Ruby extension for Rubinius
84
+ * Detect whether st.h is present and don't use RUBY_VM as the condition for
85
+ Rubinius
86
+
87
+ 2011-08-08 version 0.4.6:
88
+
89
+ * Fixed compile error problem on Mac OS X Lion
90
+
91
+ 2011-05-09 version 0.4.5:
92
+
93
+ * Improves compatibility with JRuby
94
+
95
+ 2010-11-28 version 0.4.4:
96
+
97
+ * Adds Unpacker#feed_each method
98
+ * Improves compatibility with Rubinius
99
+ * Improves compatibility with ruby-1.8.5
100
+ * Encodings of String instances to UTF-8 on Ruby 1.9
101
+
102
+ 2010-06-29 version 0.4.3:
103
+
104
+ * Adds MessagePack::VERSION constant
105
+ * Fixes SEGV problem caused by GC bug at MessagePack_Unpacker_mark
106
+
data/Gemfile ADDED
@@ -0,0 +1,11 @@
1
+ source 'https://rubygems.org/'
2
+
3
+ gemspec
4
+
5
+ group :test do
6
+ gem "rake"
7
+ gem 'rake-compiler'
8
+ gem 'rspec'
9
+ gem 'json'
10
+ gem 'yard'
11
+ end
data/README.rdoc ADDED
@@ -0,0 +1,191 @@
1
+ = CBOR for Ruby
2
+
3
+ This is a Ruby implementation of the CBOR[http://cbor.io] encoding, based on
4
+ the (polished) high-performance msgpack-ruby code.
5
+
6
+ Documentation will follow, but generally, if you replace MessagePack
7
+ and msgpack with CBOR and cbor in the text cited from MessagePack
8
+ below, you will be on the right track. For a starter:
9
+
10
+ require 'cbor'
11
+ s = [1, 2, 33.5, 4].to_cbor #=> "\x84\x01\x02\xF9P0\x04"
12
+ CBOR.decode(s) #=> [1, 2, 33.5, 4]
13
+
14
+ Use RubyGems to install:
15
+
16
+ gem install cbor
17
+
18
+ CBOR is an object representation format defined by the IETF[http://ietf.org].
19
+ The specification[http://tools.ietf.org/html/rfc7049]
20
+ is an IETF Standards-Track specification
21
+ and has been published as RFC 7049.
22
+
23
+ This is all based on wonderful work by frsyuki, and I have no idea how
24
+ to acknowledge him appropriately. This gem is not intended to fork or
25
+ supersede MessagePack[http://msgpack.org], which has a vibrant
26
+ ecosystem. It is just making use of the high-quality code that is
27
+ available in this community. If MessagePack works for you, go for it.
28
+ If you need CBOR, you need this.
29
+
30
+ Todos:
31
+
32
+ * This code has not yet been fully optimized, so it is still a few
33
+ percent slower than msgpack-ruby.
34
+
35
+ * Properly document things, in particular the classes CBOR::Simple and
36
+ CBOR::Tagged. If you check out the source, you can +rake+ +doc+ to
37
+ get some documentation in the directory +doc+ (see +index.html+ there).
38
+
39
+ * Cover more rubies.
40
+ * \[✔✔✔✔] tested on MRI (1.9.3, 2.0.0, 2.1.10, 2.2.10, 2.3.7, 2.4.4 and 2.5.1).
41
+ * (\[✔] There now also is some basic MRI 1.8.7 compatibility, however 1.8.7 does not support differentiation between byte and text strings.)
42
+ * \[✔] tested on Rubinius 2.4.1.
43
+ * \[_] Publish the pure-ruby version and make it work the same way on JRuby.
44
+
45
+ * Find and implement good ways to offer CBOR's indefinite length
46
+ ("streaming") capability at the Ruby API level. (Decoding is fully
47
+ supported, just no streaming or indefinite length encoding.)
48
+
49
+ * Rename some of the internals from msgpack to cbor. Right now, much
50
+ of the code still uses the name msgpack in its identifiers, to
51
+ facilitate merging upstream fixes. (The msgpack and cbor gems
52
+ coexist nicely in one MRI instance due to the magic in +renamer.h+.)
53
+
54
+ Same Apache 2.0 License applies to the changes as to the original.
55
+ For the changes:
56
+
57
+ Author:: Carsten Bormann <cabo@tzi.org>
58
+ Copyright:: Copyright (c) 2013, 2014 Carsten Bormann
59
+ License:: Apache License, Version 2.0
60
+
61
+ {<img src="https://travis-ci.org/cabo/cbor-ruby.svg?branch=master" />}[https://travis-ci.org/cabo/cbor-ruby] {<img src="https://badge.fury.io/rb/cbor.svg" alt="Gem Version" />}[http://badge.fury.io/rb/cbor]
62
+
63
+ For the original, see below.
64
+
65
+ = MessagePack
66
+
67
+ MessagePack[http://msgpack.org] is an efficient binary serialization format.
68
+ It lets you exchange data among multiple languages like JSON but it's faster and smaller.
69
+ For example, small integers (like flags or error code) are encoded into a single byte,
70
+ and typical short strings only require an extra byte in addition to the strings themselves.
71
+
72
+ If you ever wished to use JSON for convenience (storing an image with metadata) but could
73
+ not for technical reasons (binary data, size, speed...), MessagePack is a perfect replacement.
74
+
75
+ require 'msgpack'
76
+ msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03"
77
+ MessagePack.unpack(msg) #=> [1,2,3]
78
+
79
+ Use RubyGems to install:
80
+
81
+ gem install msgpack
82
+
83
+ or build msgpack-ruby and install:
84
+
85
+ bundle
86
+ rake
87
+ gem install --local pkg/msgpack
88
+
89
+
90
+ = Use cases
91
+
92
+ * Store objects efficiently serialized by msgpack on memcached or Redis
93
+ * In fact Redis supports msgpack in EVAL-scripts[http://redis.io/commands/eval]
94
+ * Upload data in efficient format from mobile devices such as smartphones
95
+ * MessagePack works on iPhone/iPad and Android. See also Objective-C[https://github.com/msgpack/msgpack-objectivec] and Java[https://github.com/msgpack/msgpack-java] implementations
96
+ * Design a portable protocol to communicate with embedded devices
97
+ * Check also Fluentd[http://fluentd.org/] which is a log collector which uses msgpack for the log format (they say it uses JSON but actually it's msgpack, which is compatible with JSON)
98
+ * Exchange objects between software components written in different languages
99
+ * You'll need a flexible but efficient format so that components exchange objects while keeping compatibility
100
+
101
+
102
+ = Portability
103
+
104
+ MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.
105
+
106
+ And it works with MRI (CRuby) and Rubinius.
107
+ Patches to improve portability is highly welcomed.
108
+
109
+
110
+ = Serializing objects
111
+
112
+ Use *MessagePack.pack* or *to_msgpack*:
113
+
114
+ require 'msgpack'
115
+ msg = MessagePack.pack(obj) # or
116
+ msg = obj.to_msgpack
117
+
118
+ == Streaming serialization
119
+
120
+ Packer provides advanced API to serialize objects in streaming style:
121
+
122
+ # serialize a 2-element array [e1, e2]
123
+ pk = MessagePack::Packer.new(io)
124
+ pk.write_array_header(2).write(e1).write(e2).flush
125
+
126
+ See {API reference}[http://ruby.msgpack.org/MessagePack/Packer.html] for details.
127
+
128
+ = Deserializing objects
129
+
130
+ Use *MessagePack.unpack*:
131
+
132
+ require 'msgpack'
133
+ obj = MessagePack.unpack(msg)
134
+
135
+ == Streaming deserialization
136
+
137
+ Unpacker provides advanced API to deserialize objects in streaming style:
138
+
139
+ # deserialize objects from an IO
140
+ u = MessagePack::Unpacker.new(io)
141
+ u.each do |obj|
142
+ # ...
143
+ end
144
+
145
+ or event-driven style which works well with EventMachine:
146
+
147
+ # event-driven deserialization
148
+ def on_read(data)
149
+ @u ||= MessagePack::Unpacker.new
150
+ @u.feed_each(data) {|obj|
151
+ # ...
152
+ }
153
+ end
154
+
155
+ See {API reference}[http://ruby.msgpack.org/MessagePack/Unpacker.html] for details.
156
+
157
+
158
+ = Buffer API
159
+
160
+ MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.
161
+
162
+ This {MessagePack::Buffer}[http://ruby.msgpack.org/MessagePack/Buffer.html] is backed with a fixed-length shared memory pool which is very fast for small data (<= 4KB),
163
+ and has zero-copy capability which significantly affects performance to handle large binary data.
164
+
165
+ = How to build and run tests
166
+
167
+ Before building msgpack, you need to install bundler and dependencies.
168
+
169
+ gem install bundler
170
+ bundle install
171
+
172
+ Then, you can run the tasks as follows:
173
+
174
+ * Build
175
+
176
+ bundle exec rake build
177
+
178
+ * Run tests
179
+
180
+ bundle exec rake spec
181
+
182
+ * Generating docs
183
+
184
+ bundle exec rake doc
185
+
186
+ = Copyright
187
+
188
+ Author:: Sadayuki Furuhashi <frsyuki@gmail.com>
189
+ Copyright:: Copyright (c) 2008-2013 Sadayuki Furuhashi
190
+ License:: Apache License, Version 2.0
191
+
data/Rakefile ADDED
@@ -0,0 +1,97 @@
1
+
2
+ require 'bundler'
3
+ Bundler::GemHelper.install_tasks
4
+
5
+ require 'fileutils'
6
+
7
+ require 'rspec/core'
8
+ require 'rspec/core/rake_task'
9
+ require 'yard'
10
+
11
+ RSpec::Core::RakeTask.new(:spec) do |t|
12
+ t.rspec_opts = ["-c", "-f documentation"]
13
+ t.rspec_opts << "-Ilib"
14
+ t.pattern = 'spec/**/*_spec.rb'
15
+ t.verbose = true
16
+ end
17
+
18
+ task :spec => :compile
19
+
20
+ desc 'Run RSpec code examples and measure coverage'
21
+ task :coverage do |t|
22
+ ENV['SIMPLE_COV'] = '1'
23
+ Rake::Task["spec"].invoke
24
+ end
25
+
26
+ desc 'Generate YARD document'
27
+ YARD::Rake::YardocTask.new(:doc) do |t|
28
+ t.files = ['lib/cbor/version.rb','doclib/**/*.rb']
29
+ t.options = []
30
+ t.options << '--debug' << '--verbose' if $trace
31
+ end
32
+
33
+ spec = eval File.read("cbor.gemspec")
34
+
35
+ if RUBY_PLATFORM =~ /java/
36
+ require 'rake/javaextensiontask'
37
+
38
+ Rake::JavaExtensionTask.new('cbor', spec) do |ext|
39
+ ext.ext_dir = 'ext/java'
40
+ #jruby_home = RbConfig::CONFIG['prefix']
41
+ #jars = ["#{jruby_home}/lib/jruby.jar"] + FileList['lib/*.jar']
42
+ #ext.classpath = jars.map { |x| File.expand_path x }.join ':'
43
+ end
44
+
45
+ else
46
+ require 'rake/extensiontask'
47
+
48
+ Rake::ExtensionTask.new('cbor', spec) do |ext|
49
+ ext.cross_compile = true
50
+ ext.lib_dir = File.join(*['lib', 'cbor', ENV['FAT_DIR']].compact)
51
+ #ext.cross_platform = 'i386-mswin32'
52
+ end
53
+ end
54
+
55
+ CLEAN.include('lib/cbor/*.jar')
56
+ CLEAN.include('lib/cbor/cbor.*')
57
+
58
+ task :default => :build
59
+
60
+
61
+ ###
62
+ ## Cross compile memo
63
+ ##
64
+ ## Ubuntu Ubuntu 10.04.1 LTS
65
+ ##
66
+ #
67
+ ### install mingw32 cross compiler with w64 support
68
+ # sudo apt-get install gcc-mingw32
69
+ # sudo apt-get install mingw-w64
70
+ #
71
+ ### install rbenv
72
+ # git clone git://github.com/sstephenson/rbenv.git ~/.rbenv
73
+ # echo 'export PATH="$HOME/.rbenv/bin:$PATH"' >> ~/.bash_profile
74
+ # echo 'eval "$(rbenv init -)"' >> ~/.bash_profile
75
+ # exec $SHELL -l
76
+ #
77
+ ### install cross-compiled ruby 2.0.0
78
+ # rbenv install 2.0.0-p0
79
+ # gem install rake-compiler
80
+ # rake-compiler cross-ruby VERSION=2.0.0-p0
81
+ #
82
+ ### install cross-compiled ruby 1.9.3
83
+ # rbenv install 1.9.3-p327
84
+ # gem install rake-compiler
85
+ # rake-compiler cross-ruby VERSION=1.9.3-p327
86
+ #
87
+ ### install cross-compiled ruby 1.8.7
88
+ # rbenv install 1.8.7-p371
89
+ # gem install rake-compiler
90
+ # rake-compiler cross-ruby VERSION=1.8.7-p371
91
+ #
92
+ ### build gem
93
+ # rbenv shell 1.8.7-p371
94
+ # gem install bundler && bundle
95
+ # rake cross native gem RUBY_CC_VERSION=1.8.7:1.9.3:2.0.0
96
+ #
97
+