msgpack 1.4.2 → 1.7.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (95) hide show
  1. checksums.yaml +4 -4
  2. data/ChangeLog +85 -0
  3. data/README.md +52 -1
  4. data/ext/java/org/msgpack/jruby/Buffer.java +26 -19
  5. data/ext/java/org/msgpack/jruby/Decoder.java +29 -21
  6. data/ext/java/org/msgpack/jruby/Encoder.java +68 -30
  7. data/ext/java/org/msgpack/jruby/ExtensionRegistry.java +43 -64
  8. data/ext/java/org/msgpack/jruby/ExtensionValue.java +6 -9
  9. data/ext/java/org/msgpack/jruby/Factory.java +43 -42
  10. data/ext/java/org/msgpack/jruby/Packer.java +37 -40
  11. data/ext/java/org/msgpack/jruby/Unpacker.java +80 -73
  12. data/ext/msgpack/buffer.c +54 -74
  13. data/ext/msgpack/buffer.h +21 -18
  14. data/ext/msgpack/buffer_class.c +161 -52
  15. data/ext/msgpack/buffer_class.h +1 -0
  16. data/ext/msgpack/compat.h +0 -99
  17. data/ext/msgpack/extconf.rb +25 -46
  18. data/ext/msgpack/factory_class.c +143 -87
  19. data/ext/msgpack/packer.c +66 -43
  20. data/ext/msgpack/packer.h +25 -20
  21. data/ext/msgpack/packer_class.c +102 -130
  22. data/ext/msgpack/packer_class.h +11 -0
  23. data/ext/msgpack/packer_ext_registry.c +35 -40
  24. data/ext/msgpack/packer_ext_registry.h +41 -38
  25. data/ext/msgpack/rbinit.c +1 -1
  26. data/ext/msgpack/rmem.c +3 -4
  27. data/ext/msgpack/sysdep.h +5 -2
  28. data/ext/msgpack/unpacker.c +126 -108
  29. data/ext/msgpack/unpacker.h +16 -13
  30. data/ext/msgpack/unpacker_class.c +86 -126
  31. data/ext/msgpack/unpacker_class.h +11 -0
  32. data/ext/msgpack/unpacker_ext_registry.c +40 -28
  33. data/ext/msgpack/unpacker_ext_registry.h +21 -18
  34. data/lib/msgpack/bigint.rb +69 -0
  35. data/lib/msgpack/buffer.rb +9 -0
  36. data/lib/msgpack/factory.rb +140 -10
  37. data/lib/msgpack/packer.rb +10 -1
  38. data/lib/msgpack/symbol.rb +21 -4
  39. data/lib/msgpack/time.rb +1 -1
  40. data/lib/msgpack/unpacker.rb +14 -1
  41. data/lib/msgpack/version.rb +1 -1
  42. data/lib/msgpack.rb +6 -7
  43. data/msgpack.gemspec +8 -5
  44. metadata +37 -82
  45. data/.gitignore +0 -23
  46. data/.rubocop.yml +0 -36
  47. data/.travis.yml +0 -39
  48. data/Gemfile +0 -9
  49. data/Rakefile +0 -71
  50. data/appveyor.yml +0 -18
  51. data/bench/pack.rb +0 -23
  52. data/bench/pack_log.rb +0 -33
  53. data/bench/pack_log_long.rb +0 -65
  54. data/bench/pack_symbols.rb +0 -28
  55. data/bench/run.sh +0 -14
  56. data/bench/run_long.sh +0 -35
  57. data/bench/run_symbols.sh +0 -26
  58. data/bench/unpack.rb +0 -21
  59. data/bench/unpack_log.rb +0 -34
  60. data/bench/unpack_log_long.rb +0 -67
  61. data/doclib/msgpack/buffer.rb +0 -193
  62. data/doclib/msgpack/core_ext.rb +0 -101
  63. data/doclib/msgpack/error.rb +0 -19
  64. data/doclib/msgpack/extension_value.rb +0 -9
  65. data/doclib/msgpack/factory.rb +0 -101
  66. data/doclib/msgpack/packer.rb +0 -208
  67. data/doclib/msgpack/time.rb +0 -22
  68. data/doclib/msgpack/timestamp.rb +0 -44
  69. data/doclib/msgpack/unpacker.rb +0 -183
  70. data/doclib/msgpack.rb +0 -87
  71. data/msgpack.org.md +0 -46
  72. data/spec/cases.json +0 -1
  73. data/spec/cases.msg +0 -0
  74. data/spec/cases_compact.msg +0 -0
  75. data/spec/cases_spec.rb +0 -39
  76. data/spec/cruby/buffer_io_spec.rb +0 -255
  77. data/spec/cruby/buffer_packer.rb +0 -29
  78. data/spec/cruby/buffer_spec.rb +0 -575
  79. data/spec/cruby/buffer_unpacker.rb +0 -19
  80. data/spec/cruby/unpacker_spec.rb +0 -70
  81. data/spec/ext_value_spec.rb +0 -99
  82. data/spec/exttypes.rb +0 -51
  83. data/spec/factory_spec.rb +0 -367
  84. data/spec/format_spec.rb +0 -301
  85. data/spec/jruby/benchmarks/shootout_bm.rb +0 -73
  86. data/spec/jruby/benchmarks/symbolize_keys_bm.rb +0 -25
  87. data/spec/jruby/unpacker_spec.rb +0 -186
  88. data/spec/msgpack_spec.rb +0 -214
  89. data/spec/pack_spec.rb +0 -61
  90. data/spec/packer_spec.rb +0 -557
  91. data/spec/random_compat.rb +0 -24
  92. data/spec/spec_helper.rb +0 -55
  93. data/spec/timestamp_spec.rb +0 -121
  94. data/spec/unpack_spec.rb +0 -57
  95. data/spec/unpacker_spec.rb +0 -819
data/.travis.yml DELETED
@@ -1,39 +0,0 @@
1
- language: ruby
2
-
3
- branches:
4
- only:
5
- - master
6
-
7
- gemfile:
8
- - Gemfile
9
-
10
- before_install:
11
- # This is only for Ruby 2.5.0, Bundler 1.16.1 and rubygems 2.7.3
12
- # See https://github.com/travis-ci/travis-ci/issues/8969
13
- - "[ \"x2.7.3\" = \"x\"$(gem --version) ] && gem update --system --no-document || echo \"no need to update rubygem\""
14
-
15
- # http://rubies.travis-ci.org/
16
- matrix:
17
- include:
18
- - rvm: 2.4.5
19
- os: linux
20
- - rvm: 2.5.8
21
- os: linux
22
- - rvm: 2.6.6
23
- os: linux
24
- - rvm: 2.6.6
25
- os: osx
26
- - rvm: 2.7.1
27
- os: linux
28
- - rvm: ruby-head
29
- os: linux
30
- - rvm: jruby-head
31
- os: linux
32
- - rvm: jruby-19mode
33
- os: linux
34
- allow_failures:
35
- - rvm: 2.6.1
36
- os: osx
37
- - rvm: ruby-head
38
- - rvm: jruby-head
39
- - rvm: jruby-19mode
data/Gemfile DELETED
@@ -1,9 +0,0 @@
1
- source 'https://rubygems.org/'
2
-
3
- gemspec
4
-
5
- ## enable this line to run benchmarks
6
- # gem "viiite"
7
-
8
- gem "rubocop", "~> 0.82.0"
9
- gem "simplecov"
data/Rakefile DELETED
@@ -1,71 +0,0 @@
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
- task :spec => :compile
12
-
13
- desc 'Run RSpec code examples and measure coverage'
14
- task :coverage do |t|
15
- ENV['SIMPLE_COV'] = '1'
16
- Rake::Task["spec"].invoke
17
- end
18
-
19
- desc 'Generate YARD document'
20
- YARD::Rake::YardocTask.new(:doc) do |t|
21
- t.files = ['lib/msgpack/version.rb','doclib/**/*.rb']
22
- t.options = []
23
- t.options << '--debug' << '--verbose' if $trace
24
- end
25
-
26
- spec = eval File.read("msgpack.gemspec")
27
-
28
- if RUBY_PLATFORM =~ /java/
29
- require 'rake/javaextensiontask'
30
-
31
- Rake::JavaExtensionTask.new('msgpack', spec) do |ext|
32
- ext.ext_dir = 'ext/java'
33
- jruby_home = RbConfig::CONFIG['prefix']
34
- jars = ["#{jruby_home}/lib/jruby.jar"]
35
- ext.classpath = jars.map { |x| File.expand_path(x) }.join(':')
36
- ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
37
- ext.source_version = '1.6'
38
- ext.target_version = '1.6'
39
- end
40
- else
41
- require 'rake/extensiontask'
42
-
43
- Rake::ExtensionTask.new('msgpack', spec) do |ext|
44
- ext.ext_dir = 'ext/msgpack'
45
- ext.cross_compile = true
46
- ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact)
47
- # cross_platform names are of MRI's platform name
48
- ext.cross_platform = ['x86-mingw32', 'x64-mingw32']
49
- end
50
- end
51
-
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
62
- end
63
-
64
- namespace :build do
65
- desc 'Build gem for JRuby after cleaning'
66
- task :java => [:clean, :spec, :build]
67
- end
68
-
69
- CLEAN.include('lib/msgpack/msgpack.*')
70
-
71
- task :default => [:spec, :build, :doc]
data/appveyor.yml DELETED
@@ -1,18 +0,0 @@
1
- ---
2
- install:
3
- - SET PATH=C:\Ruby%ruby_version%\bin;%PATH%
4
- - ruby --version
5
- - gem --version
6
- - bundle install
7
- build: off
8
- test_script:
9
- - bundle exec rake -rdevkit
10
-
11
- environment:
12
- matrix:
13
- - ruby_version: "200"
14
- - ruby_version: "200-x64"
15
- - ruby_version: "21"
16
- - ruby_version: "21-x64"
17
- - ruby_version: "22"
18
- - ruby_version: "22-x64"
data/bench/pack.rb DELETED
@@ -1,23 +0,0 @@
1
- require 'viiite'
2
- require 'msgpack'
3
-
4
- data = { 'hello' => 'world', 'nested' => ['structure', {value: 42}] }
5
- data_sym = { hello: 'world', nested: ['structure', {value: 42}] }
6
-
7
- data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
8
-
9
- Viiite.bench do |b|
10
- b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
11
- b.report(:strings) do
12
- runs.times do
13
- MessagePack.pack(data)
14
- end
15
- end
16
-
17
- b.report(:symbols) do
18
- runs.times do
19
- MessagePack.pack(data_sym)
20
- end
21
- end
22
- end
23
- end
data/bench/pack_log.rb DELETED
@@ -1,33 +0,0 @@
1
- require 'viiite'
2
- require 'msgpack'
3
-
4
- data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
5
- data_structure = {
6
- 'remote_host' => '127.0.0.1',
7
- 'remote_user' => '-',
8
- 'date' => '10/Oct/2000:13:55:36 -0700',
9
- 'request' => 'GET /apache_pb.gif HTTP/1.0',
10
- 'method' => 'GET',
11
- 'path' => '/apache_pb.gif',
12
- 'protocol' => 'HTTP/1.0',
13
- 'status' => 200,
14
- 'bytes' => 2326,
15
- 'referer' => 'http://www.example.com/start.html',
16
- 'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
17
- }
18
-
19
- Viiite.bench do |b|
20
- b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
21
- b.report(:plain) do
22
- runs.times do
23
- MessagePack.pack(data_plain)
24
- end
25
- end
26
-
27
- b.report(:structure) do
28
- runs.times do
29
- MessagePack.pack(data_structure)
30
- end
31
- end
32
- end
33
- end
@@ -1,65 +0,0 @@
1
- # viiite report --regroup bench,threads bench/pack_log_long.rb
2
-
3
- require 'viiite'
4
- require 'msgpack'
5
-
6
- data_plain = { 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' }
7
- data_structure = {
8
- 'remote_host' => '127.0.0.1',
9
- 'remote_user' => '-',
10
- 'date' => '10/Oct/2000:13:55:36 -0700',
11
- 'request' => 'GET /apache_pb.gif HTTP/1.0',
12
- 'method' => 'GET',
13
- 'path' => '/apache_pb.gif',
14
- 'protocol' => 'HTTP/1.0',
15
- 'status' => 200,
16
- 'bytes' => 2326,
17
- 'referer' => 'http://www.example.com/start.html',
18
- 'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
19
- }
20
-
21
- seconds = 3600 # 1 hour
22
-
23
- Viiite.bench do |b|
24
- b.range_over([1, 2, 4, 8, 16], :threads) do |threads|
25
- b.report(:plain) do
26
- ths = []
27
- end_at = Time.now + seconds
28
- threads.times do
29
- t = Thread.new do
30
- packs = 0
31
- while Time.now < end_at
32
- 10000.times do
33
- MessagePack.pack(data_plain)
34
- end
35
- packs += 10000
36
- end
37
- packs
38
- end
39
- ths.push t
40
- end
41
- sum = ths.reduce(0){|r,t| r + t.value }
42
- puts "MessagePack.pack, plain, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
43
- end
44
-
45
- b.report(:structure) do
46
- ths = []
47
- end_at = Time.now + seconds
48
- threads.times do
49
- t = Thread.new do
50
- packs = 0
51
- while Time.now < end_at
52
- 10000.times do
53
- MessagePack.pack(data_structure)
54
- end
55
- packs += 10000
56
- end
57
- packs
58
- end
59
- ths.push t
60
- end
61
- sum = ths.reduce(0){|r,t| r + t.value }
62
- puts "MessagePack.pack, structured, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
63
- end
64
- end
65
- end
@@ -1,28 +0,0 @@
1
- require 'viiite'
2
- require 'msgpack'
3
-
4
- data = :symbol
5
-
6
- Viiite.bench do |b|
7
- b.variation_point :branch, `git rev-parse --abbrev-ref HEAD`
8
-
9
- b.range_over([:symbol, :none], :reg_type) do |reg_type|
10
- packer = MessagePack::Packer.new
11
- packer.register_type(0x00, Symbol, :to_msgpack_ext) if reg_type == :symbol
12
-
13
- b.range_over([100_000, 1_000_000, 10_000_000], :count) do |count|
14
- packer.clear
15
- b.report(:multi_run) do
16
- count.times do
17
- packer.pack(data)
18
- end
19
- end
20
-
21
- packer.clear
22
- items_data = [].fill(data, 0, count)
23
- b.report(:large_run) do
24
- packer.pack(items_data)
25
- end
26
- end
27
- end
28
- end
data/bench/run.sh DELETED
@@ -1,14 +0,0 @@
1
- #!/bin/sh
2
-
3
- # prerequisites
4
- # $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
5
- # $ rake install
6
-
7
- echo "pack"
8
- viiite report --regroup bench,runs bench/pack.rb
9
- echo "unpack"
10
- viiite report --regroup bench,runs bench/unpack.rb
11
- echo "pack log"
12
- viiite report --regroup bench,runs bench/pack_log.rb
13
- echo "unpack log"
14
- viiite report --regroup bench,runs bench/unpack_log.rb
data/bench/run_long.sh DELETED
@@ -1,35 +0,0 @@
1
- #!/bin/sh
2
-
3
- # prerequisites
4
- # $ sudo apt-get install sysstat
5
- # $ rbenv shell 2.2.1 (or jruby-x.x.x or ...)
6
- # $ rake install
7
-
8
- # 60 * 600 : 60*60 * 5[threads] * 2[bench]
9
-
10
- ruby -v
11
-
12
- echo "pack log long"
13
- viiite report --regroup bench,threads bench/pack_log_long.rb &
14
- sar -o pack_log_long.sar -r 60 600 > /dev/null 2>&1 &
15
-
16
- declare -i i=0
17
- while [ $i -lt 600 ]; do
18
- ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
19
- i=i+1
20
- sleep 60
21
- done
22
-
23
- sleep 120 # cool down
24
-
25
- echo "unpack log long"
26
- viiite report --regroup bench,threads bench/unpack_log_long.rb &
27
- sar -o unpack_log_long.sar -r 60 600 > /dev/null 2>&1 &
28
-
29
- i=0
30
- while [ $i -lt 600 ]; do
31
- ps auxww | grep ruby | grep -v grep | awk '{print $5,$6;}' >> pack_log_long.mem.txt
32
- i=i+1
33
- sleep 60
34
- done
35
-
data/bench/run_symbols.sh DELETED
@@ -1,26 +0,0 @@
1
- #!/bin/sh
2
-
3
- # so master and this branch have the benchmark file in any case
4
- cp bench/pack_symbols.rb bench/pack_symbols_tmp.rb
5
-
6
- benchmark=""
7
- current_branch=`git rev-parse --abbrev-ref HEAD`
8
-
9
- for branch in master $current_branch; do
10
- echo "Testing branch $branch"
11
- git checkout $branch
12
-
13
- echo "Installing gem..."
14
- rake install
15
-
16
- echo "Running benchmark..."
17
- if [ "$benchmark" ]; then
18
- benchmark+=$'\n'
19
- fi
20
- benchmark+=$(viiite run bench/pack_symbols_tmp.rb)
21
- echo
22
- done
23
-
24
- rm bench/pack_symbols_tmp.rb
25
-
26
- echo "$benchmark" | viiite report --regroup bench,reg_type,count,branch
data/bench/unpack.rb DELETED
@@ -1,21 +0,0 @@
1
- require 'viiite'
2
- require 'msgpack'
3
-
4
- data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}])
5
-
6
- Viiite.bench do |b|
7
- b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
8
- b.report(:strings) do
9
- runs.times do
10
- MessagePack.unpack(data)
11
- end
12
- end
13
-
14
- b.report(:symbols) do
15
- options = {:symbolize_keys => true}
16
- runs.times do
17
- MessagePack.unpack(data, options)
18
- end
19
- end
20
- end
21
- end
data/bench/unpack_log.rb DELETED
@@ -1,34 +0,0 @@
1
- require 'viiite'
2
- require 'msgpack'
3
-
4
- data_plain = MessagePack.pack({ 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"' })
5
-
6
- data_structure = MessagePack.pack({
7
- 'remote_host' => '127.0.0.1',
8
- 'remote_user' => '-',
9
- 'date' => '10/Oct/2000:13:55:36 -0700',
10
- 'request' => 'GET /apache_pb.gif HTTP/1.0',
11
- 'method' => 'GET',
12
- 'path' => '/apache_pb.gif',
13
- 'protocol' => 'HTTP/1.0',
14
- 'status' => 200,
15
- 'bytes' => 2326,
16
- 'referer' => 'http://www.example.com/start.html',
17
- 'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
18
- })
19
-
20
- Viiite.bench do |b|
21
- b.range_over([10_000, 100_000, 1000_000], :runs) do |runs|
22
- b.report(:plain) do
23
- runs.times do
24
- MessagePack.unpack(data_plain)
25
- end
26
- end
27
-
28
- b.report(:structure) do
29
- runs.times do
30
- MessagePack.unpack(data_structure)
31
- end
32
- end
33
- end
34
- end
@@ -1,67 +0,0 @@
1
- # viiite report --regroup bench,threads bench/pack_log_long.rb
2
-
3
- require 'viiite'
4
- require 'msgpack'
5
-
6
- data_plain = MessagePack.pack({
7
- 'message' => '127.0.0.1 - - [10/Oct/2000:13:55:36 -0700] "GET /apache_pb.gif HTTP/1.0" 200 2326 "http://www.example.com/start.html" "Mozilla/4.08 [en] (Win98; I ;Nav)"'
8
- })
9
- data_structure = MessagePack.pack({
10
- 'remote_host' => '127.0.0.1',
11
- 'remote_user' => '-',
12
- 'date' => '10/Oct/2000:13:55:36 -0700',
13
- 'request' => 'GET /apache_pb.gif HTTP/1.0',
14
- 'method' => 'GET',
15
- 'path' => '/apache_pb.gif',
16
- 'protocol' => 'HTTP/1.0',
17
- 'status' => 200,
18
- 'bytes' => 2326,
19
- 'referer' => 'http://www.example.com/start.html',
20
- 'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)',
21
- })
22
-
23
- seconds = 3600 # 1 hour
24
-
25
- Viiite.bench do |b|
26
- b.range_over([1, 2, 4, 8, 16], :threads) do |threads|
27
- b.report(:plain) do
28
- ths = []
29
- end_at = Time.now + seconds
30
- threads.times do
31
- t = Thread.new do
32
- packs = 0
33
- while Time.now < end_at
34
- 10000.times do
35
- MessagePack.unpack(data_plain)
36
- end
37
- packs += 10000
38
- end
39
- packs
40
- end
41
- ths.push t
42
- end
43
- sum = ths.reduce(0){|r,t| r + t.value }
44
- puts "MessagePack.unpack, plain, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
45
- end
46
-
47
- b.report(:structure) do
48
- ths = []
49
- end_at = Time.now + seconds
50
- threads.times do
51
- t = Thread.new do
52
- packs = 0
53
- while Time.now < end_at
54
- 10000.times do
55
- MessagePack.unpack(data_structure)
56
- end
57
- packs += 10000
58
- end
59
- packs
60
- end
61
- ths.push t
62
- end
63
- sum = ths.reduce(0){|r,t| r + t.value }
64
- puts "MessagePack.unpack, structured, #{threads} threads: #{sum} times, #{sum / seconds} times/second."
65
- end
66
- end
67
- end
@@ -1,193 +0,0 @@
1
- module MessagePack
2
-
3
- class Buffer
4
- #
5
- # Creates a MessagePack::Buffer instance.
6
- #
7
- # @overload initialize(options={})
8
- # @param options [Hash]
9
- #
10
- # @overload initialize(io, options={})
11
- # @param io [IO]
12
- # @param options [Hash]
13
- # This buffer writes written data into the IO when it is filled.
14
- # This buffer reads data from the IO when it is empty.
15
- #
16
- # _io_ must respond to readpartial(length, [,string]) or read(string) method and
17
- # write(string) or append(string) method.
18
- #
19
- # Supported options:
20
- #
21
- # * *:io_buffer_size* buffer size to read data from the internal IO. (default: 32768)
22
- # * *:read_reference_threshold* the threshold size to enable zero-copy deserialize optimization. Read strings longer than this threshold will refer the original string instead of copying it. (default: 256) (supported in MRI only)
23
- # * *:write_reference_threshold* the threshold size to enable zero-copy serialize optimization. The buffer refers written strings longer than this threshold instead of copying it. (default: 524288) (supported in MRI only)
24
- #
25
- def initialize(*args)
26
- end
27
-
28
- #
29
- # Makes the buffer empty
30
- #
31
- # @return nil
32
- #
33
- def clear
34
- end
35
-
36
- #
37
- # Returns byte size of the buffer.
38
- #
39
- # @return nil
40
- #
41
- def size
42
- end
43
-
44
- #
45
- # Returns _true_ if the buffer is empty.
46
- # This method is slightly faster than _size_.
47
- #
48
- # @return [Boolean]
49
- #
50
- def empty?
51
- end
52
-
53
- #
54
- # Appends the given data to the buffer.
55
- #
56
- # @param data [String]
57
- # @return [Integer] byte size written
58
- #
59
- def write(data)
60
- end
61
-
62
- #
63
- # Appends the given data to the buffer.
64
- #
65
- # @param data [String]
66
- # @return [Buffer] self
67
- #
68
- def <<(data)
69
- end
70
-
71
- #
72
- # Consumes _n_ bytes from the head of the buffer and returns consumed data.
73
- # If the size of the buffer is less than _n_, it reads all of data in the buffer.
74
- #
75
- # If _n_ is 0, it does nothing and returns an empty string.
76
- # If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
77
- #
78
- # @overload read
79
- #
80
- # @overload read(n)
81
- # @param n [Integer] bytes to read
82
- #
83
- # @overload read(n, buffer)
84
- # @param n [Integer] bytes to read
85
- # @param buffer [String] buffer to read into
86
- #
87
- # @return [String]
88
- #
89
- def read(n)
90
- end
91
-
92
- #
93
- # Consumes _n_ bytes from the head of the buffer and returns consumed data.
94
- # If the size of the buffer is less than _n_, it does nothing and raises EOFError.
95
- #
96
- # If _n_ is 0, it does nothing and returns an empty string.
97
- # If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data.
98
- #
99
- # @overload read_all
100
- #
101
- # @overload read_all(n)
102
- # @param n [Integer] bytes to read
103
- #
104
- # @overload read_all(n, buffer)
105
- # @param n [Integer] bytes to read
106
- # @param buffer [String] buffer to read into
107
- #
108
- # @return [String]
109
- #
110
- def read_all(n, buffer=nil)
111
- end
112
-
113
- #
114
- # Consumes _n_ bytes from the head of the buffer.
115
- # If the size of the buffer is less than _n_, it skips all of data in the buffer and returns integer less than _n_.
116
- #
117
- # If _n_ is 0, it does nothing and returns _0_.
118
- #
119
- # @param n [Integer] byte size to skip
120
- # @return [Integer] byte size actually skipped
121
- #
122
- def skip(n)
123
- end
124
-
125
- #
126
- # Consumes _n_ bytes from the head of the buffer.
127
- # If the size of the buffer is less than _n_, it does nothing and raises EOFError.
128
- # If _n_ is 0, it does nothing.
129
- #
130
- # @param n [Integer] byte size to skip
131
- # @return [Buffer] self
132
- #
133
- def skip_all(n)
134
- end
135
-
136
- #
137
- # Returns all data in the buffer as a string.
138
- # Destructive update to the returned string does NOT effect the buffer.
139
- #
140
- # @return [String]
141
- #
142
- def to_str
143
- end
144
-
145
- #
146
- # Returns content of the buffer as an array of strings.
147
- #
148
- # This method is sometimes faster than to_s because the internal
149
- # structure of the buffer is a queue of buffer chunks.
150
- #
151
- # @return [Array] array of strings
152
- #
153
- def to_a
154
- end
155
-
156
- #
157
- # Internal io
158
- #
159
- # @return IO
160
- #
161
- attr_reader :io
162
-
163
- #
164
- # Flushes data in the internal buffer to the internal IO.
165
- # If internal IO is not set, it does nothing.
166
- #
167
- # @return [Buffer] self
168
- #
169
- def flush
170
- end
171
-
172
- #
173
- # Closes internal IO if its set.
174
- # If internal IO is not set, it does nothing
175
- #
176
- # @return nil
177
- #
178
- def close
179
- end
180
-
181
- #
182
- # Writes all of data in the internal buffer into the given IO.
183
- # This method consumes and removes data from the internal buffer.
184
- # _io_ must respond to write(data) method.
185
- #
186
- # @param io [IO]
187
- # @return [Integer] byte size of written data
188
- #
189
- def write_to(io)
190
- end
191
- end
192
-
193
- end