diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml deleted file mode 100644 index 3ef852b7..00000000 --- a/.github/workflows/ci.yaml +++ /dev/null @@ -1,84 +0,0 @@ -name: ci - -on: - pull_request: - branches: '*' - push: - branches: - - master - - main - - 'release-*' - -jobs: - mri: - strategy: - fail-fast: false - matrix: - os: [ubuntu-latest] - ruby: ['2.5', '2.6', '2.7', '3.0', '3.1', '3.2', '3.3', '3.4'] - include: - - os: macos-13 - ruby: '2.5' - - os: macos-latest - ruby: '3.2' - - os: windows-latest - ruby: '2.5' - - os: windows-latest - ruby: '3.2' - - runs-on: ${{ matrix.os }} - steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true # 'bundle install' and cache - - run: bundle exec rake - env: - MSGPACK_DEBUG: "true" - - valgrind: - runs-on: ubuntu-latest - steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: '3.1' - bundler-cache: true # 'bundle install' and cache - - run: sudo apt-get install -y valgrind - - run: bundle exec rake spec:valgrind - - other: - strategy: - fail-fast: false - matrix: - os: [ubuntu] - ruby: ['jruby-9.3', 'jruby-9.4', 'truffleruby'] - runs-on: ${{ matrix.os }}-latest - steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true # 'bundle install' and cache - - run: bundle exec rake spec - env: - MSGPACK_DEBUG: "true" - - head-versions: - continue-on-error: true - strategy: - fail-fast: false - matrix: - os: [ubuntu] - ruby: ['ruby-head', 'jruby-head'] - runs-on: ${{ matrix.os }}-latest - steps: - - uses: actions/checkout@v4 - - uses: ruby/setup-ruby@v1 - with: - ruby-version: ${{ matrix.ruby }} - bundler-cache: true # 'bundle install' and cache - - run: bundle exec rake spec || echo "failed, but ignore it" - env: - MSGPACK_DEBUG: "true" diff --git a/.gitignore b/.gitignore index 7becb09d..7bd7bf26 100644 --- a/.gitignore +++ b/.gitignore @@ -1,23 +1,13 @@ -*.o -*.so -*.bundle -*.gem -*.class -*.jar -doc -.yardoc -.bundle Gemfile* -pkg -test/debug.log +.bundle +.rbenv-version +.DS_Store *~ -*.swp -/rdoc -tmp -.classpath -.project -.settings -/nbproject/private/ -coverage/ -.idea/ -.ruby-version +/msgpack-ruby +/vendor +/.yardoc +/doc +/tmp +/pkg +/lib + diff --git a/.rubocop.yml b/.rubocop.yml deleted file mode 100644 index d2c978e2..00000000 --- a/.rubocop.yml +++ /dev/null @@ -1,36 +0,0 @@ -# This configuration was generated by `rubocop --auto-gen-config` -# on 2015-03-09 17:42:55 +0100 using RuboCop version 0.29.1. -# The point is for the user to remove these configuration records -# one by one as the offenses are removed from the code base. -# Note that changes in the inspected code, or installation of new -# versions of RuboCop, may require this file to be generated again. - -AllCops: - TargetRubyVersion: 2.5 - -# Offense count: 3 -Lint/AmbiguousOperator: - Enabled: false - -# Offense count: 1 -# Configuration parameters: AllowSafeAssignment. -Lint/AssignmentInCondition: - Enabled: false - -# Offense count: 1 -Security/Eval: - Enabled: false - -# Offense count: 3 -# Cop supports --auto-correct. -Lint/UnusedBlockArgument: - Enabled: false - -# Offense count: 35 -# Cop supports --auto-correct. -Lint/UnusedMethodArgument: - Enabled: false - -# Offense count: 128 -Lint/Void: - Enabled: false diff --git a/Array.html b/Array.html new file mode 100644 index 00000000..94ae8881 --- /dev/null +++ b/Array.html @@ -0,0 +1,219 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: Array + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "Array"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (A)</a> » + + + <span class="title">Array</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: Array + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Array</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +78 +79</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 78</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/Bignum.html b/Bignum.html new file mode 100644 index 00000000..5b286ec9 --- /dev/null +++ b/Bignum.html @@ -0,0 +1,222 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: Bignum + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "Bignum"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (B)</a> » + + + <span class="title">Bignum</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: Bignum + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Integer</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Integer</li> + + <li class="next">Bignum</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +48 +49</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 48</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/CNAME b/CNAME new file mode 100644 index 00000000..962ebf1a --- /dev/null +++ b/CNAME @@ -0,0 +1 @@ +ruby.msgpack.org diff --git a/ChangeLog b/ChangeLog deleted file mode 100644 index 5f173f2a..00000000 --- a/ChangeLog +++ /dev/null @@ -1,368 +0,0 @@ -2025-02-06 1.8.0 - -* Numerous small optimizations. -* Added `key_cache` option to `Unpacker`. - -2024-11-11 1.7.5 - -* Rerelease 1.7.4 with fixed java package. - -2024-11-11 1.7.4 - -* Fixed a potental memory leak when recursive unpacker raise. - -2024-10-03 1.7.3 - -* Limit initial containers pre-allocation to `SHRT_MAX` (32k) entries. - -2023-07-18 1.7.2: - -* Fix a potential GC bug when packing data using recursive extensions and buffers containing over 512KkiB of data (See #341). -* Fix a regression where feeding an empty string to an Unpacker would be considered like the end of the buffer. - -2023-05-19 1.7.1: - -* Fix JRuby 9.4 compatibility. -* Fix compilation on older compilers (gcc 4.x). -* Fix an infinite recursion issue when registering a Symbol type with a `nil` packer. - -2023-03-29 1.7.0: - -* Fix a possible double-free issue when GC triggers inside `_msgpack_rmem_alloc2`. -* `Unpacker#feed` now always directly read in provided strings instead of copying content in its buffer. -* `Unpacker#feed` is now an alias of `Unpacker#feed_reference`. -* Implement `Factory::Pool#unpacker` and `Factory::Pool#packer` to allow for more precise serialization. -* Require Ruby 2.5+. - -2023-03-03 1.6.1: - -* Undefine `#clone` and `#dup` on `MessagePack::Buffer`, `MessagePack::Packer` and `MessagePack::Unpacker`. - These methods were never intended, and using them could cause leaks or crashes or worse. -* Fix a possible GC crash when GC trigger inside `MessagePack::Buffer.new` (#314). - -2022-09-30 1.6.0: - -* Fix a potential use-after-free bug in Buffer_free when accessing a packer or unpacker buffer. -* `old-style-definition` compilation warnings. -* Restore zero-copy buffer feed when provided a Ruby string. This was accidentally broken in 1.5.4. -* Provide implementations for `ObjectSpace.memsize`. Message pack objects now properly report their size to Ruby. -* Fix an endianess bug on Windows platform. - -2022-08-23 1.5.6: - -* No actual code change, just re-release the `java` version properly. - -2022-08-22 1.5.5: - -* Fix a segfault when GC triggers inside a recursive extension. - -2022-07-25 1.5.4: - -* Fix a segfault when deserializing empty symbol (`:""`). -* Improve compilation flags to not strip debug symbols. - -2022-05-30 version 1.5.3: - -* Fix deduplication of empty strings when using the `freeze: true` option. -* Use `rb_hash_new_capa` when available (Ruby 3.2) for improved performance when parsing large hashes. - -2022-05-27 version 1.5.2: - -* Fix bug about unpacking ext type objects with the recursive option - -2022-04-07 version 1.5.1: - -* Fix bug about packing/unpacking ext type objects with the recursive option - -2022-04-06 version 1.5.0: - -* Add recursive option on Factory#register_type to operate Packer/Unpacker manually -* Add oversized_integer_extension option on Factory#register_type to pack/unpack bigint using ext types -* Add Factory#pool method and Factory::Pool class to provide pooled Packer and Unpacker instances - -2022-02-15 version 1.4.5: - -* Fix to create UTF-8 Symbol keys when symbolize_keys: true -* Fix to assume Symbols as US-ASCII or UTF-8 -* Optimize Packer/Unpacker initialization -* Optimize extension class lookup -* Rename Packer#clear as Packer#reset (#clear is still available as an alias) - -2022-01-22 version 1.4.4: - -* Specify the build option --platform=8 for older Java platforms - -2022-01-20 version 1.4.3: - -* Optimize serialization/deserialization of Symbols -* Support registering ext types for objects of subclasses of primitive types (like Hash) -* Add optimized_symbols_parsing option to Factory#register_type on MRI implementation -* Optimize to deduplicate Hash keys on JRuby -* Support JRuby 9.3 (and drop 9.1) - -2021-02-01 version 1.4.2: - -* Add the required Ruby version (>= 2.4) to avoid compilation errors on older Ruby runtimes -* Drop the support of old Ruby versions explicitly (1.8, 1.9, 2.0, 2.1, 2.2, 2.3) - -2021-01-27 version 1.4.1: - -* Bugfix about the wrong string encoding longer than 256 bytes (#200) - -2021-01-27 version 1.4.0: - -* Introduce the optimization to use frozen/deduped keys for map objects -* Stop releasing fat gem (pre-built binaries) for mswin32 arch environments - -2020-02-05 version 1.3.3: - -* Hotfix release for Windows environments: 1.3.2 missed including binaries - -2020-02-04 version 1.3.2: - -* Add Ruby 2.7.0 binary in gem releases for Windows - -2019-08-05 version 1.3.1: - -* Fix timestamp ext type bug about timestamps with seconds larger than 32bit int (after 2106-02-07 06:28:16 UTC) - -2019-06-20 verison 1.3.0: - -* Add timestamp ext type (id:-1) support - -2019-04-19 version 1.2.10: - -* Optimze MessagePack.unpack not to copy source string - -2019-03-13 version 1.2.9: - -* Hotfix release only for JRuby: 1.2.8-java was built incorrectly - -2019-03-11 version 1.2.8: - -* Fix a regression that MessagePack#unpack raises error if IO is assigned as the (only) argument -* Improve compatibility that MessagePack#pack returns nil if IO is assigned as 2nd argument - -2019-03-01 version 1.2.7: - -* Add Packer#write_bin and Packer#write_bin_header methods - -2019-01-08 verison 1.2.6: - -* Update Ruby version 2.6 dependency (especially for Windows environment) -* (version 1.2.4 and 1.2.5 were also releases for updated Ruby versions) - -2018-03-02 version 1.2.3: - -* Add Ruby 2.5.0 binary in gem releases for Windows - -2018-01-11 version 1.2.2: - -* Fix bug to occur SEGV occasionally (depends on GC timing) when exttype is used -* Fix bug to encode an ext type with wrong type id if superclass is also registered as ext type - -2017-12-08 version 1.2.1: - -* Hotfix release only for JRuby: 1.2.0-java was built in incorrect way - -2017-12-07 version 1.2.0: - -* Add MessagePack::Factory#dump and MessagePack::Factory#load as convenient methods - like MessagePack.dump and MessagePack.load -* Fix bug to accept MessagePack::Factory#register_type after #freeze - -2017-02-28 version 1.1.0: - -* Fix the extension type handling to accept modules in addition to classes - -2017-01-24 version 1.0.3: - -* Support Ruby 2.4 - -2016-10-17 version 1.0.2: - -* Bump version up to release newer version to fix broken gem release for JRuby - -2016-10-17 version 1.0.1: - -* Fix a bug to crash at packer when ext type is registered for superclass of packed object -* Fix JRuby implementation about inconsistent API of Unpacker constructor - -2016-07-08 version 1.0.0: - -* Fix to be able to pack Symbol with ext types -* Fix for MRI 2.4 (Integer unification) - -2016-05-10 version 0.7.6: - -* Fix bug to raise IndexOutOfBoundsException for Bignum value with small int in JRuby - -2016-04-06 version 0.7.5: - -* Improved support for i386/armel/armhf environments -* Fix bug for negative ext type id and some architectures (arm*) - -2016-01-08 version 0.7.4: - -* Improved compatibility of Packer between CRuby and JRuby about argument IO-ish object values. - -2016-01-07 version 0.7.3: - -* Add Packer#write_float32 method to pack floating point numbers into FLOAT of messagepack. - -2016-01-06 version 0.7.2: - -* Improved compatibility of Unpacker between CRuby and JRuby to accept stream-like object - by checking respond_to(:read) in addition to class check - -2015-11-20 version 0.7.1: - -* Fixed bug to pack/unpack ext type objects larger than 256bytes incorrectly. - -2015-10-24 version 0.7.0: - -* Add extension types support. -* Fix to share almost all test cases between CRuby and JRuby implementations. -* Fixed JRuby implementation to raise UnknownExtTypeError for unregistered ext type ids - instead to generate MessagePack::ExtensionValue instances. - (Specify `allow_unknown_ext: true` as unpacker option for v0.6.x behavior.) - -2015-07-22 version 0.6.2: - -* Fix release workflow: Ruby 2.1 and 2.2 are supported for Windows (2.0 is omitted) -* Fix to encode symbols along its encoding -* Fix segmentation fault in minor case - -2015-07-01 version 0.6.1: - -* Added :compatibility_mode option to Packer#initialize. Default is false. If it - is set to true, str8 format and bin format family will not be used. - -2015-05-26 version 0.6.0: - -* Added support for Binary types -* Fixed to encode/decode between Binary types and ASCII-8BIT Ruby String objects - -2015-05-21 version 0.5.12: - -* Added support for JRuby 9K. -* Added a benchmarking suite. -* Fixed a bug in the handling of options given to MessagePack.unpack in JRuby. - - -2015-02-04 version 0.5.11: - -* Fixed Encoding::CompatibilityError error when serializing a long string - longer than write_reference_threshold (5KB by default) and whose encoding - is not ASCII-8BIT. -* Fix read_(map|array)_header (@funny-falcon++). -* Internally, rename msgpack_unpacker_{init,reset,destroy} functions - so that we can load msgpack-c in the same process (@miihael++) - - -2015-01-09 version 0.5.10: - -* Merged msgpack-jruby by @iconara. JRuby can run `require 'msgpack'` to use - msgpack-jruby. - - -2014-10-05 version 0.5.9: - -* Fixed Unpacker#read_map_header and #read_array_header -* Added support for Symbol GC added since MRI 2.2.0 - - -2013-12-14 version 0.5.8: - -* Fixed compatibility with Ruby 2.1.0 -* Added :symbolize_keys option to MessagePack.load and Unpacker#initialize - - -2013-10-12 version 0.5.7: - -* Added deserialization support for the new MessagePack spec - - -2013-09-23 version 0.5.6: - -* Fixed "can't modify frozen String" exception in Unpacker with ruby 2.1.0-dev -* Getting work with Ruby v2.0 on Windows (Thank you @thegreendroid) -* Fixed EOFError handling in Unpacker - - -2013-05-12 version 0.5.5: - -* Fixed SEGV problem in to_msgpack -* Fixed a possible race condition in MessagePack.load when it loads data from IO -* mingw32 package includes binary for ruby-2.0.0 - - -2013-03-15 version 0.5.4: - -* Added missing MessagePack::Unpacker#reset method - - -2013-02-14 version 0.5.3: - -* Fixed segfault problem on Buffer#clear (reuse rmem internal fragment optimization) -* Fixed segfault problem on Buffer (rmem free code) - - -2013-02-07 version 0.5.2: - -* Fixed invalid pack/unpack on 32bit architecture such as Win32 -* Disable rmem on Rubinius because rmem is not thread safe - - -2012-12-23 version 0.5.1: - -* Fixed compile error with Rubinius 2.0.0-dev -* Optimized msgpack_packer_write_hash for Rubinius - - -2012-12-20 version 0.5.0: - -* Rewrote all code and improved performance significantly -* Added MessagePack::Buffer class -* Added MessagePack::Packer class -* Added Packer#buffer and Unpacker#buffer accessors which return MessagePack::Buffer -* Added Packer#write_{array,map}_header and Unpacker#read_{array,map}_header methods -* Added Packer#write_nil and Unpacker#skip_nil methods -* Added Packer#write -> #pack alias and Unpacker#read method -* Added exception classes - UnpackError, MalformedFormatError, StackError and TypeError -* Added MessagePack.dup -> .pack and MessagePack.load -> .unpack aliases -* Added Packer#empty?, #size and #clear methods -* Added Packer#write_to(io) method to flush serialized data to IO efficiently -* Added Unpacker#skip method to skip an object efficiently -* Removed obsoleted Unpacker#fill, #execute, #execute_limit, #finished? and #data methods -* Removed obsoleted Unapcker#stream and #stream= methods. Use unpacker.buffer.io instead - - -2012-05-05 version 0.4.7: - -* Fixed serialization of double values on ARM OABI architectures -* Fixed byteorder problem on big-endian platforms -* Don't use MRI internals in the Ruby extension for Rubinius -* Detect whether st.h is present and don't use RUBY_VM as the condition for - Rubinius - -2011-08-08 version 0.4.6: - -* Fixed compile error problem on Mac OS X Lion - -2011-05-09 version 0.4.5: - -* Improves compatibility with JRuby - -2010-11-28 version 0.4.4: - -* Adds Unpacker#feed_each method -* Improves compatibility with Rubinius -* Improves compatibility with ruby-1.8.5 -* Encodings of String instances to UTF-8 on Ruby 1.9 - -2010-06-29 version 0.4.3: - -* Adds MessagePack::VERSION constant -* Fixes SEGV problem caused by GC bug at MessagePack_Unpacker_mark - diff --git a/FalseClass.html b/FalseClass.html new file mode 100644 index 00000000..aecd67db --- /dev/null +++ b/FalseClass.html @@ -0,0 +1,219 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: FalseClass + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "FalseClass"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (F)</a> » + + + <span class="title">FalseClass</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: FalseClass + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">FalseClass</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +28 +29</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 28</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/Fixnum.html b/Fixnum.html new file mode 100644 index 00000000..b59919c2 --- /dev/null +++ b/Fixnum.html @@ -0,0 +1,222 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: Fixnum + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "Fixnum"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (F)</a> » + + + <span class="title">Fixnum</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: Fixnum + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Integer</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Integer</li> + + <li class="next">Fixnum</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +38 +39</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 38</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/Float.html b/Float.html new file mode 100644 index 00000000..5384cfa7 --- /dev/null +++ b/Float.html @@ -0,0 +1,222 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: Float + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "Float"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (F)</a> » + + + <span class="title">Float</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: Float + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Numeric</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Numeric</li> + + <li class="next">Float</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +58 +59</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 58</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/Gemfile b/Gemfile index 6e9dd4d3..463a3583 100644 --- a/Gemfile +++ b/Gemfile @@ -1,9 +1,7 @@ -source 'https://rubygems.org/' +source :rubygems -gemspec +gem 'rake', '~> 0.9.2' +gem 'rake-compiler', '~> 0.8.1' +gem 'rspec', '~> 2.11' +gem 'yard', '~> 0.8.2' -## enable this line to run benchmarks -# gem "viiite" - -gem "rubocop", "~> 0.82.0" -gem "simplecov" diff --git a/Hash.html b/Hash.html new file mode 100644 index 00000000..1af0aaa4 --- /dev/null +++ b/Hash.html @@ -0,0 +1,219 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: Hash + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "Hash"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (H)</a> » + + + <span class="title">Hash</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: Hash + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Hash</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +88 +89</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 88</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/LICENSE b/LICENSE deleted file mode 100644 index f433b1a5..00000000 --- a/LICENSE +++ /dev/null @@ -1,177 +0,0 @@ - - Apache License - Version 2.0, January 2004 - http://www.apache.org/licenses/ - - TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION - - 1. Definitions. - - "License" shall mean the terms and conditions for use, reproduction, - and distribution as defined by Sections 1 through 9 of this document. - - "Licensor" shall mean the copyright owner or entity authorized by - the copyright owner that is granting the License. - - "Legal Entity" shall mean the union of the acting entity and all - other entities that control, are controlled by, or are under common - control with that entity. For the purposes of this definition, - "control" means (i) the power, direct or indirect, to cause the - direction or management of such entity, whether by contract or - otherwise, or (ii) ownership of fifty percent (50%) or more of the - outstanding shares, or (iii) beneficial ownership of such entity. - - "You" (or "Your") shall mean an individual or Legal Entity - exercising permissions granted by this License. - - "Source" form shall mean the preferred form for making modifications, - including but not limited to software source code, documentation - source, and configuration files. - - "Object" form shall mean any form resulting from mechanical - transformation or translation of a Source form, including but - not limited to compiled object code, generated documentation, - and conversions to other media types. - - "Work" shall mean the work of authorship, whether in Source or - Object form, made available under the License, as indicated by a - copyright notice that is included in or attached to the work - (an example is provided in the Appendix below). - - "Derivative Works" shall mean any work, whether in Source or Object - form, that is based on (or derived from) the Work and for which the - editorial revisions, annotations, elaborations, or other modifications - represent, as a whole, an original work of authorship. For the purposes - of this License, Derivative Works shall not include works that remain - separable from, or merely link (or bind by name) to the interfaces of, - the Work and Derivative Works thereof. - - "Contribution" shall mean any work of authorship, including - the original version of the Work and any modifications or additions - to that Work or Derivative Works thereof, that is intentionally - submitted to Licensor for inclusion in the Work by the copyright owner - or by an individual or Legal Entity authorized to submit on behalf of - the copyright owner. For the purposes of this definition, "submitted" - means any form of electronic, verbal, or written communication sent - to the Licensor or its representatives, including but not limited to - communication on electronic mailing lists, source code control systems, - and issue tracking systems that are managed by, or on behalf of, the - Licensor for the purpose of discussing and improving the Work, but - excluding communication that is conspicuously marked or otherwise - designated in writing by the copyright owner as "Not a Contribution." - - "Contributor" shall mean Licensor and any individual or Legal Entity - on behalf of whom a Contribution has been received by Licensor and - subsequently incorporated within the Work. - - 2. Grant of Copyright License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - copyright license to reproduce, prepare Derivative Works of, - publicly display, publicly perform, sublicense, and distribute the - Work and such Derivative Works in Source or Object form. - - 3. Grant of Patent License. Subject to the terms and conditions of - this License, each Contributor hereby grants to You a perpetual, - worldwide, non-exclusive, no-charge, royalty-free, irrevocable - (except as stated in this section) patent license to make, have made, - use, offer to sell, sell, import, and otherwise transfer the Work, - where such license applies only to those patent claims licensable - by such Contributor that are necessarily infringed by their - Contribution(s) alone or by combination of their Contribution(s) - with the Work to which such Contribution(s) was submitted. If You - institute patent litigation against any entity (including a - cross-claim or counterclaim in a lawsuit) alleging that the Work - or a Contribution incorporated within the Work constitutes direct - or contributory patent infringement, then any patent licenses - granted to You under this License for that Work shall terminate - as of the date such litigation is filed. - - 4. Redistribution. You may reproduce and distribute copies of the - Work or Derivative Works thereof in any medium, with or without - modifications, and in Source or Object form, provided that You - meet the following conditions: - - (a) You must give any other recipients of the Work or - Derivative Works a copy of this License; and - - (b) You must cause any modified files to carry prominent notices - stating that You changed the files; and - - (c) You must retain, in the Source form of any Derivative Works - that You distribute, all copyright, patent, trademark, and - attribution notices from the Source form of the Work, - excluding those notices that do not pertain to any part of - the Derivative Works; and - - (d) If the Work includes a "NOTICE" text file as part of its - distribution, then any Derivative Works that You distribute must - include a readable copy of the attribution notices contained - within such NOTICE file, excluding those notices that do not - pertain to any part of the Derivative Works, in at least one - of the following places: within a NOTICE text file distributed - as part of the Derivative Works; within the Source form or - documentation, if provided along with the Derivative Works; or, - within a display generated by the Derivative Works, if and - wherever such third-party notices normally appear. The contents - of the NOTICE file are for informational purposes only and - do not modify the License. You may add Your own attribution - notices within Derivative Works that You distribute, alongside - or as an addendum to the NOTICE text from the Work, provided - that such additional attribution notices cannot be construed - as modifying the License. - - You may add Your own copyright statement to Your modifications and - may provide additional or different license terms and conditions - for use, reproduction, or distribution of Your modifications, or - for any such Derivative Works as a whole, provided Your use, - reproduction, and distribution of the Work otherwise complies with - the conditions stated in this License. - - 5. Submission of Contributions. Unless You explicitly state otherwise, - any Contribution intentionally submitted for inclusion in the Work - by You to the Licensor shall be under the terms and conditions of - this License, without any additional terms or conditions. - Notwithstanding the above, nothing herein shall supersede or modify - the terms of any separate license agreement you may have executed - with Licensor regarding such Contributions. - - 6. Trademarks. This License does not grant permission to use the trade - names, trademarks, service marks, or product names of the Licensor, - except as required for reasonable and customary use in describing the - origin of the Work and reproducing the content of the NOTICE file. - - 7. Disclaimer of Warranty. Unless required by applicable law or - agreed to in writing, Licensor provides the Work (and each - Contributor provides its Contributions) on an "AS IS" BASIS, - WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or - implied, including, without limitation, any warranties or conditions - of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A - PARTICULAR PURPOSE. You are solely responsible for determining the - appropriateness of using or redistributing the Work and assume any - risks associated with Your exercise of permissions under this License. - - 8. Limitation of Liability. In no event and under no legal theory, - whether in tort (including negligence), contract, or otherwise, - unless required by applicable law (such as deliberate and grossly - negligent acts) or agreed to in writing, shall any Contributor be - liable to You for damages, including any direct, indirect, special, - incidental, or consequential damages of any character arising as a - result of this License or out of the use or inability to use the - Work (including but not limited to damages for loss of goodwill, - work stoppage, computer failure or malfunction, or any and all - other commercial damages or losses), even if such Contributor - has been advised of the possibility of such damages. - - 9. Accepting Warranty or Additional Liability. While redistributing - the Work or Derivative Works thereof, You may choose to offer, - and charge a fee for, acceptance of support, warranty, indemnity, - or other liability obligations and/or rights consistent with this - License. However, in accepting such obligations, You may act only - on Your own behalf and on Your sole responsibility, not on behalf - of any other Contributor, and only if You agree to indemnify, - defend, and hold each Contributor harmless for any liability - incurred by, or claims asserted against, such Contributor by reason - of your accepting any such warranty or additional liability. - - END OF TERMS AND CONDITIONS diff --git a/MessagePack.html b/MessagePack.html new file mode 100644 index 00000000..ec490c8b --- /dev/null +++ b/MessagePack.html @@ -0,0 +1,962 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Module: MessagePack + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (M)</a> » + + + <span class="title">MessagePack</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Module: MessagePack + + + +</h1> +<div class="box_info"> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>lib/msgpack/version.rb<span class="defines">,<br /> + doclib/msgpack.rb,<br /> doclib/msgpack/time.rb,<br /> doclib/msgpack/error.rb,<br /> doclib/msgpack/buffer.rb,<br /> doclib/msgpack/packer.rb,<br /> doclib/msgpack/factory.rb,<br /> doclib/msgpack/unpacker.rb,<br /> doclib/msgpack/timestamp.rb,<br /> doclib/msgpack/extension_value.rb</span> +</dd> + </dl> + +</div> + +<h2>Defined Under Namespace</h2> +<p class="children"> + + + + + <strong class="classes">Classes:</strong> <span class='object_link'><a href="MessagePack/Buffer.html" title="MessagePack::Buffer (class)">Buffer</a></span>, <span class='object_link'><a href="MessagePack/ExtensionValue.html" title="MessagePack::ExtensionValue (class)">ExtensionValue</a></span>, <span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span>, <span class='object_link'><a href="MessagePack/MalformedFormatError.html" title="MessagePack::MalformedFormatError (class)">MalformedFormatError</a></span>, <span class='object_link'><a href="MessagePack/Packer.html" title="MessagePack::Packer (class)">Packer</a></span>, <span class='object_link'><a href="MessagePack/StackError.html" title="MessagePack::StackError (class)">StackError</a></span>, <span class='object_link'><a href="MessagePack/Time.html" title="MessagePack::Time (class)">Time</a></span>, <span class='object_link'><a href="MessagePack/Timestamp.html" title="MessagePack::Timestamp (class)">Timestamp</a></span>, <span class='object_link'><a href="MessagePack/UnexpectedTypeError.html" title="MessagePack::UnexpectedTypeError (class)">UnexpectedTypeError</a></span>, <span class='object_link'><a href="MessagePack/UnknownExtTypeError.html" title="MessagePack::UnknownExtTypeError (class)">UnknownExtTypeError</a></span>, <span class='object_link'><a href="MessagePack/UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span>, <span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span> + + +</p> + + + <h2> + Constant Summary + <small><a href="#" class="constants_summary_toggle">collapse</a></small> + </h2> + + <dl class="constants"> + + <dt id="VERSION-constant" class="">VERSION = + + </dt> + <dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>1.8.0</span><span class='tstring_end'>"</span></span></pre></dd> + + <dt id="DefaultFactory-constant" class="">DefaultFactory = + <div class="docstring"> + <div class="discussion"> + +<p>An instance of Factory class. DefaultFactory is also used by global pack/unpack methods such as MessagePack.dump/load, Hash#to_msgpack, and other to_msgpack methods.</p> + +<p>Calling DefaultFactory.register_type lets you add an extension type globally.</p> + + + </div> +</div> +<div class="tags"> + + +</div> + </dt> + <dd><pre class="code"><span class='const'><span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">new</a></span></span></pre></dd> + + </dl> + + + + + + + + + + <h2> + Class Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#dump-class_method" title="dump (class method)">.<strong>dump</strong>(obj) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serializes an object into an IO or String.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#load-class_method" title="load (class method)">.<strong>load</strong>(src, options = {}) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Deserializes an object from an IO or String.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#pack-class_method" title="pack (class method)">.<strong>pack</strong>(obj) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serializes an object into an IO or String.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#unpack-class_method" title="unpack (class method)">.<strong>unpack</strong>(src, options = {}) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Deserializes an object from an IO or String.</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="class_method_details" class="method_details_list"> + <h2>Class Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="dump-class_method"> + + + <span class="overload">.<strong>dump</strong>(obj, options = {}) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> </span> + + <span class="overload">.<strong>dump</strong>(obj, io, options = {}) ⇒ <tt>nil</tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serializes an object into an IO or String.</p> + +<p>See Packer#initialize for supported options.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">.<strong>dump</strong>(obj, options = {}) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + +<p>Returns serialized data.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>obj</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to be serialized</p> +</div> + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">.<strong>dump</strong>(obj, io, options = {}) ⇒ <tt>nil</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>obj</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to be serialized</p> +</div> + + </li> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>nil</tt>)</span> + + + + </li> + +</ul> + +</div> + </li> + + </ul> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +19 +20</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack.rb', line 19</span> + +<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="load-class_method"> + + + <span class="overload">.<strong>load</strong>(string, options = {}) ⇒ <tt>Object</tt> </span> + + <span class="overload">.<strong>load</strong>(io, options = {}) ⇒ <tt>Object</tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Deserializes an object from an IO or String.</p> + +<p>See Unpacker#initialize for supported options.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">.<strong>load</strong>(string, options = {}) ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>string</span> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>data to deserialize</p> +</div> + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">.<strong>load</strong>(io, options = {}) ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + </ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>deserialized object</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +56 +57</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack.rb', line 56</span> + +<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_src'>src</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="pack-class_method"> + + + <span class="overload">.<strong>pack</strong>(obj, options = {}) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> </span> + + <span class="overload">.<strong>pack</strong>(obj, io, options = {}) ⇒ <tt>nil</tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serializes an object into an IO or String. Alias of dump.</p> + +<p>See Packer#initialize for supported options.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">.<strong>pack</strong>(obj, options = {}) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + +<p>Returns serialized data.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>obj</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to be serialized</p> +</div> + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">.<strong>pack</strong>(obj, io, options = {}) ⇒ <tt>nil</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>obj</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to be serialized</p> +</div> + + </li> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>nil</tt>)</span> + + + + </li> + +</ul> + +</div> + </li> + + </ul> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +38 +39</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack.rb', line 38</span> + +<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_pack'>pack</span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="unpack-class_method"> + + + <span class="overload">.<strong>unpack</strong>(string, options = {}) ⇒ <tt>Object</tt> </span> + + <span class="overload">.<strong>unpack</strong>(io, options = {}) ⇒ <tt>Object</tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Deserializes an object from an IO or String. Alias of load.</p> + +<p>See Unpacker#initialize for supported options.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">.<strong>unpack</strong>(string, options = {}) ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>string</span> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>data to deserialize</p> +</div> + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">.<strong>unpack</strong>(io, options = {}) ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + </ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>deserialized object</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +74 +75</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack.rb', line 74</span> + +<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_unpack'>unpack</span><span class='lparen'>(</span><span class='id identifier rubyid_src'>src</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/Buffer.html b/MessagePack/Buffer.html new file mode 100644 index 00000000..768e61eb --- /dev/null +++ b/MessagePack/Buffer.html @@ -0,0 +1,1807 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::Buffer + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::Buffer"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (B)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">Buffer</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::Buffer + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">MessagePack::Buffer</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/buffer.rb</dd> + </dl> + +</div> + + + + + + <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2> + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#io-instance_method" title="#io (instance method)">#<strong>io</strong> ⇒ Object </a> + + + + </span> + + + + + <span class="note title readonly">readonly</span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Internal io.</p> +</div></span> + +</li> + + + </ul> + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#<<-instance_method" title="#<< (instance method)">#<strong><<</strong>(data) ⇒ Buffer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Appends the given data to the buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#clear-instance_method" title="#clear (instance method)">#<strong>clear</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Makes the buffer empty.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#close-instance_method" title="#close (instance method)">#<strong>close</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Closes internal IO if its set.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#empty%3F-instance_method" title="#empty? (instance method)">#<strong>empty?</strong> ⇒ Boolean </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns <em>true</em> if the buffer is empty.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#flush-instance_method" title="#flush (instance method)">#<strong>flush</strong> ⇒ Buffer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Flushes data in the internal buffer to the internal IO.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(*args) ⇒ Buffer </a> + + + + </span> + + + <span class="note title constructor">constructor</span> + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Creates a MessagePack::Buffer instance.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#read-instance_method" title="#read (instance method)">#<strong>read</strong>(n) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Consumes <em>n</em> bytes from the head of the buffer and returns consumed data.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#read_all-instance_method" title="#read_all (instance method)">#<strong>read_all</strong>(n, buffer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Consumes <em>n</em> bytes from the head of the buffer and returns consumed data.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#size-instance_method" title="#size (instance method)">#<strong>size</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns byte size of the buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#skip-instance_method" title="#skip (instance method)">#<strong>skip</strong>(n) ⇒ Integer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Consumes <em>n</em> bytes from the head of the buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#skip_all-instance_method" title="#skip_all (instance method)">#<strong>skip_all</strong>(n) ⇒ Buffer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Consumes <em>n</em> bytes from the head of the buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_a-instance_method" title="#to_a (instance method)">#<strong>to_a</strong> ⇒ Array </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns content of the buffer as an array of strings.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_str-instance_method" title="#to_str (instance method)">#<strong>to_str</strong> ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns all data in the buffer as a string.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write-instance_method" title="#write (instance method)">#<strong>write</strong>(data) ⇒ Integer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Appends the given data to the buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_to-instance_method" title="#write_to (instance method)">#<strong>write_to</strong>(io) ⇒ Integer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Writes all of data in the internal buffer into the given IO.</p> +</div></span> + +</li> + + + </ul> + + +<div id="constructor_details" class="method_details_list"> + <h2>Constructor Details</h2> + + <div class="method_details first"> + <h3 class="signature first" id="initialize-instance_method"> + + + <span class="overload">#<strong>initialize</strong>(options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt> </span> + + <span class="overload">#<strong>initialize</strong>(io, options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Creates a MessagePack::Buffer instance.</p> + +<p><em>io</em> must respond to readpartial(length, [,string]) or read(string) method and write(string) or append(string) method.</p> + +<p>Supported options:</p> +<ul><li> +<p><strong>:io_buffer_size</strong> buffer size to read data from the internal IO. (default: 32768)</p> +</li><li> +<p><strong>:read_reference_threshold</strong> 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)</p> +</li><li> +<p><strong>:write_reference_threshold</strong> 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)</p> +</li></ul> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">#<strong>initialize</strong>(options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">#<strong>initialize</strong>(io, options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + +<p>This buffer writes written data into the IO when it is filled. This buffer reads data from the IO when it is empty.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + </ul> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +25 +26</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 25</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + +</div> + + <div id="instance_attr_details" class="attr_details"> + <h2>Instance Attribute Details</h2> + + + <span id=""></span> + <div class="method_details first"> + <h3 class="signature first" id="io-instance_method"> + + #<strong>io</strong> ⇒ <tt>Object</tt> <span class="extras">(readonly)</span> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Internal io</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>IO</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +161 +162 +163</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 161</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_io'>io</span> + <span class='ivar'>@io</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="<<-instance_method"> + + #<strong><<</strong>(data) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Appends the given data to the buffer.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +68 +69</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 68</span> + +<span class='kw'>def</span> <span class='op'><<</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="clear-instance_method"> + + #<strong>clear</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Makes the buffer empty</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +33 +34</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 33</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_clear'>clear</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="close-instance_method"> + + #<strong>close</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Closes internal IO if its set. If internal IO is not set, it does nothing</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +178 +179</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 178</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_close'>close</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="empty?-instance_method"> + + #<strong>empty?</strong> ⇒ <tt>Boolean</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns <em>true</em> if the buffer is empty. This method is slightly faster than <em>size</em>.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Boolean</tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +50 +51</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 50</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_empty?'>empty?</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="flush-instance_method"> + + #<strong>flush</strong> ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Flushes data in the internal buffer to the internal IO. If internal IO is not set, it does nothing.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +169 +170</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 169</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_flush'>flush</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="read-instance_method"> + + + <span class="overload">#<strong>read</strong> ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + + <span class="overload">#<strong>read</strong>(n) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + + <span class="overload">#<strong>read</strong>(n, buffer) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Consumes <em>n</em> bytes from the head of the buffer and returns consumed data. If the size of the buffer is less than <em>n</em>, it reads all of data in the buffer.</p> + +<p>If <em>n</em> is 0, it does nothing and returns an empty string. If the optional <em>buffer</em> argument is given, the content of the string will be replaced with the consumed data.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + + <li class="overload_item"> + <span class="signature">#<strong>read</strong>(n) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>n</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>bytes to read</p> +</div> + + </li> + +</ul> + + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">#<strong>read</strong>(n, buffer) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>n</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>bytes to read</p> +</div> + + </li> + + <li> + + <span class='name'>buffer</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>buffer to read into</p> +</div> + + </li> + +</ul> + + +</div> + </li> + + </ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +89 +90</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 89</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="read_all-instance_method"> + + + <span class="overload">#<strong>read_all</strong> ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + + <span class="overload">#<strong>read_all</strong>(n) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + + <span class="overload">#<strong>read_all</strong>(n, buffer) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Consumes <em>n</em> bytes from the head of the buffer and returns consumed data. If the size of the buffer is less than <em>n</em>, it does nothing and raises EOFError.</p> + +<p>If <em>n</em> is 0, it does nothing and returns an empty string. If the optional <em>buffer</em> argument is given, the content of the string will be replaced with the consumed data.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + + <li class="overload_item"> + <span class="signature">#<strong>read_all</strong>(n) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>n</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>bytes to read</p> +</div> + + </li> + +</ul> + + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">#<strong>read_all</strong>(n, buffer) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>n</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>bytes to read</p> +</div> + + </li> + + <li> + + <span class='name'>buffer</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>buffer to read into</p> +</div> + + </li> + +</ul> + + +</div> + </li> + + </ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +110 +111</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 110</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_read_all'>read_all</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='comma'>,</span> <span class='id identifier rubyid_buffer'>buffer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="size-instance_method"> + + #<strong>size</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns byte size of the buffer.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +41 +42</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 41</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_size'>size</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="skip-instance_method"> + + #<strong>skip</strong>(n) ⇒ <tt>Integer</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Consumes <em>n</em> bytes from the head of the buffer. If the size of the buffer is less than <em>n</em>, it skips all of data in the buffer and returns integer less than <em>n</em>.</p> + +<p>If <em>n</em> is 0, it does nothing and returns <em>0</em>.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>n</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>byte size to skip</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>byte size actually skipped</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +122 +123</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 122</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_skip'>skip</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="skip_all-instance_method"> + + #<strong>skip_all</strong>(n) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Consumes <em>n</em> bytes from the head of the buffer. If the size of the buffer is less than <em>n</em>, it does nothing and raises EOFError. If <em>n</em> is 0, it does nothing.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>n</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>byte size to skip</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Buffer (class)">Buffer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +133 +134</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 133</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_skip_all'>skip_all</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="to_a-instance_method"> + + #<strong>to_a</strong> ⇒ <tt><span class='object_link'><a href="../Array.html" title="Array (class)">Array</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns content of the buffer as an array of strings.</p> + +<p>This method is sometimes faster than to_s because the internal structure of the buffer is a queue of buffer chunks.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../Array.html" title="Array (class)">Array</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>array of strings</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +153 +154</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 153</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_a'>to_a</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="to_str-instance_method"> + + #<strong>to_str</strong> ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns all data in the buffer as a string. Destructive update to the returned string does NOT effect the buffer.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +142 +143</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 142</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_str'>to_str</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write-instance_method"> + + #<strong>write</strong>(data) ⇒ <tt>Integer</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Appends the given data to the buffer.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>byte size written</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +59 +60</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 59</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_to-instance_method"> + + #<strong>write_to</strong>(io) ⇒ <tt>Integer</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Writes all of data in the internal buffer into the given IO. This method consumes and removes data from the internal buffer. <em>io</em> must respond to write(data) method.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>byte size of written data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +189 +190</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/buffer.rb', line 189</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_to'>write_to</span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/ExtensionValue.html b/MessagePack/ExtensionValue.html new file mode 100644 index 00000000..7905fdca --- /dev/null +++ b/MessagePack/ExtensionValue.html @@ -0,0 +1,321 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::ExtensionValue + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::ExtensionValue"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (E)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">ExtensionValue</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::ExtensionValue + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Struct</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Struct</li> + + <li class="next">MessagePack::ExtensionValue</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/extension_value.rb</dd> + </dl> + +</div> + +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + +<p>MessagePack::ExtensionValue is a struct to represent unknown ext type object. Its contents are accessed by type and payload (messagepack bytes representation) methods. And it is extended to add to_msgpack object.</p> + + + </div> +</div> +<div class="tags"> + + +</div> + + + + <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2> + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#payload-instance_method" title="#payload (instance method)">#<strong>payload</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns the value of attribute payload.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#type-instance_method" title="#type (instance method)">#<strong>type</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns the value of attribute type.</p> +</div></span> + +</li> + + + </ul> + + + + + + + <div id="instance_attr_details" class="attr_details"> + <h2>Instance Attribute Details</h2> + + + <span id="payload=-instance_method"></span> + <div class="method_details first"> + <h3 class="signature first" id="payload-instance_method"> + + #<strong>payload</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns the value of attribute payload</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>the current value of payload</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +8 +9 +10</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/extension_value.rb', line 8</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_payload'>payload</span> + <span class='ivar'>@payload</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + + <span id="type=-instance_method"></span> + <div class="method_details "> + <h3 class="signature " id="type-instance_method"> + + #<strong>type</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns the value of attribute type</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>the current value of type</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +8 +9 +10</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/extension_value.rb', line 8</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_type'>type</span> + <span class='ivar'>@type</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/Factory.html b/MessagePack/Factory.html new file mode 100644 index 00000000..2d485de3 --- /dev/null +++ b/MessagePack/Factory.html @@ -0,0 +1,1072 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::Factory + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::Factory"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (F)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">Factory</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::Factory + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">MessagePack::Factory</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/factory.rb</dd> + </dl> + +</div> + +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + +<p>MessagePack::Factory is a class to generate Packer and Unpacker which has same set of ext types.</p> + + + </div> +</div> +<div class="tags"> + + +</div><h2>Defined Under Namespace</h2> +<p class="children"> + + + + + <strong class="classes">Classes:</strong> <span class='object_link'><a href="Factory/Pool.html" title="MessagePack::Factory::Pool (class)">Pool</a></span> + + +</p> + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#dump-instance_method" title="#dump (instance method)">#<strong>dump</strong>(obj, options = nil) ⇒ String </a> + + + + (also: #pack) + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serialize the passed value.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong> ⇒ Factory </a> + + + + </span> + + + <span class="note title constructor">constructor</span> + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Creates a MessagePack::Factory instance.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#load-instance_method" title="#load (instance method)">#<strong>load</strong>(data, options = nil) ⇒ Object </a> + + + + (also: #unpack) + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Deserializes an object from the string or io and returns it.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#packer-instance_method" title="#packer (instance method)">#<strong>packer</strong>(*args) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Creates a MessagePack::Packer instance, which has ext types already registered.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#pool-instance_method" title="#pool (instance method)">#<strong>pool</strong>(size = 1, **options) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Creates a MessagePack::PooledFactory instance of the given size.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#register_type-instance_method" title="#register_type (instance method)">#<strong>register_type</strong>(type, klass, options = {}) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Register a type and Class to be registered for packer and/or unpacker.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#registered_types-instance_method" title="#registered_types (instance method)">#<strong>registered_types</strong>(selector = :both) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns a list of registered types, ordered by type id.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#type_registered%3F-instance_method" title="#type_registered? (instance method)">#<strong>type_registered?</strong>(klass_or_type, selector = :both) ⇒ Boolean </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns true/false which indicate specified class or type id is registered or not.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#unpacker-instance_method" title="#unpacker (instance method)">#<strong>unpacker</strong>(*args) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Creates a MessagePack::Unpacker instance, which has ext types already registered.</p> +</div></span> + +</li> + + + </ul> + + +<div id="constructor_details" class="method_details_list"> + <h2>Constructor Details</h2> + + <div class="method_details first"> + <h3 class="signature first" id="initialize-instance_method"> + + #<strong>initialize</strong> ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Factory (class)">Factory</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Creates a MessagePack::Factory instance</p> + + + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +10 +11</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 10</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + +</div> + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="dump-instance_method"> + + #<strong>dump</strong>(obj, options = nil) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> + + + + <span class="aliases">Also known as: + <span class="names"><span id='pack-instance_method'>pack</span></span> + </span> + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serialize the passed value</p> + +<p>If it could not serialize the object, it raises NoMethodError: undefined method ‘to_msgpack’ for #<the_object>.</p> + +<p>See Packer#initialize for supported options.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>obj</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to serialize</p> +</div> + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>nil</tt>)</em> + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized object</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +34 +35</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 34</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="load-instance_method"> + + #<strong>load</strong>(data, options = nil) ⇒ <tt>Object</tt> + + + + <span class="aliases">Also known as: + <span class="names"><span id='unpack-instance_method'>unpack</span></span> + </span> + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Deserializes an object from the string or io and returns it.</p> + +<p>If there’re not enough data to deserialize one object, this method raises EOFError. If data format is invalid, this method raises MessagePack::MalformedFormatError. If the object nests too deeply, this method raises MessagePack::StackError.</p> + +<p>See Unpacker#initialize for supported options.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>nil</tt>)</em> + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>deserialized object</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +60 +61</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 60</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="packer-instance_method"> + + #<strong>packer</strong>(*args) ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Creates a MessagePack::Packer instance, which has ext types already registered. Options are passed to MessagePack::Packer#initialized.</p> + +<p>See also Packer#initialize for options.</p> + + + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +19 +20</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 19</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_packer'>packer</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="pool-instance_method"> + + #<strong>pool</strong>(size = 1, **options) ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Creates a MessagePack::PooledFactory instance of the given size.</p> + +<p>PooledFactory keeps Packer and Unpacker instance in a pool for improved performance. Note that the size defines how many instances are kept in cache, not the maximum of instances that can be created. If the pool limit is reached, a new instance is created anyway.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>size</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>1</tt>)</em> + + + — + <div class='inline'> +<p>specify how many Packer and Unpacker to keep in cache (default 1)</p> +</div> + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>Combined options for Packer and Unpacker. See Packer#initialize and Unpacker#initialize for supported options.</p> +</div> + + </li> + +</ul> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +113 +114</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 113</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_pool'>pool</span><span class='lparen'>(</span><span class='id identifier rubyid_size'>size</span><span class='op'>=</span><span class='int'>1</span><span class='comma'>,</span> <span class='op'>**</span><span class='id identifier rubyid_options'>options</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="register_type-instance_method"> + + #<strong>register_type</strong>(type, klass, options = {}) ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Register a type and Class to be registered for packer and/or unpacker. If options are not specified, factory will use :to_msgpack_ext for packer, and :from_msgpack_ext for unpacker.</p> + +<p>Supported options:</p> +<ul><li> +<p><strong>:packer</strong> specify symbol or proc object for packer</p> +</li><li> +<p><strong>:unpacker</strong> specify symbol or proc object for unpacker</p> +</li><li> +<p><strong>:optimized_symbols_parsing</strong> specify true to use the optimized symbols parsing (not supported on JRuby now)</p> +</li><li> +<p><strong>recursive</strong> specify true to receive the packer or unpacker as argument to generate the extension body manually.</p> +</li></ul> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>type</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>type id of registered Class (0-127)</p> +</div> + + </li> + + <li> + + <span class='name'>klass</span> + + + <span class='type'>(<tt>Class</tt>)</span> + + + + — + <div class='inline'> +<p>Class to be associated with type id</p> +</div> + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + — + <div class='inline'> +<p>specify method name or Proc which are used by packer/unpacker</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +81 +82</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 81</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_klass'>klass</span><span class='comma'>,</span> <span class='id identifier rubyid_options'>options</span><span class='op'>=</span><span class='lbrace'>{</span><span class='rbrace'>}</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="registered_types-instance_method"> + + #<strong>registered_types</strong>(selector = :both) ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns a list of registered types, ordered by type id.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>selector</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Symbol.html" title="Symbol (class)">Symbol</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>:both</tt>)</em> + + + — + <div class='inline'> +<p>specify to list types registered for :packer, :unpacker or :both (default)</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>Array</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +90 +91</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 90</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_registered_types'>registered_types</span><span class='lparen'>(</span><span class='id identifier rubyid_selector'>selector</span><span class='op'>=</span><span class='symbol'>:both</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="type_registered?-instance_method"> + + #<strong>type_registered?</strong>(klass_or_type, selector = :both) ⇒ <tt>Boolean</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns true/false which indicate specified class or type id is registered or not.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>klass_or_type</span> + + + <span class='type'>(<tt>Class or <span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>Class or type id (0-127) to be checked</p> +</div> + + </li> + + <li> + + <span class='name'>selector</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Symbol.html" title="Symbol (class)">Symbol</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>:both</tt>)</em> + + + — + <div class='inline'> +<p>specify to check for :packer, :unpacker or :both (default)</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Boolean</tt>)</span> + + + + — + <div class='inline'> +<p>true or false</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +100 +101</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 100</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_type_registered?'>type_registered?</span><span class='lparen'>(</span><span class='id identifier rubyid_klass_or_type'>klass_or_type</span><span class='comma'>,</span> <span class='id identifier rubyid_selector'>selector</span><span class='op'>=</span><span class='symbol'>:both</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="unpacker-instance_method"> + + #<strong>unpacker</strong>(*args) ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Creates a MessagePack::Unpacker instance, which has ext types already registered. Options are passed to MessagePack::Unpacker#initialized.</p> + +<p>See also Unpacker#initialize for options.</p> + + + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +44 +45</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 44</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/Factory/Pool.html b/MessagePack/Factory/Pool.html new file mode 100644 index 00000000..c9c07737 --- /dev/null +++ b/MessagePack/Factory/Pool.html @@ -0,0 +1,499 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::Factory::Pool + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::Factory::Pool"; + relpath = '../../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../../_index.html">Index (P)</a> » + <span class='title'><span class='object_link'><a href="../../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> » <span class='title'><span class='object_link'><a href="../Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span> + » + <span class="title">Pool</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::Factory::Pool + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">MessagePack::Factory::Pool</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/factory.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#dump-instance_method" title="#dump (instance method)">#<strong>dump</strong>(object) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serialize the passed value.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#load-instance_method" title="#load (instance method)">#<strong>load</strong>(data) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Deserializes an object from the string or io and returns it.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#packer-instance_method" title="#packer (instance method)">#<strong>packer</strong> {|packer| ... } ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Yields a Packer from the pool, and check it back in.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#unpacker-instance_method" title="#unpacker (instance method)">#<strong>unpacker</strong> {|unpacker| ... } ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Yields an Unpacker from the pool, and check it back in.</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="dump-instance_method"> + + #<strong>dump</strong>(object) ⇒ <tt><span class='object_link'><a href="../../String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serialize the passed value</p> + +<p>If it could not serialize the object, it raises NoMethodError: undefined method ‘to_msgpack’ for #<the_object>.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>obj</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to serialize</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../../String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized object</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +139 +140</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 139</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='id identifier rubyid_object'>object</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="load-instance_method"> + + #<strong>load</strong>(data) ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Deserializes an object from the string or io and returns it.</p> + +<p>If there’re not enough data to deserialize one object, this method raises EOFError. If data format is invalid, this method raises MessagePack::MalformedFormatError. If the object nests too deeply, this method raises MessagePack::StackError.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>deserialized object</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +127 +128</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 127</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="packer-instance_method"> + + #<strong>packer</strong> {|packer| ... } ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Yields a Packer from the pool, and check it back in.</p> + +<p>The packer should no longer be held after the block has returned.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Yield Parameters:</p> +<ul class="yieldparam"> + + <li> + + <span class='name'>packer</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Packer.html" title="MessagePack::Packer (class)">MessagePack::Packer</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +161 +162</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 161</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_packer'>packer</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="unpacker-instance_method"> + + #<strong>unpacker</strong> {|unpacker| ... } ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Yields an Unpacker from the pool, and check it back in.</p> + +<p>The unpacker should no longer be held after the block has returned.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Yield Parameters:</p> +<ul class="yieldparam"> + + <li> + + <span class='name'>unpacker</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Unpacker.html" title="MessagePack::Unpacker (class)">MessagePack::Unpacker</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +150 +151</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/factory.rb', line 150</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/MalformedFormatError.html b/MessagePack/MalformedFormatError.html new file mode 100644 index 00000000..dce3a77b --- /dev/null +++ b/MessagePack/MalformedFormatError.html @@ -0,0 +1,132 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Exception: MessagePack::MalformedFormatError + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::MalformedFormatError"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (M)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">MalformedFormatError</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Exception: MessagePack::MalformedFormatError + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">StandardError</li> + + <li class="next"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></li> + + <li class="next">MessagePack::MalformedFormatError</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/error.rb</dd> + </dl> + +</div> + + + + + + + + + + + + + + + + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/Packer.html b/MessagePack/Packer.html new file mode 100644 index 00000000..47d10612 --- /dev/null +++ b/MessagePack/Packer.html @@ -0,0 +1,2052 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::Packer + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::Packer"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (P)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">Packer</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::Packer + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">MessagePack::Packer</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/packer.rb</dd> + </dl> + +</div> + +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + +<p>MessagePack::Packer is a class to serialize objects.</p> + + + </div> +</div> +<div class="tags"> + + +</div> + + + + <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2> + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#buffer-instance_method" title="#buffer (instance method)">#<strong>buffer</strong> ⇒ Object </a> + + + + </span> + + + + + <span class="note title readonly">readonly</span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Internal buffer.</p> +</div></span> + +</li> + + + </ul> + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#empty%3F-instance_method" title="#empty? (instance method)">#<strong>empty?</strong> ⇒ Boolean </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns <em>true</em> if the internal buffer is empty.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#flush-instance_method" title="#flush (instance method)">#<strong>flush</strong> ⇒ Packer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Flushes data in the internal buffer to the internal IO.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#full_pack-instance_method" title="#full_pack (instance method)">#<strong>full_pack</strong> ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns all data in the buffer as a string, and reset the buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(*args) ⇒ Packer </a> + + + + </span> + + + <span class="note title constructor">constructor</span> + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Creates a MessagePack::Packer instance.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#register_type-instance_method" title="#register_type (instance method)">#<strong>register_type</strong>(type, klass, method_name, &block) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Register a new ext type to serialize it.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#registered_types-instance_method" title="#registered_types (instance method)">#<strong>registered_types</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns a list of registered types, ordered by type id.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#reset-instance_method" title="#reset (instance method)">#<strong>reset</strong> ⇒ Object </a> + + + + (also: #clear) + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Makes the internal buffer empty.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#size-instance_method" title="#size (instance method)">#<strong>size</strong> ⇒ Integer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns size of the internal buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_a-instance_method" title="#to_a (instance method)">#<strong>to_a</strong> ⇒ Array </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns content of the internal buffer as an array of strings.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_str-instance_method" title="#to_str (instance method)">#<strong>to_str</strong> ⇒ String </a> + + + + (also: #to_s) + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns all data in the buffer as a string.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#type_registered%3F-instance_method" title="#type_registered? (instance method)">#<strong>type_registered?</strong>(klass_or_type) ⇒ Boolean </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns true/false which indicate specified class or type id is registered or not.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write-instance_method" title="#write (instance method)">#<strong>write</strong>(obj) ⇒ Packer </a> + + + + (also: #pack) + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serializes an object into internal buffer, and flushes to io if necessary.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_array_header-instance_method" title="#write_array_header (instance method)">#<strong>write_array_header</strong>(n) ⇒ Packer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Write a header of an array whose size is <em>n</em>.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_bin-instance_method" title="#write_bin (instance method)">#<strong>write_bin</strong>(obj) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serializes a string object as binary data.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_bin_header-instance_method" title="#write_bin_header (instance method)">#<strong>write_bin_header</strong>(n) ⇒ Packer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Write a header of a binary string whose size is <em>n</em>.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_float32-instance_method" title="#write_float32 (instance method)">#<strong>write_float32</strong>(value) ⇒ Packer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serializes <em>value</em> as 32-bit single precision float into internal buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_map_header-instance_method" title="#write_map_header (instance method)">#<strong>write_map_header</strong>(n) ⇒ Packer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Write a header of an map whose size is <em>n</em>.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_nil-instance_method" title="#write_nil (instance method)">#<strong>write_nil</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Serializes a nil object.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#write_to-instance_method" title="#write_to (instance method)">#<strong>write_to</strong>(io) ⇒ Integer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Writes all of data in the internal buffer into the given IO.</p> +</div></span> + +</li> + + + </ul> + + +<div id="constructor_details" class="method_details_list"> + <h2>Constructor Details</h2> + + <div class="method_details first"> + <h3 class="signature first" id="initialize-instance_method"> + + + <span class="overload">#<strong>initialize</strong>(options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> </span> + + <span class="overload">#<strong>initialize</strong>(io, options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Creates a MessagePack::Packer instance. See Buffer#initialize for supported options.</p> + +<p>Supported options:</p> +<ul><li> +<p><strong>:compatibility_mode</strong> serialize in older versions way, without str8 and bin types</p> +</li></ul> + +<p>See also Buffer#initialize for other options.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">#<strong>initialize</strong>(options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">#<strong>initialize</strong>(io, options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + +<p>This packer writes serialized objects into the IO when the internal buffer is filled. <em>io</em> must respond to write(string) or append(string) method.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + </ul> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +26 +27</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 26</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + +</div> + + <div id="instance_attr_details" class="attr_details"> + <h2>Instance Attribute Details</h2> + + + <span id=""></span> + <div class="method_details first"> + <h3 class="signature first" id="buffer-instance_method"> + + #<strong>buffer</strong> ⇒ <tt>Object</tt> <span class="extras">(readonly)</span> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Internal buffer</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>MessagePack::Buffer</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +72 +73 +74</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 72</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_buffer'>buffer</span> + <span class='ivar'>@buffer</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="empty?-instance_method"> + + #<strong>empty?</strong> ⇒ <tt>Boolean</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns <em>true</em> if the internal buffer is empty. Same as buffer.empty?. This method is slightly faster than <em>size</em>.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Boolean</tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +176 +177</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 176</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_empty?'>empty?</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="flush-instance_method"> + + #<strong>flush</strong> ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Flushes data in the internal buffer to the internal IO. Same as _buffer.flush. If internal IO is not set, it does nothing.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +150 +151</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 150</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_flush'>flush</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="full_pack-instance_method"> + + #<strong>full_pack</strong> ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns all data in the buffer as a string, and reset the buffer.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +184 +185</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 184</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_full_pack'>full_pack</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="register_type-instance_method"> + + + <span class="overload">#<strong>register_type</strong>(type, klass) {|object| ... } ⇒ <tt>Object</tt> </span> + + <span class="overload">#<strong>register_type</strong>(type, klass, method_name) ⇒ <tt>Object</tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Register a new ext type to serialize it. This method should be called with one of method name or block, which returns bytes(ASCII-8BIT String) representation of object to be serialized.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">#<strong>register_type</strong>(type, klass) {|object| ... } ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>type</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>type id (0-127) user defined type id for specified Class</p> +</div> + + </li> + + <li> + + <span class='name'>klass</span> + + + <span class='type'>(<tt>Class</tt>)</span> + + + + — + <div class='inline'> +<p>Class to be serialized with specified type id</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Yield Parameters:</p> +<ul class="yieldparam"> + + <li> + + <span class='name'>object</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to be serialized</p> +</div> + + </li> + +</ul> + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">#<strong>register_type</strong>(type, klass, method_name) ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>type</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>type id (0-127) user defined type id for specified Class</p> +</div> + + </li> + + <li> + + <span class='name'>klass</span> + + + <span class='type'>(<tt>Class</tt>)</span> + + + + — + <div class='inline'> +<p>Class to be serialized with specified type id</p> +</div> + + </li> + + <li> + + <span class='name'>method_name</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Symbol.html" title="Symbol (class)">Symbol</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>method which returns bytes of serialized representation</p> +</div> + + </li> + +</ul> + + +</div> + </li> + + </ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +46 +47</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 46</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_klass'>klass</span><span class='comma'>,</span> <span class='id identifier rubyid_method_name'>method_name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="registered_types-instance_method"> + + #<strong>registered_types</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns a list of registered types, ordered by type id. Each element is a Hash object includes keys :type, :class and :packer.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>Array</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +55 +56</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 55</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_registered_types'>registered_types</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="reset-instance_method"> + + #<strong>reset</strong> ⇒ <tt>Object</tt> + + + + <span class="aliases">Also known as: + <span class="names"><span id='clear-instance_method'>clear</span></span> + </span> + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Makes the internal buffer empty. Same as <em>buffer.clear</em>.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +158 +159</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 158</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_reset'>reset</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="size-instance_method"> + + #<strong>size</strong> ⇒ <tt>Integer</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns size of the internal buffer. Same as buffer.size.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +167 +168</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 167</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_size'>size</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="to_a-instance_method"> + + #<strong>to_a</strong> ⇒ <tt><span class='object_link'><a href="../Array.html" title="Array (class)">Array</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns content of the internal buffer as an array of strings. Same as buffer.to_a. This method is faster than <em>to_str</em>.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../Array.html" title="Array (class)">Array</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>array of strings</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +205 +206</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 205</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_a'>to_a</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="to_str-instance_method"> + + #<strong>to_str</strong> ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> + + + + <span class="aliases">Also known as: + <span class="names"><span id='to_s-instance_method'>to_s</span></span> + </span> + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns all data in the buffer as a string. Same as buffer.to_str.</p> + +<p>Does not empty the buffer, in most case <em>full_pack</em> is prefered.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +194 +195</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 194</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_str'>to_str</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="type_registered?-instance_method"> + + #<strong>type_registered?</strong>(klass_or_type) ⇒ <tt>Boolean</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns true/false which indicate specified class or type id is registered or not.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>klass_or_type</span> + + + <span class='type'>(<tt>Class or <span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>Class or type id (0-127) to be checked</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Boolean</tt>)</span> + + + + — + <div class='inline'> +<p>true or false</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +64 +65</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 64</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_type_registered?'>type_registered?</span><span class='lparen'>(</span><span class='id identifier rubyid_klass_or_type'>klass_or_type</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write-instance_method"> + + #<strong>write</strong>(obj) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> + + + + <span class="aliases">Also known as: + <span class="names"><span id='pack-instance_method'>pack</span></span> + </span> + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serializes an object into internal buffer, and flushes to io if necessary.</p> + +<p>If it could not serialize the object, it raises NoMethodError: undefined method ‘to_msgpack’ for #<the_object>.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>obj</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>object to serialize</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +83 +84</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 83</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_array_header-instance_method"> + + #<strong>write_array_header</strong>(n) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Write a header of an array whose size is <em>n</em>. For example, write_array_header(1).write(true) is same as write([ true ]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +106 +107</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 106</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_array_header'>write_array_header</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_bin-instance_method"> + + #<strong>write_bin</strong>(obj) ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serializes a string object as binary data. Same as write(“string”.encode(Encoding::BINARY)).</p> + + + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +97 +98</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 97</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_bin'>write_bin</span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_bin_header-instance_method"> + + #<strong>write_bin_header</strong>(n) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Write a header of a binary string whose size is <em>n</em>. Useful if you want to append large binary data without loading it into memory at once. For example, MessagePack::Packer.new(io).write_bin_header(12).flush io.write(‘chunk1’) io.write(‘chunk2’) is the same as write(‘chunk1chunk2’.encode(Encoding::BINARY)).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +129 +130</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 129</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_bin_header'>write_bin_header</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_float32-instance_method"> + + #<strong>write_float32</strong>(value) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serializes <em>value</em> as 32-bit single precision float into internal buffer. <em>value</em> will be approximated with the nearest possible single precision float, thus being potentially lossy. However, the serialized string will only take up 5 bytes instead of 9 bytes compared to directly serializing a 64-bit double precision Ruby Float.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>value</span> + + + <span class='type'>(<tt>Numeric</tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +141 +142</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 141</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_float32'>write_float32</span><span class='lparen'>(</span><span class='id identifier rubyid_value'>value</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_map_header-instance_method"> + + #<strong>write_map_header</strong>(n) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Write a header of an map whose size is <em>n</em>. For example, write_map_header(1).write(‘key’).write(true) is same as write(‘key’=>true).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Packer (class)">Packer</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +115 +116</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 115</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_map_header'>write_map_header</span><span class='lparen'>(</span><span class='id identifier rubyid_n'>n</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_nil-instance_method"> + + #<strong>write_nil</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Serializes a nil object. Same as write(nil).</p> + + + </div> +</div> +<div class="tags"> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +91 +92</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 91</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_nil'>write_nil</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="write_to-instance_method"> + + #<strong>write_to</strong>(io) ⇒ <tt>Integer</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Writes all of data in the internal buffer into the given IO. Same as buffer.write_to(io). This method consumes and removes data from the internal buffer. <em>io</em> must respond to write(data) method.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>byte size of written data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +216 +217</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/packer.rb', line 216</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_write_to'>write_to</span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/StackError.html b/MessagePack/StackError.html new file mode 100644 index 00000000..ed27ad94 --- /dev/null +++ b/MessagePack/StackError.html @@ -0,0 +1,132 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Exception: MessagePack::StackError + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::StackError"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (S)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">StackError</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Exception: MessagePack::StackError + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">StandardError</li> + + <li class="next"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></li> + + <li class="next">MessagePack::StackError</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/error.rb</dd> + </dl> + +</div> + + + + + + + + + + + + + + + + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/Time.html b/MessagePack/Time.html new file mode 100644 index 00000000..fc4c7312 --- /dev/null +++ b/MessagePack/Time.html @@ -0,0 +1,196 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::Time + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::Time"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (T)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">Time</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::Time + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">MessagePack::Time</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/time.rb</dd> + </dl> + +</div> + +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + +<p>MessagePack::Time provides packer and unpacker functions for a timestamp type.</p> + + + </div> +</div> +<div class="tags"> + + <div class="examples"> + <h4 class="tag_title">Examples:</h4> + + + <h5 class="example_title"><div class='inline'> +<p>Setup for DefaultFactory</p> +</div></h5> + + <pre class="example code"><code><span class='const'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span> + <span class='const'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Timestamp.html" title="MessagePack::Timestamp (class)">Timestamp</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="Timestamp.html#TYPE-constant" title="MessagePack::Timestamp::TYPE (constant)">TYPE</a></span></span><span class='comma'>,</span> + <span class='const'>Time</span><span class='comma'>,</span> + <span class='label'>packer:</span> <span class='const'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'>Time</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="#Packer-constant" title="MessagePack::Time::Packer (constant)">Packer</a></span></span><span class='comma'>,</span> + <span class='label'>unpacker:</span> <span class='const'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'>Time</span><span class='op'>::</span><span class='const'><span class='object_link'><a href="#Unpacker-constant" title="MessagePack::Time::Unpacker (constant)">Unpacker</a></span></span> +<span class='rparen'>)</span></code></pre> + + </div> + + +</div> + + <h2> + Constant Summary + <small><a href="#" class="constants_summary_toggle">collapse</a></small> + </h2> + + <dl class="constants"> + + <dt id="Packer-constant" class="">Packer = + <div class="docstring"> + <div class="discussion"> + +<p>A packer function that packs a Time instance to a MessagePack timestamp.</p> + + + </div> +</div> +<div class="tags"> + + +</div> + </dt> + <dd><pre class="code"><span class='id identifier rubyid_lambda'>lambda</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_payload'>payload</span><span class='op'>|</span> + <span class='comment'># ... +</span><span class='rbrace'>}</span></pre></dd> + + <dt id="Unpacker-constant" class="">Unpacker = + <div class="docstring"> + <div class="discussion"> + +<p>An unpacker function that unpacks a MessagePack timestamp to a Time instance.</p> + + + </div> +</div> +<div class="tags"> + + +</div> + </dt> + <dd><pre class="code"><span class='id identifier rubyid_lambda'>lambda</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_time'>time</span><span class='op'>|</span> + <span class='comment'># ... +</span><span class='rbrace'>}</span></pre></dd> + + </dl> + + + + + + + + + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/Timestamp.html b/MessagePack/Timestamp.html new file mode 100644 index 00000000..aa9b1562 --- /dev/null +++ b/MessagePack/Timestamp.html @@ -0,0 +1,686 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::Timestamp + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::Timestamp"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (T)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">Timestamp</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::Timestamp + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">MessagePack::Timestamp</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/timestamp.rb</dd> + </dl> + +</div> + +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + +<p>A utility class for MessagePack timestamp type</p> + + + </div> +</div> +<div class="tags"> + + +</div> + + <h2> + Constant Summary + <small><a href="#" class="constants_summary_toggle">collapse</a></small> + </h2> + + <dl class="constants"> + + <dt id="TYPE-constant" class="">TYPE = + <div class="docstring"> + <div class="discussion"> + +<p>The timestamp extension type defined in the MessagePack spec.</p> + +<p>See <a href="https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type">github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type</a> for details.</p> + + + </div> +</div> +<div class="tags"> + + +</div> + </dt> + <dd><pre class="code"><span class='op'>-</span><span class='int'>1</span></pre></dd> + + </dl> + + + + + + <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2> + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#nsec-instance_method" title="#nsec (instance method)">#<strong>nsec</strong> ⇒ Integer </a> + + + + </span> + + + + + <span class="note title readonly">readonly</span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Nanosecond part of the timestamp.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#sec-instance_method" title="#sec (instance method)">#<strong>sec</strong> ⇒ Integer </a> + + + + </span> + + + + + <span class="note title readonly">readonly</span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Second part of the timestamp.</p> +</div></span> + +</li> + + + </ul> + + + + + + <h2> + Class Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#from_msgpack_ext-class_method" title="from_msgpack_ext (class method)">.<strong>from_msgpack_ext</strong>(data) ⇒ MessagePack::Timestamp </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'></div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack_ext-class_method" title="to_msgpack_ext (class method)">.<strong>to_msgpack_ext</strong>(sec, nsec) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'></div></span> + +</li> + + + </ul> + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(sec, nsec) ⇒ Timestamp </a> + + + + </span> + + + <span class="note title constructor">constructor</span> + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>A new instance of Timestamp.</p> +</div></span> + +</li> + + + </ul> + + +<div id="constructor_details" class="method_details_list"> + <h2>Constructor Details</h2> + + <div class="method_details first"> + <h3 class="signature first" id="initialize-instance_method"> + + #<strong>initialize</strong>(sec, nsec) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Timestamp (class)">Timestamp</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns a new instance of Timestamp.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>sec</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + </li> + + <li> + + <span class='name'>nsec</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + </li> + +</ul> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +19 +20</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/timestamp.rb', line 19</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='id identifier rubyid_sec'>sec</span><span class='comma'>,</span> <span class='id identifier rubyid_nsec'>nsec</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + +</div> + + <div id="instance_attr_details" class="attr_details"> + <h2>Instance Attribute Details</h2> + + + <span id=""></span> + <div class="method_details first"> + <h3 class="signature first" id="nsec-instance_method"> + + #<strong>nsec</strong> ⇒ <tt>Integer</tt> <span class="extras">(readonly)</span> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns Nanosecond part of the timestamp.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>Nanosecond part of the timestamp.</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +15 +16 +17</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/timestamp.rb', line 15</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_nsec'>nsec</span> + <span class='ivar'>@nsec</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + + <span id=""></span> + <div class="method_details "> + <h3 class="signature " id="sec-instance_method"> + + #<strong>sec</strong> ⇒ <tt>Integer</tt> <span class="extras">(readonly)</span> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns Second part of the timestamp.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>Second part of the timestamp.</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +12 +13 +14</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/timestamp.rb', line 12</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_sec'>sec</span> + <span class='ivar'>@sec</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + + + <div id="class_method_details" class="method_details_list"> + <h2>Class Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="from_msgpack_ext-class_method"> + + .<strong>from_msgpack_ext</strong>(data) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Timestamp (class)">MessagePack::Timestamp</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + + <div class="examples"> + <h4 class="tag_title">Examples:</h4> + + + <h5 class="example_title"><div class='inline'> +<p>An unpacker implementation for the Time class</p> +</div></h5> + + <pre class="example code"><code><span class='id identifier rubyid_lambda'>lambda</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_payload'>payload</span><span class='op'>|</span> + <span class='id identifier rubyid_tv'>tv</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="MessagePack::Timestamp (class)">Timestamp</a></span></span><span class='period'>.</span><span class='id identifier rubyid_from_msgpack_ext'>from_msgpack_ext</span><span class='lparen'>(</span><span class='id identifier rubyid_payload'>payload</span><span class='rparen'>)</span> + <span class='const'><span class='object_link'><a href="Time.html" title="MessagePack::Time (class)">Time</a></span></span><span class='period'>.</span><span class='id identifier rubyid_at'>at</span><span class='lparen'>(</span><span class='id identifier rubyid_tv'>tv</span><span class='period'>.</span><span class='id identifier rubyid_sec'>sec</span><span class='comma'>,</span> <span class='id identifier rubyid_tv'>tv</span><span class='period'>.</span><span class='id identifier rubyid_nsec'>nsec</span><span class='comma'>,</span> <span class='symbol'>:nanosecond</span><span class='rparen'>)</span> +<span class='kw'>end</span></code></pre> + + </div> +<p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Timestamp (class)">MessagePack::Timestamp</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +30 +31</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/timestamp.rb', line 30</span> + +<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_from_msgpack_ext'>from_msgpack_ext</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="to_msgpack_ext-class_method"> + + .<strong>to_msgpack_ext</strong>(sec, nsec) ⇒ <tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + + <div class="examples"> + <h4 class="tag_title">Examples:</h4> + + + <h5 class="example_title"><div class='inline'> +<p>A packer implementation for the Time class</p> +</div></h5> + + <pre class="example code"><code><span class='id identifier rubyid_unpacker'>unpacker</span> <span class='op'>=</span> <span class='id identifier rubyid_lambda'>lambda</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_time'>time</span><span class='op'>|</span> + <span class='const'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="" title="MessagePack::Timestamp (class)">Timestamp</a></span></span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack_ext'>to_msgpack_ext</span><span class='lparen'>(</span><span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_tv_sec'>tv_sec</span><span class='comma'>,</span> <span class='id identifier rubyid_time'>time</span><span class='period'>.</span><span class='id identifier rubyid_tv_nsec'>tv_nsec</span><span class='rparen'>)</span> +<span class='kw'>end</span></code></pre> + + </div> +<p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>sec</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + </li> + + <li> + + <span class='name'>nsec</span> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +41 +42</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/timestamp.rb', line 41</span> + +<span class='kw'>def</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack_ext'>to_msgpack_ext</span><span class='lparen'>(</span><span class='id identifier rubyid_sec'>sec</span><span class='comma'>,</span> <span class='id identifier rubyid_nsec'>nsec</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/TypeError.html b/MessagePack/TypeError.html new file mode 100644 index 00000000..c68c9d73 --- /dev/null +++ b/MessagePack/TypeError.html @@ -0,0 +1,120 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" + "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> +<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> + <head> + <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> +<title> + Module: MessagePack::TypeError + + — Documentation by YARD 0.8.7.6 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" charset="utf-8" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" charset="utf-8" /> + +<script type="text/javascript" charset="utf-8"> + hasFrames = window.top.frames.main ? true : false; + relpath = '../'; + framesUrl = "../frames.html#!MessagePack/TypeError.html"; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (T)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">TypeError</span> + + + <div class="noframes"><span class="title">(</span><a href="." target="_top">no frames</a><span class="title">)</span></div> +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + Class List + </a> + + <a class="full_list_link" id="method_list_link" + href="../method_list.html"> + Method List + </a> + + <a class="full_list_link" id="file_list_link" + href="../file_list.html"> + File List + </a> + +</div> + <div class="clear"></div> + </div> + + <iframe id="search_frame"></iframe> + + <div id="content"><h1>Module: MessagePack::TypeError + + + +</h1> + +<dl class="box"> + + + + + + + + <dt class="r1">Included in:</dt> + <dd class="r1"><span class='object_link'><a href="UnexpectedTypeError.html" title="MessagePack::UnexpectedTypeError (class)">UnexpectedTypeError</a></span></dd> + + + + <dt class="r2 last">Defined in:</dt> + <dd class="r2 last">doclib/msgpack/error.rb</dd> + +</dl> +<div class="clear"></div> + +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + +<p>:nodoc: all</p> + + + </div> +</div> +<div class="tags"> + + +</div> + + + + + + + + +</div> + + <div id="footer"> + Generated on Mon Aug 3 13:04:20 2015 by + <a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.8.7.6 (ruby-2.2.2). +</div> + + </body> +</html> \ No newline at end of file diff --git a/MessagePack/UnexpectedTypeError.html b/MessagePack/UnexpectedTypeError.html new file mode 100644 index 00000000..2fa13d41 --- /dev/null +++ b/MessagePack/UnexpectedTypeError.html @@ -0,0 +1,138 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Exception: MessagePack::UnexpectedTypeError + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::UnexpectedTypeError"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (U)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">UnexpectedTypeError</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Exception: MessagePack::UnexpectedTypeError + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">StandardError</li> + + <li class="next"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></li> + + <li class="next">MessagePack::UnexpectedTypeError</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + <dl> + <dt>Includes:</dt> + <dd>TypeError</dd> + </dl> + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/error.rb</dd> + </dl> + +</div> + + + + + + + + + + + + + + + + + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/UnknownExtTypeError.html b/MessagePack/UnknownExtTypeError.html new file mode 100644 index 00000000..3541fb4d --- /dev/null +++ b/MessagePack/UnknownExtTypeError.html @@ -0,0 +1,138 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Exception: MessagePack::UnknownExtTypeError + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::UnknownExtTypeError"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (U)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">UnknownExtTypeError</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Exception: MessagePack::UnknownExtTypeError + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">StandardError</li> + + <li class="next"><span class='object_link'><a href="UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span></li> + + <li class="next">MessagePack::UnknownExtTypeError</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + <dl> + <dt>Includes:</dt> + <dd>TypeError</dd> + </dl> + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/error.rb</dd> + </dl> + +</div> + + + + + + + + + + + + + + + + + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/UnpackError.html b/MessagePack/UnpackError.html new file mode 100644 index 00000000..45115aed --- /dev/null +++ b/MessagePack/UnpackError.html @@ -0,0 +1,128 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Exception: MessagePack::UnpackError + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::UnpackError"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (U)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">UnpackError</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Exception: MessagePack::UnpackError + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">StandardError</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">StandardError</li> + + <li class="next">MessagePack::UnpackError</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/error.rb</dd> + </dl> + +</div> + +<div id="subclasses"> + <h2>Direct Known Subclasses</h2> + <p class="children"><span class='object_link'><a href="MalformedFormatError.html" title="MessagePack::MalformedFormatError (class)">MalformedFormatError</a></span>, <span class='object_link'><a href="StackError.html" title="MessagePack::StackError (class)">StackError</a></span>, <span class='object_link'><a href="UnexpectedTypeError.html" title="MessagePack::UnexpectedTypeError (class)">UnexpectedTypeError</a></span>, <span class='object_link'><a href="UnknownExtTypeError.html" title="MessagePack::UnknownExtTypeError (class)">UnknownExtTypeError</a></span></p> +</div> + + + + + + + + + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/MessagePack/Unpacker.html b/MessagePack/Unpacker.html new file mode 100644 index 00000000..0bc42b77 --- /dev/null +++ b/MessagePack/Unpacker.html @@ -0,0 +1,1624 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: MessagePack::Unpacker + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="../css/style.css" type="text/css" /> + + <link rel="stylesheet" href="../css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "MessagePack::Unpacker"; + relpath = '../'; +</script> + + + <script type="text/javascript" charset="utf-8" src="../js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="../js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="../class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="../_index.html">Index (U)</a> » + <span class='title'><span class='object_link'><a href="../MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span> + » + <span class="title">Unpacker</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="../class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: MessagePack::Unpacker + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">MessagePack::Unpacker</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/unpacker.rb</dd> + </dl> + +</div> + +<h2>Overview</h2><div class="docstring"> + <div class="discussion"> + +<p>MessagePack::Unpacker is a class to deserialize objects.</p> + + + </div> +</div> +<div class="tags"> + + +</div> + + + + <h2>Instance Attribute Summary <small><a href="#" class="summary_toggle">collapse</a></small></h2> + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#buffer-instance_method" title="#buffer (instance method)">#<strong>buffer</strong> ⇒ MessagePack::Buffer </a> + + + + </span> + + + + + <span class="note title readonly">readonly</span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Internal buffer.</p> +</div></span> + +</li> + + + </ul> + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#each-instance_method" title="#each (instance method)">#<strong>each</strong> {|object| ... } ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Repeats to deserialize objects.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#feed-instance_method" title="#feed (instance method)">#<strong>feed</strong>(data) ⇒ Unpacker </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Appends data into the internal buffer.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#feed_each-instance_method" title="#feed_each (instance method)">#<strong>feed_each</strong>(data) {|object| ... } ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Appends data into the internal buffer and repeats to deserialize objects.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#initialize-instance_method" title="#initialize (instance method)">#<strong>initialize</strong>(*args) ⇒ Unpacker </a> + + + + </span> + + + <span class="note title constructor">constructor</span> + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Creates a MessagePack::Unpacker instance.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#read-instance_method" title="#read (instance method)">#<strong>read</strong> ⇒ Object </a> + + + + (also: #unpack) + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Deserializes an object from the io or internal buffer and returns it.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#read_array_header-instance_method" title="#read_array_header (instance method)">#<strong>read_array_header</strong> ⇒ Integer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Read a header of an array and returns its size.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#read_map_header-instance_method" title="#read_map_header (instance method)">#<strong>read_map_header</strong> ⇒ Integer </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Reads a header of an map and returns its size.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#register_type-instance_method" title="#register_type (instance method)">#<strong>register_type</strong>(type, klass, method_name, &block) ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Register a new ext type to deserialize it.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#registered_types-instance_method" title="#registered_types (instance method)">#<strong>registered_types</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns a list of registered types, ordered by type id.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#reset-instance_method" title="#reset (instance method)">#<strong>reset</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Clears the internal buffer and resets deserialization state of the unpacker.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#skip-instance_method" title="#skip (instance method)">#<strong>skip</strong> ⇒ Object </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Deserializes an object and ignores it.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#skip_nil-instance_method" title="#skip_nil (instance method)">#<strong>skip_nil</strong> ⇒ Boolean </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Deserializes a nil value if it exists and returns <em>true</em>.</p> +</div></span> + +</li> + + + <li class="public "> + <span class="summary_signature"> + + <a href="#type_registered%3F-instance_method" title="#type_registered? (instance method)">#<strong>type_registered?</strong>(klass_or_type) ⇒ Boolean </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Returns true/false which indicate specified class or type id is registered or not.</p> +</div></span> + +</li> + + + </ul> + + +<div id="constructor_details" class="method_details_list"> + <h2>Constructor Details</h2> + + <div class="method_details first"> + <h3 class="signature first" id="initialize-instance_method"> + + + <span class="overload">#<strong>initialize</strong>(options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Unpacker (class)">Unpacker</a></span></tt> </span> + + <span class="overload">#<strong>initialize</strong>(io, options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Unpacker (class)">Unpacker</a></span></tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Creates a MessagePack::Unpacker instance.</p> + +<p>Supported options:</p> +<ul><li> +<p><strong>:symbolize_keys</strong> deserialize keys of Hash objects as Symbol instead of String</p> +</li><li> +<p><strong>:freeze</strong> freeze the deserialized objects. Can allow string deduplication and some allocation elision.</p> +</li><li> +<p><strong>:key_cache</strong> Enable caching of map keys, this can improve performance significantly if the same map keys are frequently encountered, but also degrade performance if that’s not the case.</p> +</li><li> +<p><strong>:allow_unknown_ext</strong> allow to deserialize ext type object with unknown type id as ExtensionValue instance. Otherwise (by default), unpacker throws UnknownExtTypeError.</p> +</li></ul> + +<p>See also Buffer#initialize for other options.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">#<strong>initialize</strong>(options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Unpacker (class)">Unpacker</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">#<strong>initialize</strong>(io, options = {}) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Unpacker (class)">Unpacker</a></span></tt> </span> + <div class="docstring"> + <div class="discussion"> + +<p>This unpacker reads data from the <em>io</em> to fill the internal buffer. <em>io</em> must respond to readpartial(length [,string]) or read(length [,string]) method.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>io</span> + + + <span class='type'>(<tt>IO</tt>)</span> + + + + </li> + + <li> + + <span class='name'>options</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Hash.html" title="Hash (class)">Hash</a></span></tt>)</span> + + + <em class="default">(defaults to: <tt>{}</tt>)</em> + + + </li> + +</ul> + + +</div> + </li> + + </ul> + + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +28 +29</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 28</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span><span class='lparen'>(</span><span class='op'>*</span><span class='id identifier rubyid_args'>args</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + +</div> + + <div id="instance_attr_details" class="attr_details"> + <h2>Instance Attribute Details</h2> + + + <span id=""></span> + <div class="method_details first"> + <h3 class="signature first" id="buffer-instance_method"> + + #<strong>buffer</strong> ⇒ <tt><span class='object_link'><a href="Buffer.html" title="MessagePack::Buffer (class)">MessagePack::Buffer</a></span></tt> <span class="extras">(readonly)</span> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Internal buffer</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="Buffer.html" title="MessagePack::Buffer (class)">MessagePack::Buffer</a></span></tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +72 +73 +74</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 72</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_buffer'>buffer</span> + <span class='ivar'>@buffer</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="each-instance_method"> + + #<strong>each</strong> {|object| ... } ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Repeats to deserialize objects.</p> + +<p>It repeats until the io or internal buffer does not include any complete objects.</p> + +<p>If an IO is set, it repeats to read data from the IO when the buffer becomes empty until the IO raises EOFError.</p> + +<p>This method could raise same errors with <em>read</em> excepting EOFError.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Yield Parameters:</p> +<ul class="yieldparam"> + + <li> + + <span class='name'>object</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>deserialized object</p> +</div> + + </li> + +</ul> +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +162 +163</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 162</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_each'>each</span><span class='lparen'>(</span><span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="feed-instance_method"> + + #<strong>feed</strong>(data) ⇒ <tt><span class='object_link'><a href="" title="MessagePack::Unpacker (class)">Unpacker</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Appends data into the internal buffer. This method is equivalent to unpacker.buffer.append(data).</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="MessagePack::Unpacker (class)">Unpacker</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>self</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +146 +147</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 146</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_feed'>feed</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="feed_each-instance_method"> + + #<strong>feed_each</strong>(data) {|object| ... } ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Appends data into the internal buffer and repeats to deserialize objects. This method is equivalent to unpacker.feed(data) && unpacker.each { … }.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + </li> + +</ul> + +<p class="tag_title">Yield Parameters:</p> +<ul class="yieldparam"> + + <li> + + <span class='name'>object</span> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>deserialized object</p> +</div> + + </li> + +</ul> +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +173 +174</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 173</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_feed_each'>feed_each</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="read-instance_method"> + + #<strong>read</strong> ⇒ <tt>Object</tt> + + + + <span class="aliases">Also known as: + <span class="names"><span id='unpack-instance_method'>unpack</span></span> + </span> + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Deserializes an object from the io or internal buffer and returns it.</p> + +<p>This method reads data from io into the internal buffer and deserializes an object from the buffer. It repeats reading data from the io until enough data is available to deserialize at least one object. After deserializing one object, unused data is left in the internal buffer.</p> + +<p>If there’re not enough data to deserialize one object, this method raises EOFError. If data format is invalid, this method raises MessagePack::MalformedFormatError. If the object nests too deeply, this method raises MessagePack::StackError.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Object</tt>)</span> + + + + — + <div class='inline'> +<p>deserialized object</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +88 +89</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 88</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_read'>read</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="read_array_header-instance_method"> + + #<strong>read_array_header</strong> ⇒ <tt>Integer</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Read a header of an array and returns its size. It converts a serialized array into a stream of elements.</p> + +<p>If the serialized object is not an array, it raises MessagePack::UnexpectedTypeError. If there’re not enough data, this method raises EOFError.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>size of the array</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +124 +125</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 124</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_read_array_header'>read_array_header</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="read_map_header-instance_method"> + + #<strong>read_map_header</strong> ⇒ <tt>Integer</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Reads a header of an map and returns its size. It converts a serialized map into a stream of key-value pairs.</p> + +<p>If the serialized object is not a map, it raises MessagePack::UnexpectedTypeError. If there’re not enough data, this method raises EOFError.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Integer</tt>)</span> + + + + — + <div class='inline'> +<p>size of the map</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +136 +137</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 136</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_read_map_header'>read_map_header</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="register_type-instance_method"> + + + <span class="overload">#<strong>register_type</strong>(type) {|data| ... } ⇒ <tt>Object</tt> </span> + + <span class="overload">#<strong>register_type</strong>(type, klass, class_method_name) ⇒ <tt>Object</tt> </span> + + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Register a new ext type to deserialize it. This method should be called with Class and its class method name, or block, which returns a instance object.</p> + + + </div> +</div> +<div class="tags"> + + <p class="tag_title">Overloads:</p> + <ul class="overload"> + + + <li class="overload_item"> + <span class="signature">#<strong>register_type</strong>(type) {|data| ... } ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>type</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>type id (0-127) user defined type id for specified deserializer block</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Yield Parameters:</p> +<ul class="yieldparam"> + + <li> + + <span class='name'>data</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>bytes(ASCII-8BIT String) represents serialized object, to be deserialized</p> +</div> + + </li> + +</ul> + +</div> + </li> + + + <li class="overload_item"> + <span class="signature">#<strong>register_type</strong>(type, klass, class_method_name) ⇒ <tt>Object</tt> </span> + <div class="docstring"> + <div class="discussion"> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>type</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>type id (0-127) user defined type id for specified Class</p> +</div> + + </li> + + <li> + + <span class='name'>klass</span> + + + <span class='type'>(<tt>Class</tt>)</span> + + + + — + <div class='inline'> +<p>Class to be serialized with specified type id</p> +</div> + + </li> + + <li> + + <span class='name'>class_method_name</span> + + + <span class='type'>(<tt><span class='object_link'><a href="../Symbol.html" title="Symbol (class)">Symbol</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>class method which returns an instance object</p> +</div> + + </li> + +</ul> + + +</div> + </li> + + </ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +46 +47</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 46</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='id identifier rubyid_type'>type</span><span class='comma'>,</span> <span class='id identifier rubyid_klass'>klass</span><span class='comma'>,</span> <span class='id identifier rubyid_method_name'>method_name</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="registered_types-instance_method"> + + #<strong>registered_types</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns a list of registered types, ordered by type id. Each element is a Hash object includes keys :type, :class and :unpacker.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>Array</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +55 +56</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 55</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_registered_types'>registered_types</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="reset-instance_method"> + + #<strong>reset</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Clears the internal buffer and resets deserialization state of the unpacker.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +181 +182</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 181</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_reset'>reset</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="skip-instance_method"> + + #<strong>skip</strong> ⇒ <tt>Object</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Deserializes an object and ignores it. This method is faster than <em>read</em>.</p> + +<p>This method could raise the same errors with <em>read</em>.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'></span> + + + + + <div class='inline'> +<p>nil</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +100 +101</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 100</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_skip'>skip</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="skip_nil-instance_method"> + + #<strong>skip_nil</strong> ⇒ <tt>Boolean</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Deserializes a nil value if it exists and returns <em>true</em>. Otherwise, if a byte exists but the byte doesn’t represent nil value, returns <em>false</em>.</p> + +<p>If there’re not enough data, this method raises EOFError.</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Boolean</tt>)</span> + + + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +112 +113</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 112</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_skip_nil'>skip_nil</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + <div class="method_details "> + <h3 class="signature " id="type_registered?-instance_method"> + + #<strong>type_registered?</strong>(klass_or_type) ⇒ <tt>Boolean</tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Returns true/false which indicate specified class or type id is registered or not.</p> + + + </div> +</div> +<div class="tags"> + <p class="tag_title">Parameters:</p> +<ul class="param"> + + <li> + + <span class='name'>klass_or_type</span> + + + <span class='type'>(<tt>Class or <span class='object_link'><a href="../Fixnum.html" title="Fixnum (class)">Fixnum</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>Class or type id (0-127) to be checked</p> +</div> + + </li> + +</ul> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt>Boolean</tt>)</span> + + + + — + <div class='inline'> +<p>true or false</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +64 +65</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/unpacker.rb', line 64</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_type_registered?'>type_registered?</span><span class='lparen'>(</span><span class='id identifier rubyid_klass_or_type'>klass_or_type</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/NilClass.html b/NilClass.html new file mode 100644 index 00000000..1badf602 --- /dev/null +++ b/NilClass.html @@ -0,0 +1,219 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: NilClass + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "NilClass"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (N)</a> » + + + <span class="title">NilClass</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: NilClass + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">NilClass</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +8 +9</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 8</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/README.md b/README.md deleted file mode 100644 index 6a7b72d5..00000000 --- a/README.md +++ /dev/null @@ -1,302 +0,0 @@ -# MessagePack - -[MessagePack](http://msgpack.org) is an efficient binary serialization format. -It lets you exchange data among multiple languages like JSON but it's faster and smaller. -For example, small integers (like flags or error code) are encoded into a single byte, -and typical short strings only require an extra byte in addition to the strings themselves. - -If you ever wished to use JSON for convenience (storing an image with metadata) but could -not for technical reasons (binary data, size, speed...), MessagePack is a perfect replacement. - -```ruby -require 'msgpack' -msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03" -MessagePack.unpack(msg) #=> [1,2,3] -``` - -Add msgpack to your Gemfile to install with Bundler: - -```ruby -# Gemfile -gem 'msgpack' -``` - -Or, use RubyGems to install: - - gem install msgpack - -Or, build msgpack-ruby and install from a checked-out msgpack-ruby repository: - - bundle - rake - gem install --local pkg/msgpack - - -## Use cases - -* Create REST API returing MessagePack using Rails + [RABL](https://github.com/nesquena/rabl) -* Store objects efficiently serialized by msgpack on memcached or Redis - * In fact Redis supports msgpack in [EVAL-scripts](https://redis.io/docs/latest/commands/eval/) -* Upload data in efficient format from mobile devices such as smartphones - * 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 -* Design a portable protocol to communicate with embedded devices - * Check also [Fluentd](https://www.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) -* Exchange objects between software components written in different languages - * You'll need a flexible but efficient format so that components exchange objects while keeping compatibility - -## Portability - -MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures. - -And it works with MRI (CRuby) and Rubinius. -Patches to improve portability are highly welcomed. - - -## Serializing objects - -Use `MessagePack.pack` or `to_msgpack`: - -```ruby -require 'msgpack' -msg = MessagePack.pack(obj) # or -msg = obj.to_msgpack -File.binwrite('mydata.msgpack', msg) -``` - -### Streaming serialization - -Packer provides advanced API to serialize objects in streaming style: - -```ruby -# serialize a 2-element array [e1, e2] -pk = MessagePack::Packer.new(io) -pk.write_array_header(2).write(e1).write(e2).flush -``` - -See [API reference](http://ruby.msgpack.org/MessagePack/Packer.html) for details. - -## Deserializing objects - -Use `MessagePack.unpack`: - -```ruby -require 'msgpack' -msg = File.binread('mydata.msgpack') -obj = MessagePack.unpack(msg) -``` - -### Streaming deserialization - -Unpacker provides advanced API to deserialize objects in streaming style: - -```ruby -# deserialize objects from an IO -u = MessagePack::Unpacker.new(io) -u.each do |obj| - # ... -end -``` - -or event-driven style which works well with EventMachine: - -```ruby -# event-driven deserialization -def on_read(data) - @u ||= MessagePack::Unpacker.new - @u.feed_each(data) {|obj| - # ... - } -end -``` - -See [API reference](http://ruby.msgpack.org/MessagePack/Unpacker.html) for details. - -## Serializing and deserializing symbols - -By default, symbols are serialized as strings: - -```ruby -packed = :symbol.to_msgpack # => "\xA6symbol" -MessagePack.unpack(packed) # => "symbol" -``` - -This can be customized by registering an extension type for them: - -```ruby -MessagePack::DefaultFactory.register_type(0x00, Symbol) - -# symbols now survive round trips -packed = :symbol.to_msgpack # => "\xc7\x06\x00symbol" -MessagePack.unpack(packed) # => :symbol -``` - -The extension type for symbols is configurable like any other extension type. -For example, to customize how symbols are packed you can just redefine -Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from -being serialized altogether by throwing an exception: - -```ruby -class Symbol - def to_msgpack_ext - raise "Serialization of symbols prohibited" - end -end - -MessagePack::DefaultFactory.register_type(0x00, Symbol) - -[1, :symbol, 'string'].to_msgpack # => RuntimeError: Serialization of symbols prohibited -``` - -## Serializing and deserializing Time instances - -There are the timestamp extension type in MessagePack, -but it is not registered by default. - -To map Ruby's Time to MessagePack's timestamp for the default factory: - -```ruby -MessagePack::DefaultFactory.register_type( - MessagePack::Timestamp::TYPE, # or just -1 - Time, - packer: MessagePack::Time::Packer, - unpacker: MessagePack::Time::Unpacker -) -``` - -See [API reference](http://ruby.msgpack.org/) for details. - -## Extension Types - -Packer and Unpacker support [Extension types of MessagePack](https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type). - -```ruby -# register how to serialize custom class at first -pk = MessagePack::Packer.new(io) -pk.register_type(0x01, MyClass1, :to_msgpack_ext) # equal to pk.register_type(0x01, MyClass) -pk.register_type(0x02, MyClass2){|obj| obj.how_to_serialize() } # blocks also available - -# almost same API for unpacker -uk = MessagePack::Unpacker.new() -uk.register_type(0x01, MyClass1, :from_msgpack_ext) -uk.register_type(0x02){|data| MyClass2.create_from_serialized_data(data) } -``` - -`MessagePack::Factory` is to create packer and unpacker which have same extension types. - -```ruby -factory = MessagePack::Factory.new -factory.register_type(0x01, MyClass1) # same with next line -factory.register_type(0x01, MyClass1, packer: :to_msgpack_ext, unpacker: :from_msgpack_ext) -pk = factory.packer(options_for_packer) -uk = factory.unpacker(options_for_unpacker) -``` - -For `MessagePack.pack` and `MessagePack.unpack`, default packer/unpacker refer `MessagePack::DefaultFactory`. Call `MessagePack::DefaultFactory.register_type` to enable types process globally. - -```ruby -MessagePack::DefaultFactory.register_type(0x03, MyClass3) -MessagePack.unpack(data_with_ext_typeid_03) #=> MyClass3 instance -``` - -Alternatively, extension types can call the packer or unpacker recursively to generate the extension data: - -```ruby -Point = Struct.new(:x, :y) -factory = MessagePack::Factory.new -factory.register_type( - 0x01, - Point, - packer: ->(point, packer) { - packer.write(point.x) - packer.write(point.y) - }, - unpacker: ->(unpacker) { - x = unpacker.read - y = unpacker.read - Point.new(x, y) - }, - recursive: true, -) -factory.load(factory.dump(Point.new(12, 34))) # => #<struct Point x=12, y=34> -``` - -## Pooling - -Creating `Packer` and `Unpacker` objects is expensive. For best performance it is preferable to re-use these objects. - -`MessagePack::Factory#pool` makes that easier: - -```ruby -factory = MessagePack::Factory.new -factory.register_type( - 0x01, - Point, - packer: ->(point, packer) { - packer.write(point.x) - packer.write(point.y) - }, - unpacker: ->(unpacker) { - x = unpacker.read - y = unpacker.read - Point.new(x, y) - }, - recursive: true, -) -pool = factory.pool(5) # The pool size should match the number of threads expected to use the factory concurrently. - -pool.load(pool.dump(Point.new(12, 34))) # => #<struct Point x=12, y=34> -``` - -## Buffer API - -MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API. - -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), -and has zero-copy capability which significantly affects performance to handle large binary data. - -## How to build and run tests - -Before building msgpack, you need to install bundler and dependencies. - - gem install bundler - bundle install - -Then, you can run the tasks as follows: - -### Build - - bundle exec rake build - -### Run tests - - bundle exec rake spec - -### Generating docs - - bundle exec rake doc - -## How to build -java rubygems - -To build -java gems for JRuby, run: - - rake build:java - -If this directory has Gemfile.lock (generated with MRI), remove it beforehand. - -## Updating documents - -Online documentation (https://ruby.msgpack.org) is generated from the gh-pages branch. -To update documents in gh-pages branch: - - bundle exec rake doc - git checkout gh-pages - cp -a doc/* ./ - -## Copyright - -* Author - * Sadayuki Furuhashi <frsyuki@gmail.com> -* Copyright - * Copyright (c) 2008-2015 Sadayuki Furuhashi -* License - * Apache License, Version 2.0 diff --git a/Rakefile b/Rakefile index 979f8c95..815897d3 100644 --- a/Rakefile +++ b/Rakefile @@ -1,82 +1,23 @@ - -require 'bundler' -Bundler::GemHelper.install_tasks - require 'fileutils' -require 'rspec/core' -require 'rspec/core/rake_task' -require 'yard' -if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.6.0') - require 'ruby_memcheck' - require 'ruby_memcheck/rspec/rake_task' - - RubyMemcheck.config(binary_name: 'msgpack') -end - -task :spec => :compile - -desc 'Run RSpec code examples and measure coverage' -task :coverage do |t| - ENV['SIMPLE_COV'] = '1' - Rake::Task["spec"].invoke -end - -desc 'Generate YARD document' -YARD::Rake::YardocTask.new(:doc) do |t| - t.files = ['lib/msgpack/version.rb','doclib/**/*.rb'] - t.options = [] - t.options << '--debug' << '--verbose' if $trace -end - -spec = eval File.read("msgpack.gemspec") - -if RUBY_PLATFORM =~ /java/ - require 'rake/javaextensiontask' - - Rake::JavaExtensionTask.new('msgpack', spec) do |ext| - ext.ext_dir = 'ext/java' - jruby_home = RbConfig::CONFIG['prefix'] - jars = ["#{jruby_home}/lib/jruby.jar"] - ext.classpath = jars.map { |x| File.expand_path(x) }.join(':') - ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact) - ext.release = '8' - end -else - require 'rake/extensiontask' - - Rake::ExtensionTask.new('msgpack', spec) do |ext| - ext.ext_dir = 'ext/msgpack' - ext.cross_compile = true - ext.lib_dir = File.join(*['lib', 'msgpack', ENV['FAT_DIR']].compact) - # cross_platform names are of MRI's platform name - ext.cross_platform = ['x86-mingw32', 'x64-mingw32'] +task :update do + if File.directory?("msgpack-ruby") + Dir.glob("msgpack-ruby/*", &FileUtils.method(:rm_rf)) + Dir.chdir("msgpack-ruby") do + sh "git checkout ." + end + else + sh "git clone git://github.com/msgpack/msgpack-ruby.git" end -end -test_pattern = case - when RUBY_PLATFORM =~ /java/ then 'spec/{,jruby/}*_spec.rb' - when RUBY_ENGINE =~ /rbx/ then 'spec/*_spec.rb' - else 'spec/{,cruby/}*_spec.rb' # MRI - end -spec_config = lambda do |t| - t.rspec_opts = ["-c", "-f progress"] - t.rspec_opts << "-Ilib" - t.pattern = test_pattern - t.verbose = true -end -RSpec::Core::RakeTask.new(:spec, &spec_config) -if Gem::Version.new(RUBY_VERSION) > Gem::Version.new('2.6.0') - namespace :spec do - RubyMemcheck::RSpec::RakeTask.new(valgrind: :compile, &spec_config) + Dir.chdir("msgpack-ruby") do + sh "git checkout master" + sh "git pull" + sh "rake doc" end -end -namespace :build do - desc 'Build gem for JRuby after cleaning' - task :java => [:clean, :spec, :build] + FileUtils.cp_r Dir.glob("msgpack-ruby/doc/*"), '.' end -CLEAN.include('lib/msgpack/msgpack.*') +task :default => :update -task :default => [:spec, :build, :doc] diff --git a/String.html b/String.html new file mode 100644 index 00000000..208e8529 --- /dev/null +++ b/String.html @@ -0,0 +1,219 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: String + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "String"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (S)</a> » + + + <span class="title">String</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: String + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">String</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +68 +69</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 68</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/Symbol.html b/Symbol.html new file mode 100644 index 00000000..18a3bbdb --- /dev/null +++ b/Symbol.html @@ -0,0 +1,219 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: Symbol + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "Symbol"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (S)</a> » + + + <span class="title">Symbol</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: Symbol + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">Symbol</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +98 +99</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 98</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/TrueClass.html b/TrueClass.html new file mode 100644 index 00000000..23bfc3c3 --- /dev/null +++ b/TrueClass.html @@ -0,0 +1,219 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Class: TrueClass + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "TrueClass"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index (T)</a> » + + + <span class="title">TrueClass</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Class: TrueClass + + + +</h1> +<div class="box_info"> + + <dl> + <dt>Inherits:</dt> + <dd> + <span class="inheritName">Object</span> + + <ul class="fullTree"> + <li>Object</li> + + <li class="next">TrueClass</li> + + </ul> + <a href="#" class="inheritanceTree">show all</a> + + </dd> + </dl> + + + + + + + + + + + + <dl> + <dt>Defined in:</dt> + <dd>doclib/msgpack/core_ext.rb</dd> + </dl> + +</div> + + + + + + + + + + <h2> + Instance Method Summary + <small><a href="#" class="summary_toggle">collapse</a></small> + </h2> + + <ul class="summary"> + + <li class="public "> + <span class="summary_signature"> + + <a href="#to_msgpack-instance_method" title="#to_msgpack (instance method)">#<strong>to_msgpack</strong>(packer = nil) ⇒ String </a> + + + + </span> + + + + + + + + + + <span class="summary_desc"><div class='inline'> +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> +</div></span> + +</li> + + + </ul> + + + + + <div id="instance_method_details" class="method_details_list"> + <h2>Instance Method Details</h2> + + + <div class="method_details first"> + <h3 class="signature first" id="to_msgpack-instance_method"> + + #<strong>to_msgpack</strong>(packer = nil) ⇒ <tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt> + + + + + +</h3><div class="docstring"> + <div class="discussion"> + +<p>Same as MessagePack.to_msgpack(self[, packer]).</p> + + + </div> +</div> +<div class="tags"> + +<p class="tag_title">Returns:</p> +<ul class="return"> + + <li> + + + <span class='type'>(<tt><span class='object_link'><a href="String.html" title="String (class)">String</a></span></tt>)</span> + + + + — + <div class='inline'> +<p>serialized data</p> +</div> + + </li> + +</ul> + +</div><table class="source_code"> + <tr> + <td> + <pre class="lines"> + + +18 +19</pre> + </td> + <td> + <pre class="code"><span class="info file"># File 'doclib/msgpack/core_ext.rb', line 18</span> + +<span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack'>to_msgpack</span><span class='lparen'>(</span><span class='id identifier rubyid_packer'>packer</span><span class='op'>=</span><span class='kw'>nil</span><span class='rparen'>)</span> +<span class='kw'>end</span></pre> + </td> + </tr> +</table> +</div> + + </div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/_index.html b/_index.html new file mode 100644 index 00000000..aabb7486 --- /dev/null +++ b/_index.html @@ -0,0 +1,331 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = null; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1 class="noborder title">Documentation by YARD 0.9.37</h1> +<div id="listing"> + <h1 class="alphaindex">Alphabetic Index</h1> + + <h2>File Listing</h2> + <ul id="files" class="index_inline_list"> + + + <li class="r1"><a href="index.html" title="README">README</a></li> + + + </ul> + +<div class="clear"></div> +<h2>Namespace Listing A-Z</h2> + + + + +<table> + <tr> + <td valign='top' width="33%"> + + + <ul id="alpha_A" class="alpha"> + <li class="letter">A</li> + <ul> + + <li> + <span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span> + + </li> + + </ul> + </ul> + + + <ul id="alpha_B" class="alpha"> + <li class="letter">B</li> + <ul> + + <li> + <span class='object_link'><a href="Bignum.html" title="Bignum (class)">Bignum</a></span> + + </li> + + <li> + <span class='object_link'><a href="MessagePack/Buffer.html" title="MessagePack::Buffer (class)">Buffer</a></span> + + <small>(MessagePack)</small> + + </li> + + </ul> + </ul> + + + <ul id="alpha_E" class="alpha"> + <li class="letter">E</li> + <ul> + + <li> + <span class='object_link'><a href="MessagePack/ExtensionValue.html" title="MessagePack::ExtensionValue (class)">ExtensionValue</a></span> + + <small>(MessagePack)</small> + + </li> + + </ul> + </ul> + + + <ul id="alpha_F" class="alpha"> + <li class="letter">F</li> + <ul> + + <li> + <span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="FalseClass.html" title="FalseClass (class)">FalseClass</a></span> + + </li> + + <li> + <span class='object_link'><a href="Fixnum.html" title="Fixnum (class)">Fixnum</a></span> + + </li> + + <li> + <span class='object_link'><a href="Float.html" title="Float (class)">Float</a></span> + + </li> + + </ul> + </ul> + + + <ul id="alpha_H" class="alpha"> + <li class="letter">H</li> + <ul> + + <li> + <span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span> + + </li> + + </ul> + </ul> + + + <ul id="alpha_M" class="alpha"> + <li class="letter">M</li> + <ul> + + <li> + <span class='object_link'><a href="MessagePack/MalformedFormatError.html" title="MessagePack::MalformedFormatError (class)">MalformedFormatError</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span> + + </li> + + </ul> + </ul> + + + <ul id="alpha_N" class="alpha"> + <li class="letter">N</li> + <ul> + + <li> + <span class='object_link'><a href="NilClass.html" title="NilClass (class)">NilClass</a></span> + + </li> + + </ul> + </ul> + + + </td><td valign='top' width="33%"> + + + <ul id="alpha_P" class="alpha"> + <li class="letter">P</li> + <ul> + + <li> + <span class='object_link'><a href="MessagePack/Packer.html" title="MessagePack::Packer (class)">Packer</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="MessagePack/Factory/Pool.html" title="MessagePack::Factory::Pool (class)">Pool</a></span> + + <small>(MessagePack::Factory)</small> + + </li> + + </ul> + </ul> + + + <ul id="alpha_S" class="alpha"> + <li class="letter">S</li> + <ul> + + <li> + <span class='object_link'><a href="MessagePack/StackError.html" title="MessagePack::StackError (class)">StackError</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="String.html" title="String (class)">String</a></span> + + </li> + + <li> + <span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span> + + </li> + + </ul> + </ul> + + + <ul id="alpha_T" class="alpha"> + <li class="letter">T</li> + <ul> + + <li> + <span class='object_link'><a href="MessagePack/Time.html" title="MessagePack::Time (class)">Time</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="MessagePack/Timestamp.html" title="MessagePack::Timestamp (class)">Timestamp</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="TrueClass.html" title="TrueClass (class)">TrueClass</a></span> + + </li> + + </ul> + </ul> + + + <ul id="alpha_U" class="alpha"> + <li class="letter">U</li> + <ul> + + <li> + <span class='object_link'><a href="MessagePack/UnexpectedTypeError.html" title="MessagePack::UnexpectedTypeError (class)">UnexpectedTypeError</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="MessagePack/UnknownExtTypeError.html" title="MessagePack::UnknownExtTypeError (class)">UnknownExtTypeError</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="MessagePack/UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span> + + <small>(MessagePack)</small> + + </li> + + <li> + <span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span> + + <small>(MessagePack)</small> + + </li> + + </ul> + </ul> + + </td> + </tr> +</table> + +</div> + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/bench/bench.rb b/bench/bench.rb deleted file mode 100644 index 91afd548..00000000 --- a/bench/bench.rb +++ /dev/null @@ -1,78 +0,0 @@ -# % bundle install -# % bundle exec ruby bench/bench.rb - -require 'msgpack' - -require 'benchmark/ips' - -object_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)"' -} - -data_plain = MessagePack.pack(object_plain) - -object_structured = { - 'remote_host' => '127.0.0.1', - 'remote_user' => '-', - 'date' => '10/Oct/2000:13:55:36 -0700', - 'request' => 'GET /apache_pb.gif HTTP/1.0', - 'method' => 'GET', - 'path' => '/apache_pb.gif', - 'protocol' => 'HTTP/1.0', - 'status' => 200, - 'bytes' => 2326, - 'referer' => 'http://www.example.com/start.html', - 'agent' => 'Mozilla/4.08 [en] (Win98; I ;Nav)', -} - -data_structured = MessagePack.pack(object_structured) - -class Extended - def to_msgpack_ext - MessagePack.pack({}) - end - - def self.from_msgpack_ext(data) - MessagePack.unpack(data) - Extended.new - end -end - -object_extended = { - 'extended' => Extended.new -} - -extended_packer = MessagePack::Packer.new -extended_packer.register_type(0x00, Extended, :to_msgpack_ext) -data_extended = extended_packer.pack(object_extended).to_s - -Benchmark.ips do |x| - x.report('pack-plain') do - MessagePack.pack(object_plain) - end - - x.report('pack-structured') do - MessagePack.pack(object_structured) - end - - x.report('pack-extended') do - packer = MessagePack::Packer.new - packer.register_type(0x00, Extended, :to_msgpack_ext) - packer.pack(object_extended).to_s - end - - x.report('unpack-plain') do - MessagePack.unpack(data_plain) - end - - x.report('unpack-structured') do - MessagePack.unpack(data_structured) - end - - x.report('unpack-extended') do - unpacker = MessagePack::Unpacker.new - unpacker.register_type(0x00, Extended, :from_msgpack_ext) - unpacker.feed data_extended - unpacker.read - end -end diff --git a/bin/console b/bin/console deleted file mode 100755 index 32e3f94f..00000000 --- a/bin/console +++ /dev/null @@ -1,8 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -require "bundler/setup" -require "msgpack" - -require "irb" -IRB.start(__FILE__) diff --git a/bin/rspec b/bin/rspec deleted file mode 100755 index cb53ebe5..00000000 --- a/bin/rspec +++ /dev/null @@ -1,27 +0,0 @@ -#!/usr/bin/env ruby -# frozen_string_literal: true - -# -# This file was generated by Bundler. -# -# The application 'rspec' is installed as part of a gem, and -# this file is here to facilitate running it. -# - -ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../Gemfile", __dir__) - -bundle_binstub = File.expand_path("bundle", __dir__) - -if File.file?(bundle_binstub) - if File.read(bundle_binstub, 300).include?("This file was generated by Bundler") - load(bundle_binstub) - else - abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run. -Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.") - end -end - -require "rubygems" -require "bundler/setup" - -load Gem.bin_path("rspec-core", "rspec") diff --git a/class_list.html b/class_list.html new file mode 100644 index 00000000..28367480 --- /dev/null +++ b/class_list.html @@ -0,0 +1,54 @@ +<!DOCTYPE html> +<html > + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta charset="utf-8" /> + + <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" /> + + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script> + + + <title>Class List</title> + <base id="base_target" target="_parent" /> + </head> + <body> + <div id="content"> + <div class="fixed_header"> + <h1 id="full_list_header">Class List</h1> + <div id="full_list_nav"> + + <span><a target="_self" href="class_list.html"> + Classes + </a></span> + + <span><a target="_self" href="method_list.html"> + Methods + </a></span> + + <span><a target="_self" href="file_list.html"> + Files + </a></span> + + </div> + + <div id="search"> + <label for="search-class">Search:</label> + <input id="search-class" type="text" /> + </div> + </div> + + <ul id="full_list" class="class"> + <li id="object_" class="odd"><div class="item" style="padding-left:30px"><span class='object_link'><a href="top-level-namespace.html" title="Top Level Namespace (root)">Top Level Namespace</a></span></div></li> +<li id='object_Array' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li><li id='object_Bignum' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Bignum.html" title="Bignum (class)">Bignum</a></span> < Integer<small class='search_info'>Top Level Namespace</small></div></li><li id='object_FalseClass' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="FalseClass.html" title="FalseClass (class)">FalseClass</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li><li id='object_Fixnum' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Fixnum.html" title="Fixnum (class)">Fixnum</a></span> < Integer<small class='search_info'>Top Level Namespace</small></div></li><li id='object_Float' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Float.html" title="Float (class)">Float</a></span> < Numeric<small class='search_info'>Top Level Namespace</small></div></li><li id='object_Hash' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li><li id='object_MessagePack' class='even'><div class='item' style='padding-left:30px'><a tabindex='0' class='toggle' role='button' aria-label='MessagePack child nodes' aria-expanded='false' aria-controls='object_MessagePack'></a> <span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span><small class='search_info'>Top Level Namespace</small></div><div aria-labelledby='object_MessagePack'><ul><li id='object_MessagePack::Buffer' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/Buffer.html" title="MessagePack::Buffer (class)">Buffer</a></span> < Object<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::ExtensionValue' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/ExtensionValue.html" title="MessagePack::ExtensionValue (class)">ExtensionValue</a></span> < Struct<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::Factory' class='collapsed odd'><div class='item' style='padding-left:45px'><a tabindex='0' class='toggle' role='button' aria-label='Factory child nodes' aria-expanded='false' aria-controls='object_MessagePack::Factory'></a> <span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span> < Object<small class='search_info'>MessagePack</small></div><div aria-labelledby='object_MessagePack::Factory'><ul><li id='object_MessagePack::Factory::Pool' class='collapsed'><div class='item' style='padding-left:60px'><span class='object_link'><a href="MessagePack/Factory/Pool.html" title="MessagePack::Factory::Pool (class)">Pool</a></span> < Object<small class='search_info'>MessagePack::Factory</small></div></li></ul></div></li><li id='object_MessagePack::MalformedFormatError' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/MalformedFormatError.html" title="MessagePack::MalformedFormatError (class)">MalformedFormatError</a></span> < UnpackError<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::Packer' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/Packer.html" title="MessagePack::Packer (class)">Packer</a></span> < Object<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::StackError' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/StackError.html" title="MessagePack::StackError (class)">StackError</a></span> < UnpackError<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::Time' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/Time.html" title="MessagePack::Time (class)">Time</a></span> < Object<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::Timestamp' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/Timestamp.html" title="MessagePack::Timestamp (class)">Timestamp</a></span> < Object<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::UnexpectedTypeError' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/UnexpectedTypeError.html" title="MessagePack::UnexpectedTypeError (class)">UnexpectedTypeError</a></span> < UnpackError<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::UnknownExtTypeError' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/UnknownExtTypeError.html" title="MessagePack::UnknownExtTypeError (class)">UnknownExtTypeError</a></span> < UnpackError<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::UnpackError' class='collapsed odd'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/UnpackError.html" title="MessagePack::UnpackError (class)">UnpackError</a></span> < StandardError<small class='search_info'>MessagePack</small></div></li><li id='object_MessagePack::Unpacker' class='collapsed even'><div class='item' style='padding-left:45px'><span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span> < Object<small class='search_info'>MessagePack</small></div></li></ul></div></li><li id='object_NilClass' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="NilClass.html" title="NilClass (class)">NilClass</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li><li id='object_String' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="String.html" title="String (class)">String</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li><li id='object_Symbol' class='odd'><div class='item' style='padding-left:30px'><span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li><li id='object_TrueClass' class='even'><div class='item' style='padding-left:30px'><span class='object_link'><a href="TrueClass.html" title="TrueClass (class)">TrueClass</a></span> < Object<small class='search_info'>Top Level Namespace</small></div></li> + + </ul> + </div> + </body> +</html> diff --git a/css/common.css b/css/common.css new file mode 100644 index 00000000..cf25c452 --- /dev/null +++ b/css/common.css @@ -0,0 +1 @@ +/* Override this file with custom rules */ \ No newline at end of file diff --git a/css/full_list.css b/css/full_list.css new file mode 100644 index 00000000..6eef5e4a --- /dev/null +++ b/css/full_list.css @@ -0,0 +1,58 @@ +body { + margin: 0; + font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + font-size: 13px; + height: 101%; + overflow-x: hidden; + background: #fafafa; +} + +h1 { padding: 12px 10px; padding-bottom: 0; margin: 0; font-size: 1.4em; } +.clear { clear: both; } +.fixed_header { position: fixed; background: #fff; width: 100%; padding-bottom: 10px; margin-top: 0; top: 0; z-index: 9999; height: 70px; } +#search { position: absolute; right: 5px; top: 9px; padding-left: 24px; } +#content.insearch #search, #content.insearch #noresults { background: url(data:image/gif;base64,R0lGODlhEAAQAPYAAP///wAAAPr6+pKSkoiIiO7u7sjIyNjY2J6engAAAI6OjsbGxjIyMlJSUuzs7KamppSUlPLy8oKCghwcHLKysqSkpJqamvT09Pj4+KioqM7OzkRERAwMDGBgYN7e3ujo6Ly8vCoqKjY2NkZGRtTU1MTExDw8PE5OTj4+PkhISNDQ0MrKylpaWrS0tOrq6nBwcKysrLi4uLq6ul5eXlxcXGJiYoaGhuDg4H5+fvz8/KKiohgYGCwsLFZWVgQEBFBQUMzMzDg4OFhYWBoaGvDw8NbW1pycnOLi4ubm5kBAQKqqqiQkJCAgIK6urnJyckpKSjQ0NGpqatLS0sDAwCYmJnx8fEJCQlRUVAoKCggICLCwsOTk5ExMTPb29ra2tmZmZmhoaNzc3KCgoBISEiIiIgAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAACH/C05FVFNDQVBFMi4wAwEAAAAh/hpDcmVhdGVkIHdpdGggYWpheGxvYWQuaW5mbwAh+QQJCAAAACwAAAAAEAAQAAAHaIAAgoMgIiYlg4kACxIaACEJCSiKggYMCRselwkpghGJBJEcFgsjJyoAGBmfggcNEx0flBiKDhQFlIoCCA+5lAORFb4AJIihCRbDxQAFChAXw9HSqb60iREZ1omqrIPdJCTe0SWI09GBACH5BAkIAAAALAAAAAAQABAAAAdrgACCgwc0NTeDiYozCQkvOTo9GTmDKy8aFy+NOBA7CTswgywJDTIuEjYFIY0JNYMtKTEFiRU8Pjwygy4ws4owPyCKwsMAJSTEgiQlgsbIAMrO0dKDGMTViREZ14kYGRGK38nHguHEJcvTyIEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDAggPg4iJAAMJCRUAJRIqiRGCBI0WQEEJJkWDERkYAAUKEBc4Po1GiKKJHkJDNEeKig4URLS0ICImJZAkuQAhjSi/wQyNKcGDCyMnk8u5rYrTgqDVghgZlYjcACTA1sslvtHRgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCQARAtOUoQRGRiFD0kJUYWZhUhKT1OLhR8wBaaFBzQ1NwAlkIszCQkvsbOHL7Y4q4IuEjaqq0ZQD5+GEEsJTDCMmIUhtgk1lo6QFUwJVDKLiYJNUd6/hoEAIfkECQgAAAAsAAAAABAAEAAAB2iAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4uen4ICCA+IkIsDCQkVACWmhwSpFqAABQoQF6ALTkWFnYMrVlhWvIKTlSAiJiVVPqlGhJkhqShHV1lCW4cMqSkAR1ofiwsjJyqGgQAh+QQJCAAAACwAAAAAEAAQAAAHZ4AAgoOEhYaCJSWHgxGDJCSMhREZGIYYGY2ElYebi56fhyWQniSKAKKfpaCLFlAPhl0gXYNGEwkhGYREUywag1wJwSkHNDU3D0kJYIMZQwk8MjPBLx9eXwuETVEyAC/BOKsuEjYFhoEAIfkECQgAAAAsAAAAABAAEAAAB2eAAIKDhIWGgiUlh4MRgyQkjIURGRiGGBmNhJWHm4ueICImip6CIQkJKJ4kigynKaqKCyMnKqSEK05StgAGQRxPYZaENqccFgIID4KXmQBhXFkzDgOnFYLNgltaSAAEpxa7BQoQF4aBACH5BAkIAAAALAAAAAAQABAAAAdogACCg4SFggJiPUqCJSWGgkZjCUwZACQkgxGEXAmdT4UYGZqCGWQ+IjKGGIUwPzGPhAc0NTewhDOdL7Ykji+dOLuOLhI2BbaFETICx4MlQitdqoUsCQ2vhKGjglNfU0SWmILaj43M5oEAOwAAAAAAAAAAAA==) no-repeat center left; } +#full_list { padding: 0; list-style: none; margin-left: 0; margin-top: 80px; font-size: 1.1em; } +#full_list ul { padding: 0; } +#full_list li { padding: 0; margin: 0; list-style: none; } +#full_list li .item { padding: 5px 5px 5px 12px; } +#noresults { padding: 7px 12px; background: #fff; } +#content.insearch #noresults { margin-left: 7px; } +li.collapsed ul { display: none; } +li a.toggle { cursor: default; position: relative; left: -5px; top: 4px; text-indent: -999px; width: 10px; height: 9px; margin-left: -10px; display: block; float: left; background: url(data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABQAAAASCAYAAABb0P4QAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAAK8AAACvABQqw0mAAAABx0RVh0U29mdHdhcmUAQWRvYmUgRmlyZXdvcmtzIENTM5jWRgMAAAAVdEVYdENyZWF0aW9uIFRpbWUAMy8xNC8wOeNZPpQAAAE2SURBVDiNrZTBccIwEEXfelIAHUA6CZ24BGaWO+FuzZAK4k6gg5QAdGAq+Bxs2Yqx7BzyL7Llp/VfzZeQhCTc/ezuGzKKnKSzpCxXJM8fwNXda3df5RZETlIt6YUzSQDs93sl8w3wBZxCCE10GM1OcWbWjB2mWgEH4Mfdyxm3PSepBHibgQE2wLe7r4HjEidpnXMYdQPKEMJcsZ4zs2POYQOcaPfwMVOo58zsAdMt18BuoVDPxUJRacELbXv3hUIX2vYmOUvi8C8ydz/ThjXrqKqqLbDIAdsCKBd+Wo7GWa7o9qzOQHVVVXeAbs+yHHCH4aTsaCOQqunmUy1yBUAXkdMIfMlgF5EXLo2OpV/c/Up7jG4hhHcYLgWzAZXUc2b2ixsfvc/RmNNfOXD3Q/oeL9axJE1yT9IOoUu6MGUkAAAAAElFTkSuQmCC) no-repeat bottom left; } +li.collapsed a.toggle { cursor: default; background-position: top left; } +li { color: #666; cursor: pointer; } +li.deprecated { text-decoration: line-through; font-style: italic; } +li.odd { background: #f0f0f0; } +li.even { background: #fafafa; } +.item:hover { background: #ddd; } +li small:before { content: "("; } +li small:after { content: ")"; } +li small.search_info { display: none; } +a, a:visited { text-decoration: none; color: #05a; } +li.clicked > .item { background: #05a; color: #ccc; } +li.clicked > .item a, li.clicked > .item a:visited { color: #eee; } +li.clicked > .item a.toggle { opacity: 0.5; background-position: bottom right; } +li.collapsed.clicked a.toggle { background-position: top right; } +#search input { border: 1px solid #bbb; border-radius: 3px; } +#full_list_nav { margin-left: 10px; font-size: 0.9em; display: block; color: #aaa; } +#full_list_nav a, #nav a:visited { color: #358; } +#full_list_nav a:hover { background: transparent; color: #5af; } +#full_list_nav span:after { content: ' | '; } +#full_list_nav span:last-child:after { content: ''; } + +#content h1 { margin-top: 0; } +li { white-space: nowrap; cursor: normal; } +li small { display: block; font-size: 0.8em; } +li small:before { content: ""; } +li small:after { content: ""; } +li small.search_info { display: none; } +#search { width: 170px; position: static; margin: 3px; margin-left: 10px; font-size: 0.9em; color: #666; padding-left: 0; padding-right: 24px; } +#content.insearch #search { background-position: center right; } +#search input { width: 110px; } + +#full_list.insearch ul { display: block; } +#full_list.insearch .item { display: none; } +#full_list.insearch .found { display: block; padding-left: 11px !important; } +#full_list.insearch li a.toggle { display: none; } +#full_list.insearch li small.search_info { display: block; } diff --git a/css/style.css b/css/style.css new file mode 100644 index 00000000..f169a651 --- /dev/null +++ b/css/style.css @@ -0,0 +1,503 @@ +html { + width: 100%; + height: 100%; +} +body { + font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + font-size: 13px; + width: 100%; + margin: 0; + padding: 0; + display: flex; + display: -webkit-flex; + display: -ms-flexbox; +} + +#nav { + position: relative; + width: 100%; + height: 100%; + border: 0; + border-right: 1px dotted #eee; + overflow: auto; +} +.nav_wrap { + margin: 0; + padding: 0; + width: 20%; + height: 100%; + position: relative; + display: flex; + display: -webkit-flex; + display: -ms-flexbox; + flex-shrink: 0; + -webkit-flex-shrink: 0; + -ms-flex: 1 0; +} +#resizer { + position: absolute; + right: -5px; + top: 0; + width: 10px; + height: 100%; + cursor: col-resize; + z-index: 9999; +} +#main { + flex: 5 1; + -webkit-flex: 5 1; + -ms-flex: 5 1; + outline: none; + position: relative; + background: #fff; + padding: 1.2em; + padding-top: 0.2em; + box-sizing: border-box; +} + +@media (max-width: 920px) { + .nav_wrap { width: 100%; top: 0; right: 0; overflow: visible; position: absolute; } + #resizer { display: none; } + #nav { + z-index: 9999; + background: #fff; + display: none; + position: absolute; + top: 40px; + right: 12px; + width: 500px; + max-width: 80%; + height: 80%; + overflow-y: scroll; + border: 1px solid #999; + border-collapse: collapse; + box-shadow: -7px 5px 25px #aaa; + border-radius: 2px; + } +} + +@media (min-width: 920px) { + body { height: 100%; overflow: hidden; } + #main { height: 100%; overflow: auto; } + #search { display: none; } +} + +@media (max-width: 320px) { + body { height: 100%; overflow: hidden; overflow-wrap: break-word; } + #main { height: 100%; overflow: auto; } +} + +#main img { max-width: 100%; } +h1 { font-size: 25px; margin: 1em 0 0.5em; padding-top: 4px; border-top: 1px dotted #d5d5d5; } +h1.noborder { border-top: 0px; margin-top: 0; padding-top: 4px; } +h1.title { margin-bottom: 10px; } +h1.alphaindex { margin-top: 0; font-size: 22px; } +h2 { + padding: 0; + padding-bottom: 3px; + border-bottom: 1px #aaa solid; + font-size: 1.4em; + margin: 1.8em 0 0.5em; + position: relative; +} +h2 small { font-weight: normal; font-size: 0.7em; display: inline; position: absolute; right: 0; } +h2 small a { + display: block; + height: 20px; + border: 1px solid #aaa; + border-bottom: 0; + border-top-left-radius: 5px; + background: #f8f8f8; + position: relative; + padding: 2px 7px; +} +a { font-weight: 550; } +.clear { clear: both; } +.inline { display: inline; } +.inline p:first-child { display: inline; } +.docstring, .tags, #filecontents { font-size: 15px; line-height: 1.5145em; } +.docstring p > code, .docstring p > tt, .tags p > code, .tags p > tt { + color: #c7254e; background: #f9f2f4; padding: 2px 4px; font-size: 1em; + border-radius: 4px; +} +.docstring h1, .docstring h2, .docstring h3, .docstring h4 { padding: 0; border: 0; border-bottom: 1px dotted #bbb; } +.docstring h1 { font-size: 1.2em; } +.docstring h2 { font-size: 1.1em; } +.docstring h3, .docstring h4 { font-size: 1em; border-bottom: 0; padding-top: 10px; } +.summary_desc .object_link a, .docstring .object_link a { + font-family: monospace; font-size: 1.05em; + color: #05a; background: #EDF4FA; padding: 2px 4px; font-size: 1em; + border-radius: 4px; +} +.rdoc-term { padding-right: 25px; font-weight: bold; } +.rdoc-list p { margin: 0; padding: 0; margin-bottom: 4px; } +.summary_desc pre.code .object_link a, .docstring pre.code .object_link a { + padding: 0px; background: inherit; color: inherit; border-radius: inherit; +} + +/* style for <table> */ +#filecontents table, .docstring table { border-collapse: collapse; } +#filecontents table th, #filecontents table td, +.docstring table th, .docstring table td { border: 1px solid #ccc; padding: 8px; padding-right: 17px; } +#filecontents table tr:nth-child(odd), +.docstring table tr:nth-child(odd) { background: #eee; } +#filecontents table tr:nth-child(even), +.docstring table tr:nth-child(even) { background: #fff; } +#filecontents table th, .docstring table th { background: #fff; } + +/* style for <ul> */ +#filecontents li > p, .docstring li > p { margin: 0px; } +#filecontents ul, .docstring ul { padding-left: 20px; } +/* style for <dl> */ +#filecontents dl, .docstring dl { border: 1px solid #ccc; } +#filecontents dt, .docstring dt { background: #ddd; font-weight: bold; padding: 3px 5px; } +#filecontents dd, .docstring dd { padding: 5px 0px; margin-left: 18px; } +#filecontents dd > p, .docstring dd > p { margin: 0px; } + +.note { + color: #222; + margin: 20px 0; + padding: 10px; + border: 1px solid #eee; + border-radius: 3px; + display: block; +} +.docstring .note { + border-left-color: #ccc; + border-left-width: 5px; +} +.note.todo { background: #ffffc5; border-color: #ececaa; } +.note.returns_void { background: #efefef; } +.note.deprecated { background: #ffe5e5; border-color: #e9dada; } +.note.title.deprecated { background: #ffe5e5; border-color: #e9dada; } +.note.private { background: #ffffc5; border-color: #ececaa; } +.note.title { padding: 3px 6px; font-size: 0.9em; font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; display: inline; } +.summary_signature + .note.title { margin-left: 7px; } +h1 .note.title { font-size: 0.5em; font-weight: normal; padding: 3px 5px; position: relative; top: -3px; text-transform: capitalize; } +.note.title { background: #efefef; } +.note.title.constructor { color: #fff; background: #6a98d6; border-color: #6689d6; } +.note.title.writeonly { color: #fff; background: #45a638; border-color: #2da31d; } +.note.title.readonly { color: #fff; background: #6a98d6; border-color: #6689d6; } +.note.title.private { background: #d5d5d5; border-color: #c5c5c5; } +.note.title.not_defined_here { background: transparent; border: none; font-style: italic; } +.discussion .note { margin-top: 6px; } +.discussion .note:first-child { margin-top: 0; } + +h3.inherited { + font-style: italic; + font-family: "Lucida Sans", "Lucida Grande", Verdana, Arial, sans-serif; + font-weight: normal; + padding: 0; + margin: 0; + margin-top: 12px; + margin-bottom: 3px; + font-size: 13px; +} +p.inherited { + padding: 0; + margin: 0; + margin-left: 25px; +} + +.box_info dl { + margin: 0; + border: 0; + width: 100%; + font-size: 1em; + display: flex; + display: -webkit-flex; + display: -ms-flexbox; +} +.box_info dl dt { + flex-shrink: 0; + -webkit-flex-shrink: 1; + -ms-flex-shrink: 1; + width: 100px; + text-align: right; + font-weight: bold; + border: 1px solid #aaa; + border-width: 1px 0px 0px 1px; + padding: 6px 0; + padding-right: 10px; +} +.box_info dl dd { + flex-grow: 1; + -webkit-flex-grow: 1; + -ms-flex: 1; + max-width: 420px; + padding: 6px 0; + padding-right: 20px; + border: 1px solid #aaa; + border-width: 1px 1px 0 0; + overflow: hidden; + position: relative; +} +.box_info dl:last-child > * { + border-bottom: 1px solid #aaa; +} +.box_info dl:nth-child(odd) > * { background: #eee; } +.box_info dl:nth-child(even) > * { background: #fff; } +.box_info dl > * { margin: 0; } + +ul.toplevel { list-style: none; padding-left: 0; font-size: 1.1em; } +.index_inline_list { padding-left: 0; font-size: 1.1em; } + +.index_inline_list li { + list-style: none; + display: inline-block; + padding: 0 12px; + line-height: 30px; + margin-bottom: 5px; +} + +dl.constants { margin-left: 10px; } +dl.constants dt { font-weight: bold; font-size: 1.1em; margin-bottom: 5px; } +dl.constants.compact dt { display: inline-block; font-weight: normal } +dl.constants dd { width: 75%; white-space: pre; font-family: monospace; margin-bottom: 18px; } +dl.constants .docstring .note:first-child { margin-top: 5px; } + +.summary_desc { + margin-left: 32px; + display: block; + font-family: sans-serif; + font-size: 1.1em; + margin-top: 8px; + line-height: 1.5145em; + margin-bottom: 0.8em; +} +.summary_desc tt { font-size: 0.9em; } +dl.constants .note { padding: 2px 6px; padding-right: 12px; margin-top: 6px; } +dl.constants .docstring { margin-left: 32px; font-size: 0.9em; font-weight: normal; } +dl.constants .tags { padding-left: 32px; font-size: 0.9em; line-height: 0.8em; } +dl.constants .discussion *:first-child { margin-top: 0; } +dl.constants .discussion *:last-child { margin-bottom: 0; } + +.method_details { border-top: 1px dotted #ccc; margin-top: 25px; padding-top: 0; } +.method_details.first { border: 0; margin-top: 5px; } +.method_details.first h3.signature { margin-top: 1em; } +p.signature, h3.signature { + font-size: 1.1em; font-weight: normal; font-family: Monaco, Consolas, Courier, monospace; + padding: 6px 10px; margin-top: 1em; + background: #E8F4FF; border: 1px solid #d8d8e5; border-radius: 5px; +} +p.signature tt, +h3.signature tt { font-family: Monaco, Consolas, Courier, monospace; } +p.signature .overload, +h3.signature .overload { display: block; } +p.signature .extras, +h3.signature .extras { font-weight: normal; font-family: sans-serif; color: #444; font-size: 1em; } +p.signature .not_defined_here, +h3.signature .not_defined_here, +p.signature .aliases, +h3.signature .aliases { display: block; font-weight: normal; font-size: 0.9em; font-family: sans-serif; margin-top: 0px; color: #555; } +p.signature .aliases .names, +h3.signature .aliases .names { font-family: Monaco, Consolas, Courier, monospace; font-weight: bold; color: #000; font-size: 1.2em; } + +.tags .tag_title { font-size: 1.05em; margin-bottom: 0; font-weight: bold; } +.tags .tag_title tt { color: initial; padding: initial; background: initial; } +.tags ul { margin-top: 5px; padding-left: 30px; list-style: square; } +.tags ul li { margin-bottom: 3px; } +.tags ul .name { font-family: monospace; font-weight: bold; } +.tags ul .note { padding: 3px 6px; } +.tags { margin-bottom: 12px; } + +.tags .examples .tag_title { margin-bottom: 10px; font-weight: bold; } +.tags .examples .inline p { padding: 0; margin: 0; font-weight: bold; font-size: 1em; } +.tags .examples .inline p:before { content: "▸"; font-size: 1em; margin-right: 5px; } + +.tags .overload .overload_item { list-style: none; margin-bottom: 25px; } +.tags .overload .overload_item .signature { + padding: 2px 8px; + background: #F1F8FF; border: 1px solid #d8d8e5; border-radius: 3px; +} +.tags .overload .signature { margin-left: -15px; font-family: monospace; display: block; font-size: 1.1em; } +.tags .overload .docstring { margin-top: 15px; } + +.defines { display: none; } + +#method_missing_details .notice.this { position: relative; top: -8px; color: #888; padding: 0; margin: 0; } + +.showSource { font-size: 0.9em; } +.showSource a, .showSource a:visited { text-decoration: none; color: #666; } + +#content a, #content a:visited { text-decoration: none; color: #05a; } +#content a:hover { background: #ffffa5; } + +ul.summary { + list-style: none; + font-family: monospace; + font-size: 1em; + line-height: 1.5em; + padding-left: 0px; +} +ul.summary a, ul.summary a:visited { + text-decoration: none; font-size: 1.1em; +} +ul.summary li { margin-bottom: 5px; } +.summary_signature { padding: 4px 8px; background: #f8f8f8; border: 1px solid #f0f0f0; border-radius: 5px; } +.summary_signature:hover { background: #CFEBFF; border-color: #A4CCDA; cursor: pointer; } +.summary_signature.deprecated { background: #ffe5e5; border-color: #e9dada; } +ul.summary.compact li { display: inline-block; margin: 0px 5px 0px 0px; line-height: 2.6em;} +ul.summary.compact .summary_signature { padding: 5px 7px; padding-right: 4px; } +#content .summary_signature:hover a, +#content .summary_signature:hover a:visited { + background: transparent; + color: #049; +} + +p.inherited a { font-family: monospace; font-size: 0.9em; } +p.inherited { word-spacing: 5px; font-size: 1.2em; } + +p.children { font-size: 1.2em; } +p.children a { font-size: 0.9em; } +p.children strong { font-size: 0.8em; } +p.children strong.modules { padding-left: 5px; } + +ul.fullTree { display: none; padding-left: 0; list-style: none; margin-left: 0; margin-bottom: 10px; } +ul.fullTree ul { margin-left: 0; padding-left: 0; list-style: none; } +ul.fullTree li { text-align: center; padding-top: 18px; padding-bottom: 12px; background: url(data:image/gif;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs+9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAKT2lDQ1BQaG90b3Nob3AgSUNDIHByb2ZpbGUAAHjanVNnVFPpFj333vRCS4iAlEtvUhUIIFJCi4AUkSYqIQkQSoghodkVUcERRUUEG8igiAOOjoCMFVEsDIoK2AfkIaKOg6OIisr74Xuja9a89+bN/rXXPues852zzwfACAyWSDNRNYAMqUIeEeCDx8TG4eQuQIEKJHAAEAizZCFz/SMBAPh+PDwrIsAHvgABeNMLCADATZvAMByH/w/qQplcAYCEAcB0kThLCIAUAEB6jkKmAEBGAYCdmCZTAKAEAGDLY2LjAFAtAGAnf+bTAICd+Jl7AQBblCEVAaCRACATZYhEAGg7AKzPVopFAFgwABRmS8Q5ANgtADBJV2ZIALC3AMDOEAuyAAgMADBRiIUpAAR7AGDIIyN4AISZABRG8lc88SuuEOcqAAB4mbI8uSQ5RYFbCC1xB1dXLh4ozkkXKxQ2YQJhmkAuwnmZGTKBNA/g88wAAKCRFRHgg/P9eM4Ors7ONo62Dl8t6r8G/yJiYuP+5c+rcEAAAOF0ftH+LC+zGoA7BoBt/qIl7gRoXgugdfeLZrIPQLUAoOnaV/Nw+H48PEWhkLnZ2eXk5NhKxEJbYcpXff5nwl/AV/1s+X48/Pf14L7iJIEyXYFHBPjgwsz0TKUcz5IJhGLc5o9H/LcL//wd0yLESWK5WCoU41EScY5EmozzMqUiiUKSKcUl0v9k4t8s+wM+3zUAsGo+AXuRLahdYwP2SycQWHTA4vcAAPK7b8HUKAgDgGiD4c93/+8//UegJQCAZkmScQAAXkQkLlTKsz/HCAAARKCBKrBBG/TBGCzABhzBBdzBC/xgNoRCJMTCQhBCCmSAHHJgKayCQiiGzbAdKmAv1EAdNMBRaIaTcA4uwlW4Dj1wD/phCJ7BKLyBCQRByAgTYSHaiAFiilgjjggXmYX4IcFIBBKLJCDJiBRRIkuRNUgxUopUIFVIHfI9cgI5h1xGupE7yAAygvyGvEcxlIGyUT3UDLVDuag3GoRGogvQZHQxmo8WoJvQcrQaPYw2oefQq2gP2o8+Q8cwwOgYBzPEbDAuxsNCsTgsCZNjy7EirAyrxhqwVqwDu4n1Y8+xdwQSgUXACTYEd0IgYR5BSFhMWE7YSKggHCQ0EdoJNwkDhFHCJyKTqEu0JroR+cQYYjIxh1hILCPWEo8TLxB7iEPENyQSiUMyJ7mQAkmxpFTSEtJG0m5SI+ksqZs0SBojk8naZGuyBzmULCAryIXkneTD5DPkG+Qh8lsKnWJAcaT4U+IoUspqShnlEOU05QZlmDJBVaOaUt2ooVQRNY9aQq2htlKvUYeoEzR1mjnNgxZJS6WtopXTGmgXaPdpr+h0uhHdlR5Ol9BX0svpR+iX6AP0dwwNhhWDx4hnKBmbGAcYZxl3GK+YTKYZ04sZx1QwNzHrmOeZD5lvVVgqtip8FZHKCpVKlSaVGyovVKmqpqreqgtV81XLVI+pXlN9rkZVM1PjqQnUlqtVqp1Q61MbU2epO6iHqmeob1Q/pH5Z/YkGWcNMw09DpFGgsV/jvMYgC2MZs3gsIWsNq4Z1gTXEJrHN2Xx2KruY/R27iz2qqaE5QzNKM1ezUvOUZj8H45hx+Jx0TgnnKKeX836K3hTvKeIpG6Y0TLkxZVxrqpaXllirSKtRq0frvTau7aedpr1Fu1n7gQ5Bx0onXCdHZ4/OBZ3nU9lT3acKpxZNPTr1ri6qa6UbobtEd79up+6Ynr5egJ5Mb6feeb3n+hx9L/1U/W36p/VHDFgGswwkBtsMzhg8xTVxbzwdL8fb8VFDXcNAQ6VhlWGX4YSRudE8o9VGjUYPjGnGXOMk423GbcajJgYmISZLTepN7ppSTbmmKaY7TDtMx83MzaLN1pk1mz0x1zLnm+eb15vft2BaeFostqi2uGVJsuRaplnutrxuhVo5WaVYVVpds0atna0l1rutu6cRp7lOk06rntZnw7Dxtsm2qbcZsOXYBtuutm22fWFnYhdnt8Wuw+6TvZN9un2N/T0HDYfZDqsdWh1+c7RyFDpWOt6azpzuP33F9JbpL2dYzxDP2DPjthPLKcRpnVOb00dnF2e5c4PziIuJS4LLLpc+Lpsbxt3IveRKdPVxXeF60vWdm7Obwu2o26/uNu5p7ofcn8w0nymeWTNz0MPIQ+BR5dE/C5+VMGvfrH5PQ0+BZ7XnIy9jL5FXrdewt6V3qvdh7xc+9j5yn+M+4zw33jLeWV/MN8C3yLfLT8Nvnl+F30N/I/9k/3r/0QCngCUBZwOJgUGBWwL7+Hp8Ib+OPzrbZfay2e1BjKC5QRVBj4KtguXBrSFoyOyQrSH355jOkc5pDoVQfujW0Adh5mGLw34MJ4WHhVeGP45wiFga0TGXNXfR3ENz30T6RJZE3ptnMU85ry1KNSo+qi5qPNo3ujS6P8YuZlnM1VidWElsSxw5LiquNm5svt/87fOH4p3iC+N7F5gvyF1weaHOwvSFpxapLhIsOpZATIhOOJTwQRAqqBaMJfITdyWOCnnCHcJnIi/RNtGI2ENcKh5O8kgqTXqS7JG8NXkkxTOlLOW5hCepkLxMDUzdmzqeFpp2IG0yPTq9MYOSkZBxQqohTZO2Z+pn5mZ2y6xlhbL+xW6Lty8elQfJa7OQrAVZLQq2QqboVFoo1yoHsmdlV2a/zYnKOZarnivN7cyzytuQN5zvn//tEsIS4ZK2pYZLVy0dWOa9rGo5sjxxedsK4xUFK4ZWBqw8uIq2Km3VT6vtV5eufr0mek1rgV7ByoLBtQFr6wtVCuWFfevc1+1dT1gvWd+1YfqGnRs+FYmKrhTbF5cVf9go3HjlG4dvyr+Z3JS0qavEuWTPZtJm6ebeLZ5bDpaql+aXDm4N2dq0Dd9WtO319kXbL5fNKNu7g7ZDuaO/PLi8ZafJzs07P1SkVPRU+lQ27tLdtWHX+G7R7ht7vPY07NXbW7z3/T7JvttVAVVN1WbVZftJ+7P3P66Jqun4lvttXa1ObXHtxwPSA/0HIw6217nU1R3SPVRSj9Yr60cOxx++/p3vdy0NNg1VjZzG4iNwRHnk6fcJ3/ceDTradox7rOEH0x92HWcdL2pCmvKaRptTmvtbYlu6T8w+0dbq3nr8R9sfD5w0PFl5SvNUyWna6YLTk2fyz4ydlZ19fi753GDborZ752PO32oPb++6EHTh0kX/i+c7vDvOXPK4dPKy2+UTV7hXmq86X23qdOo8/pPTT8e7nLuarrlca7nuer21e2b36RueN87d9L158Rb/1tWeOT3dvfN6b/fF9/XfFt1+cif9zsu72Xcn7q28T7xf9EDtQdlD3YfVP1v+3Njv3H9qwHeg89HcR/cGhYPP/pH1jw9DBY+Zj8uGDYbrnjg+OTniP3L96fynQ89kzyaeF/6i/suuFxYvfvjV69fO0ZjRoZfyl5O/bXyl/erA6xmv28bCxh6+yXgzMV70VvvtwXfcdx3vo98PT+R8IH8o/2j5sfVT0Kf7kxmTk/8EA5jz/GMzLdsAAAAgY0hSTQAAeiUAAICDAAD5/wAAgOkAAHUwAADqYAAAOpgAABdvkl/FRgAAAHtJREFUeNqMzrEJAkEURdGzuhgZbSoYWcAWoBVsB4JgZAGmphsZCZYzTQgWNCYrDN9RvMmHx+X916SUBFbo8CzD1idXrLErw1mQttgXtyrOcQ/Ny5p4Qh+2XqLYYazsPWNTiuMkRxa4vcV+evuNAUOLIx5+c2hyzv7hNQC67Q+/HHmlEwAAAABJRU5ErkJggg==) no-repeat top center; } +ul.fullTree li:first-child { padding-top: 0; background: transparent; } +ul.fullTree li:last-child { padding-bottom: 0; } +.showAll ul.fullTree { display: block; } +.showAll .inheritName { display: none; } + +#search { position: absolute; right: 12px; top: 0px; z-index: 9000; } +#search a { + display: block; float: left; + padding: 4px 8px; text-decoration: none; color: #05a; fill: #05a; + border: 1px solid #d8d8e5; + border-bottom-left-radius: 3px; border-bottom-right-radius: 3px; + background: #F1F8FF; + box-shadow: -1px 1px 3px #ddd; +} +#search a:hover { background: #f5faff; color: #06b; fill: #06b; } +#search a.active { + background: #568; padding-bottom: 20px; color: #fff; fill: #fff; + border: 1px solid #457; + border-top-left-radius: 5px; border-top-right-radius: 5px; +} +#search a.inactive { color: #999; fill: #999; } +.inheritanceTree, .toggleDefines { + float: right; + border-left: 1px solid #aaa; + position: absolute; top: 0; right: 0; + height: 100%; + background: #f6f6f6; + padding: 5px; + min-width: 55px; + text-align: center; +} + +#menu { font-size: 1.3em; color: #bbb; } +#menu .title, #menu a { font-size: 0.7em; } +#menu .title a { font-size: 1em; } +#menu .title { color: #555; } +#menu a, #menu a:visited { color: #333; text-decoration: none; border-bottom: 1px dotted #bbd; } +#menu a:hover { color: #05a; } + +#footer { margin-top: 15px; border-top: 1px solid #ccc; text-align: center; padding: 7px 0; color: #999; } +#footer a, #footer a:visited { color: #444; text-decoration: none; border-bottom: 1px dotted #bbd; } +#footer a:hover { color: #05a; } + +#listing ul.alpha { font-size: 1.1em; } +#listing ul.alpha { margin: 0; padding: 0; padding-bottom: 10px; list-style: none; } +#listing ul.alpha li.letter { font-size: 1.4em; padding-bottom: 10px; } +#listing ul.alpha ul { margin: 0; padding-left: 15px; } +#listing ul small { color: #666; font-size: 0.7em; } + +li.r1 { background: #f0f0f0; } +li.r2 { background: #fafafa; } + +#content ul.summary li.deprecated .summary_signature a, +#content ul.summary li.deprecated .summary_signature a:visited { text-decoration: line-through; font-style: italic; } + +#toc { + position: relative; + float: right; + overflow-x: auto; + right: -3px; + margin-left: 20px; + margin-bottom: 20px; + padding: 20px; padding-right: 30px; + max-width: 300px; + z-index: 5000; + background: #fefefe; + border: 1px solid #ddd; + box-shadow: -2px 2px 6px #bbb; +} +#toc .title { margin: 0; } +#toc ol { padding-left: 1.8em; } +#toc li { font-size: 1.1em; line-height: 1.7em; } +#toc > ol > li { font-size: 1.1em; font-weight: bold; } +#toc ol > li > ol { font-size: 0.9em; } +#toc ol ol > li > ol { padding-left: 2.3em; } +#toc ol + li { margin-top: 0.3em; } +#toc.hidden { padding: 10px; background: #fefefe; box-shadow: none; } +#toc.hidden:hover { background: #fafafa; } +#filecontents h1 + #toc.nofloat { margin-top: 0; } +@media (max-width: 560px) { + #toc { + margin-left: 0; + margin-top: 16px; + float: none; + max-width: none; + } +} + +/* syntax highlighting */ +.source_code { display: none; padding: 3px 8px; border-left: 8px solid #ddd; margin-top: 5px; } +#filecontents pre.code, .docstring pre.code, .source_code pre { font-family: monospace; } +#filecontents pre.code, .docstring pre.code { display: block; } +.source_code .lines { padding-right: 12px; color: #555; text-align: right; } +#filecontents pre.code, .docstring pre.code, +.tags pre.example { + padding: 9px 14px; + margin-top: 4px; + border: 1px solid #e1e1e8; + background: #f7f7f9; + border-radius: 4px; + font-size: 1em; + overflow-x: auto; + line-height: 1.2em; +} +pre.code { color: #000; tab-size: 2; } +pre.code .info.file { color: #555; } +pre.code .val { color: #036A07; } +pre.code .tstring_content, +pre.code .heredoc_beg, pre.code .heredoc_end, +pre.code .qwords_beg, pre.code .qwords_end, pre.code .qwords_sep, +pre.code .words_beg, pre.code .words_end, pre.code .words_sep, +pre.code .qsymbols_beg, pre.code .qsymbols_end, pre.code .qsymbols_sep, +pre.code .symbols_beg, pre.code .symbols_end, pre.code .symbols_sep, +pre.code .tstring, pre.code .dstring { color: #036A07; } +pre.code .fid, pre.code .rubyid_new, pre.code .rubyid_to_s, +pre.code .rubyid_to_sym, pre.code .rubyid_to_f, +pre.code .dot + pre.code .id, +pre.code .rubyid_to_i pre.code .rubyid_each { color: #0085FF; } +pre.code .comment { color: #0066FF; } +pre.code .const, pre.code .constant { color: #585CF6; } +pre.code .label, +pre.code .symbol { color: #C5060B; } +pre.code .kw, +pre.code .rubyid_require, +pre.code .rubyid_extend, +pre.code .rubyid_include { color: #0000FF; } +pre.code .ivar { color: #318495; } +pre.code .gvar, +pre.code .rubyid_backref, +pre.code .rubyid_nth_ref { color: #6D79DE; } +pre.code .regexp, .dregexp { color: #036A07; } +pre.code a { border-bottom: 1px dotted #bbf; } +/* inline code */ +*:not(pre) > code { + padding: 1px 3px 1px 3px; + border: 1px solid #E1E1E8; + background: #F7F7F9; + border-radius: 4px; +} + +/* Color fix for links */ +#content .summary_desc pre.code .id > .object_link a, /* identifier */ +#content .docstring pre.code .id > .object_link a { color: #0085FF; } +#content .summary_desc pre.code .const > .object_link a, /* constant */ +#content .docstring pre.code .const > .object_link a { color: #585CF6; } diff --git a/doclib/msgpack.rb b/doclib/msgpack.rb deleted file mode 100644 index 841f11cc..00000000 --- a/doclib/msgpack.rb +++ /dev/null @@ -1,87 +0,0 @@ - -module MessagePack - # - # Serializes an object into an IO or String. - # - # @overload dump(obj, options={}) - # @param obj [Object] object to be serialized - # @param options [Hash] - # @return [String] serialized data - # - # @overload dump(obj, io, options={}) - # @param obj [Object] object to be serialized - # @param io [IO] - # @param options [Hash] - # @return [nil] - # - # See Packer#initialize for supported options. - # - def self.dump(obj) - end - - # - # Serializes an object into an IO or String. Alias of dump. - # - # @overload pack(obj, options={}) - # @param obj [Object] object to be serialized - # @param options [Hash] - # @return [String] serialized data - # - # @overload pack(obj, io, options={}) - # @param obj [Object] object to be serialized - # @param io [IO] - # @param options [Hash] - # @return [nil] - # - # See Packer#initialize for supported options. - # - def self.pack(obj) - end - - # - # Deserializes an object from an IO or String. - # - # @overload load(string, options={}) - # @param string [String] data to deserialize - # @param options [Hash] - # - # @overload load(io, options={}) - # @param io [IO] - # @param options [Hash] - # - # @return [Object] deserialized object - # - # See Unpacker#initialize for supported options. - # - def self.load(src, options={}) - end - - # - # Deserializes an object from an IO or String. Alias of load. - # - # @overload unpack(string, options={}) - # @param string [String] data to deserialize - # @param options [Hash] - # - # @overload unpack(io, options={}) - # @param io [IO] - # @param options [Hash] - # - # @return [Object] deserialized object - # - # See Unpacker#initialize for supported options. - # - def self.unpack(src, options={}) - end - - # - # An instance of Factory class. DefaultFactory is also used - # by global pack/unpack methods such as MessagePack.dump/load, - # Hash#to_msgpack, and other to_msgpack methods. - # - # Calling DefaultFactory.register_type lets you add an extension - # type globally. - # - DefaultFactory = Factory.new -end - diff --git a/doclib/msgpack/buffer.rb b/doclib/msgpack/buffer.rb deleted file mode 100644 index 26145d8f..00000000 --- a/doclib/msgpack/buffer.rb +++ /dev/null @@ -1,193 +0,0 @@ -module MessagePack - - class Buffer - # - # Creates a MessagePack::Buffer instance. - # - # @overload initialize(options={}) - # @param options [Hash] - # - # @overload initialize(io, options={}) - # @param io [IO] - # @param options [Hash] - # This buffer writes written data into the IO when it is filled. - # This buffer reads data from the IO when it is empty. - # - # _io_ must respond to readpartial(length, [,string]) or read(string) method and - # write(string) or append(string) method. - # - # Supported options: - # - # * *:io_buffer_size* buffer size to read data from the internal IO. (default: 32768) - # * *: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) - # * *: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) - # - def initialize(*args) - end - - # - # Makes the buffer empty - # - # @return nil - # - def clear - end - - # - # Returns byte size of the buffer. - # - # @return nil - # - def size - end - - # - # Returns _true_ if the buffer is empty. - # This method is slightly faster than _size_. - # - # @return [Boolean] - # - def empty? - end - - # - # Appends the given data to the buffer. - # - # @param data [String] - # @return [Integer] byte size written - # - def write(data) - end - - # - # Appends the given data to the buffer. - # - # @param data [String] - # @return [Buffer] self - # - def <<(data) - end - - # - # Consumes _n_ bytes from the head of the buffer and returns consumed data. - # If the size of the buffer is less than _n_, it reads all of data in the buffer. - # - # If _n_ is 0, it does nothing and returns an empty string. - # If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data. - # - # @overload read - # - # @overload read(n) - # @param n [Integer] bytes to read - # - # @overload read(n, buffer) - # @param n [Integer] bytes to read - # @param buffer [String] buffer to read into - # - # @return [String] - # - def read(n) - end - - # - # Consumes _n_ bytes from the head of the buffer and returns consumed data. - # If the size of the buffer is less than _n_, it does nothing and raises EOFError. - # - # If _n_ is 0, it does nothing and returns an empty string. - # If the optional _buffer_ argument is given, the content of the string will be replaced with the consumed data. - # - # @overload read_all - # - # @overload read_all(n) - # @param n [Integer] bytes to read - # - # @overload read_all(n, buffer) - # @param n [Integer] bytes to read - # @param buffer [String] buffer to read into - # - # @return [String] - # - def read_all(n, buffer=nil) - end - - # - # Consumes _n_ bytes from the head of the buffer. - # If the size of the buffer is less than _n_, it skips all of data in the buffer and returns integer less than _n_. - # - # If _n_ is 0, it does nothing and returns _0_. - # - # @param n [Integer] byte size to skip - # @return [Integer] byte size actually skipped - # - def skip(n) - end - - # - # Consumes _n_ bytes from the head of the buffer. - # If the size of the buffer is less than _n_, it does nothing and raises EOFError. - # If _n_ is 0, it does nothing. - # - # @param n [Integer] byte size to skip - # @return [Buffer] self - # - def skip_all(n) - end - - # - # Returns all data in the buffer as a string. - # Destructive update to the returned string does NOT effect the buffer. - # - # @return [String] - # - def to_str - end - - # - # Returns content of the buffer as an array of strings. - # - # This method is sometimes faster than to_s because the internal - # structure of the buffer is a queue of buffer chunks. - # - # @return [Array] array of strings - # - def to_a - end - - # - # Internal io - # - # @return IO - # - attr_reader :io - - # - # Flushes data in the internal buffer to the internal IO. - # If internal IO is not set, it does nothing. - # - # @return [Buffer] self - # - def flush - end - - # - # Closes internal IO if its set. - # If internal IO is not set, it does nothing - # - # @return nil - # - def close - end - - # - # Writes all of data in the internal buffer into the given IO. - # This method consumes and removes data from the internal buffer. - # _io_ must respond to write(data) method. - # - # @param io [IO] - # @return [Integer] byte size of written data - # - def write_to(io) - end - end - -end diff --git a/doclib/msgpack/core_ext.rb b/doclib/msgpack/core_ext.rb deleted file mode 100644 index 17264088..00000000 --- a/doclib/msgpack/core_ext.rb +++ /dev/null @@ -1,101 +0,0 @@ - -class NilClass - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class TrueClass - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class FalseClass - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class Fixnum < Integer - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class Bignum < Integer - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class Float < Numeric - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class String - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class Array - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class Hash - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - -class Symbol - # - # Same as MessagePack.to_msgpack(self[, packer]). - # - # @return [String] serialized data - # - def to_msgpack(packer=nil) - end -end - diff --git a/doclib/msgpack/error.rb b/doclib/msgpack/error.rb deleted file mode 100644 index 85570035..00000000 --- a/doclib/msgpack/error.rb +++ /dev/null @@ -1,19 +0,0 @@ -module MessagePack - - class UnpackError < StandardError - end - - class MalformedFormatError < UnpackError - end - - class StackError < UnpackError - end - - class UnexpectedTypeError < UnpackError - include TypeError - end - - class UnknownExtTypeError < UnpackError - include TypeError - end -end diff --git a/doclib/msgpack/extension_value.rb b/doclib/msgpack/extension_value.rb deleted file mode 100644 index f0c3adc6..00000000 --- a/doclib/msgpack/extension_value.rb +++ /dev/null @@ -1,9 +0,0 @@ -module MessagePack - - # - # MessagePack::ExtensionValue is a struct to represent unknown ext type object. - # Its contents are accessed by type and payload (messagepack bytes representation) methods. - # And it is extended to add to_msgpack object. - # - ExtensionValue = Struct.new(:type, :payload) -end diff --git a/doclib/msgpack/factory.rb b/doclib/msgpack/factory.rb deleted file mode 100644 index a61b0d47..00000000 --- a/doclib/msgpack/factory.rb +++ /dev/null @@ -1,165 +0,0 @@ -module MessagePack - # - # MessagePack::Factory is a class to generate Packer and Unpacker which has - # same set of ext types. - # - class Factory - # - # Creates a MessagePack::Factory instance - # - def initialize - end - - # - # Creates a MessagePack::Packer instance, which has ext types already registered. - # Options are passed to MessagePack::Packer#initialized. - # - # See also Packer#initialize for options. - # - def packer(*args) - end - - # - # Serialize the passed value - # - # If it could not serialize the object, it raises - # NoMethodError: undefined method `to_msgpack' for #<the_object>. - # - # @param obj [Object] object to serialize - # @param options [Hash] - # @return [String] serialized object - # - # See Packer#initialize for supported options. - # - def dump(obj, options=nil) - end - alias pack dump - - # - # Creates a MessagePack::Unpacker instance, which has ext types already registered. - # Options are passed to MessagePack::Unpacker#initialized. - # - # See also Unpacker#initialize for options. - # - def unpacker(*args) - end - - # - # Deserializes an object from the string or io and returns it. - # - # If there're not enough data to deserialize one object, this method raises EOFError. - # If data format is invalid, this method raises MessagePack::MalformedFormatError. - # If the object nests too deeply, this method raises MessagePack::StackError. - # - # @param data [String] - # @param options [Hash] - # @return [Object] deserialized object - # - # See Unpacker#initialize for supported options. - # - def load(data, options=nil) - end - alias unpack load - - # - # Register a type and Class to be registered for packer and/or unpacker. - # If options are not specified, factory will use :to_msgpack_ext for packer, and - # :from_msgpack_ext for unpacker. - # - # @param type [Fixnum] type id of registered Class (0-127) - # @param klass [Class] Class to be associated with type id - # @param options [Hash] specify method name or Proc which are used by packer/unpacker - # @return nil - # - # Supported options: - # - # * *:packer* specify symbol or proc object for packer - # * *:unpacker* specify symbol or proc object for unpacker - # * *:optimized_symbols_parsing* specify true to use the optimized symbols parsing (not supported on JRuby now) - # * *recursive* specify true to receive the packer or unpacker as argument to generate the extension body manually. - # - def register_type(type, klass, options={}) - end - - # - # Returns a list of registered types, ordered by type id. - # - # @param selector [Symbol] specify to list types registered for :packer, :unpacker or :both (default) - # @return Array - # - def registered_types(selector=:both) - end - - # - # Returns true/false which indicate specified class or type id is registered or not. - # - # @param klass_or_type [Class or Fixnum] Class or type id (0-127) to be checked - # @param selector [Symbol] specify to check for :packer, :unpacker or :both (default) - # @return true or false - # - def type_registered?(klass_or_type, selector=:both) - end - - # - # Creates a MessagePack::PooledFactory instance of the given size. - # - # PooledFactory keeps Packer and Unpacker instance in a pool for improved performance. - # Note that the size defines how many instances are kept in cache, not the maximum of instances - # that can be created. If the pool limit is reached, a new instance is created anyway. - # - # @param size [Fixnum] specify how many Packer and Unpacker to keep in cache (default 1) - # @param options [Hash] Combined options for Packer and Unpacker. See Packer#initialize and Unpacker#initialize - # for supported options. - def pool(size=1, **options) - end - - class Pool - # - # Deserializes an object from the string or io and returns it. - # - # If there're not enough data to deserialize one object, this method raises EOFError. - # If data format is invalid, this method raises MessagePack::MalformedFormatError. - # If the object nests too deeply, this method raises MessagePack::StackError. - # - # @param data [String] - # @return [Object] deserialized object - # - def load(data) - end - - # - # Serialize the passed value - # - # If it could not serialize the object, it raises - # NoMethodError: undefined method `to_msgpack' for #<the_object>. - # - # @param obj [Object] object to serialize - # @return [String] serialized object - # - def dump(object) - end - - # - # Yields an Unpacker from the pool, and check it back in. - # - # The unpacker should no longer be held after the block has returned. - # - # @yieldparam unpacker [MessagePack::Unpacker] - # @returns [Object] the block return value - # - def unpacker(&block) - end - - # - # Yields a Packer from the pool, and check it back in. - # - # The packer should no longer be held after the block has returned. - # - # @yieldparam packer [MessagePack::Packer] - # @returns [Object] the block return value - # - def packer(&block) - end - end - end -end diff --git a/doclib/msgpack/packer.rb b/doclib/msgpack/packer.rb deleted file mode 100644 index 3893e0f4..00000000 --- a/doclib/msgpack/packer.rb +++ /dev/null @@ -1,219 +0,0 @@ -module MessagePack - - # - # MessagePack::Packer is a class to serialize objects. - # - class Packer - # - # Creates a MessagePack::Packer instance. - # See Buffer#initialize for supported options. - # - # @overload initialize(options={}) - # @param options [Hash] - # - # @overload initialize(io, options={}) - # @param io [IO] - # @param options [Hash] - # This packer writes serialized objects into the IO when the internal buffer is filled. - # _io_ must respond to write(string) or append(string) method. - # - # Supported options: - # - # * *:compatibility_mode* serialize in older versions way, without str8 and bin types - # - # See also Buffer#initialize for other options. - # - def initialize(*args) - end - - # - # Register a new ext type to serialize it. This method should be called with one of - # method name or block, which returns bytes(ASCII-8BIT String) representation of - # object to be serialized. - # - # @overload register_type(type, klass, &block) - # @param type [Fixnum] type id (0-127) user defined type id for specified Class - # @param klass [Class] Class to be serialized with specified type id - # @yieldparam object [Object] object to be serialized - # - # @overload register_type(type, klass, method_name) - # @param type [Fixnum] type id (0-127) user defined type id for specified Class - # @param klass [Class] Class to be serialized with specified type id - # @param method_name [Symbol] method which returns bytes of serialized representation - # - # @return nil - # - def register_type(type, klass, method_name, &block) - end - - # - # Returns a list of registered types, ordered by type id. - # Each element is a Hash object includes keys :type, :class and :packer. - # - # @return Array - # - def registered_types - end - - # - # Returns true/false which indicate specified class or type id is registered or not. - # - # @param klass_or_type [Class or Fixnum] Class or type id (0-127) to be checked - # @return true or false - # - def type_registered?(klass_or_type) - end - - # - # Internal buffer - # - # @return MessagePack::Buffer - # - attr_reader :buffer - - # - # Serializes an object into internal buffer, and flushes to io if necessary. - # - # If it could not serialize the object, it raises - # NoMethodError: undefined method `to_msgpack' for #<the_object>. - # - # @param obj [Object] object to serialize - # @return [Packer] self - # - def write(obj) - end - - alias pack write - - # - # Serializes a nil object. Same as write(nil). - # - def write_nil - end - - # - # Serializes a string object as binary data. Same as write("string".encode(Encoding::BINARY)). - # - def write_bin(obj) - end - - # - # Write a header of an array whose size is _n_. - # For example, write_array_header(1).write(true) is same as write([ true ]). - # - # @return [Packer] self - # - def write_array_header(n) - end - - # - # Write a header of an map whose size is _n_. - # For example, write_map_header(1).write('key').write(true) is same as write('key'=>true). - # - # @return [Packer] self - # - def write_map_header(n) - end - - # - # Write a header of a binary string whose size is _n_. Useful if you want to append large binary data without loading it into memory at once. - # For example, - # MessagePack::Packer.new(io).write_bin_header(12).flush - # io.write('chunk1') - # io.write('chunk2') - # is the same as - # write('chunk1chunk2'.encode(Encoding::BINARY)). - # - # @return [Packer] self - # - def write_bin_header(n) - end - - # - # Serializes _value_ as 32-bit single precision float into internal buffer. - # _value_ will be approximated with the nearest possible single precision float, thus - # being potentially lossy. However, the serialized string will only take up 5 bytes - # instead of 9 bytes compared to directly serializing a 64-bit double precision Ruby Float. - # - # @param value [Numeric] - # @return [Packer] self - # - def write_float32(value) - end - - # - # Flushes data in the internal buffer to the internal IO. Same as _buffer.flush. - # If internal IO is not set, it does nothing. - # - # @return [Packer] self - # - def flush - end - - # - # Makes the internal buffer empty. Same as _buffer.clear_. - # - # @return nil - # - def reset - end - alias clear reset - - # - # Returns size of the internal buffer. Same as buffer.size. - # - # @return [Integer] - # - def size - end - - # - # Returns _true_ if the internal buffer is empty. Same as buffer.empty?. - # This method is slightly faster than _size_. - # - # @return [Boolean] - # - def empty? - end - - # - # Returns all data in the buffer as a string, and reset the buffer. - # - # @return [String] - # - def full_pack - end - - # - # Returns all data in the buffer as a string. Same as buffer.to_str. - # - # Does not empty the buffer, in most case _full_pack_ is prefered. - # - # @return [String] - # - def to_str - end - - alias to_s to_str - - # - # Returns content of the internal buffer as an array of strings. Same as buffer.to_a. - # This method is faster than _to_str_. - # - # @return [Array] array of strings - # - def to_a - end - - # - # Writes all of data in the internal buffer into the given IO. Same as buffer.write_to(io). - # This method consumes and removes data from the internal buffer. - # _io_ must respond to write(data) method. - # - # @param io [IO] - # @return [Integer] byte size of written data - # - def write_to(io) - end - end -end diff --git a/doclib/msgpack/time.rb b/doclib/msgpack/time.rb deleted file mode 100644 index 7e5d0b7b..00000000 --- a/doclib/msgpack/time.rb +++ /dev/null @@ -1,22 +0,0 @@ -module MessagePack - - # MessagePack::Time provides packer and unpacker functions for a timestamp type. - # @example Setup for DefaultFactory - # MessagePack::DefaultFactory.register_type( - # MessagePack::Timestamp::TYPE, - # Time, - # packer: MessagePack::Time::Packer, - # unpacker: MessagePack::Time::Unpacker - # ) - class Time - # A packer function that packs a Time instance to a MessagePack timestamp. - Packer = lambda { |payload| - # ... - } - - # An unpacker function that unpacks a MessagePack timestamp to a Time instance. - Unpacker = lambda { |time| - # ... - } - end -end diff --git a/doclib/msgpack/timestamp.rb b/doclib/msgpack/timestamp.rb deleted file mode 100644 index 9b67bb1f..00000000 --- a/doclib/msgpack/timestamp.rb +++ /dev/null @@ -1,44 +0,0 @@ -module MessagePack - # A utility class for MessagePack timestamp type - class Timestamp - # - # The timestamp extension type defined in the MessagePack spec. - # - # See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type for details. - # - TYPE = -1 - - # @return [Integer] Second part of the timestamp. - attr_reader :sec - - # @return [Integer] Nanosecond part of the timestamp. - attr_reader :nsec - - # @param [Integer] sec - # @param [Integer] nsec - def initialize(sec, nsec) - end - - # @example An unpacker implementation for the Time class - # lambda do |payload| - # tv = MessagePack::Timestamp.from_msgpack_ext(payload) - # Time.at(tv.sec, tv.nsec, :nanosecond) - # end - # - # @param [String] data - # @return [MessagePack::Timestamp] - def self.from_msgpack_ext(data) - end - - # @example A packer implementation for the Time class - # unpacker = lambda do |time| - # MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec) - # end - # - # @param [Integer] sec - # @param [Integer] nsec - # @return [String] - def self.to_msgpack_ext(sec, nsec) - end - end -end diff --git a/doclib/msgpack/unpacker.rb b/doclib/msgpack/unpacker.rb deleted file mode 100644 index ea4f0786..00000000 --- a/doclib/msgpack/unpacker.rb +++ /dev/null @@ -1,185 +0,0 @@ -module MessagePack - - # - # MessagePack::Unpacker is a class to deserialize objects. - # - class Unpacker - # - # Creates a MessagePack::Unpacker instance. - # - # @overload initialize(options={}) - # @param options [Hash] - # - # @overload initialize(io, options={}) - # @param io [IO] - # @param options [Hash] - # This unpacker reads data from the _io_ to fill the internal buffer. - # _io_ must respond to readpartial(length [,string]) or read(length [,string]) method. - # - # Supported options: - # - # * *:symbolize_keys* deserialize keys of Hash objects as Symbol instead of String - # * *:freeze* freeze the deserialized objects. Can allow string deduplication and some allocation elision. - # * *:key_cache* Enable caching of map keys, this can improve performance significantly if the same map keys are frequently encountered, but also degrade performance if that's not the case. - # * *:allow_unknown_ext* allow to deserialize ext type object with unknown type id as ExtensionValue instance. Otherwise (by default), unpacker throws UnknownExtTypeError. - # - # See also Buffer#initialize for other options. - # - def initialize(*args) - end - - # - # Register a new ext type to deserialize it. This method should be called with - # Class and its class method name, or block, which returns a instance object. - # - # @overload register_type(type, &block) - # @param type [Fixnum] type id (0-127) user defined type id for specified deserializer block - # @yieldparam data [String] bytes(ASCII-8BIT String) represents serialized object, to be deserialized - # - # @overload register_type(type, klass, class_method_name) - # @param type [Fixnum] type id (0-127) user defined type id for specified Class - # @param klass [Class] Class to be serialized with specified type id - # @param class_method_name [Symbol] class method which returns an instance object - # - # @return nil - # - def register_type(type, klass, method_name, &block) - end - - # - # Returns a list of registered types, ordered by type id. - # Each element is a Hash object includes keys :type, :class and :unpacker. - # - # @return Array - # - def registered_types - end - - # - # Returns true/false which indicate specified class or type id is registered or not. - # - # @param klass_or_type [Class or Fixnum] Class or type id (0-127) to be checked - # @return true or false - # - def type_registered?(klass_or_type) - end - - # - # Internal buffer - # - # @return [MessagePack::Buffer] - # - attr_reader :buffer - - # - # Deserializes an object from the io or internal buffer and returns it. - # - # This method reads data from io into the internal buffer and deserializes an object - # from the buffer. It repeats reading data from the io until enough data is available - # to deserialize at least one object. After deserializing one object, unused data is - # left in the internal buffer. - # - # If there're not enough data to deserialize one object, this method raises EOFError. - # If data format is invalid, this method raises MessagePack::MalformedFormatError. - # If the object nests too deeply, this method raises MessagePack::StackError. - # - # @return [Object] deserialized object - # - def read - end - - alias unpack read - - # - # Deserializes an object and ignores it. This method is faster than _read_. - # - # This method could raise the same errors with _read_. - # - # @return nil - # - def skip - end - - # - # Deserializes a nil value if it exists and returns _true_. - # Otherwise, if a byte exists but the byte doesn't represent nil value, - # returns _false_. - # - # If there're not enough data, this method raises EOFError. - # - # @return [Boolean] - # - def skip_nil - end - - # - # Read a header of an array and returns its size. - # It converts a serialized array into a stream of elements. - # - # If the serialized object is not an array, it raises MessagePack::UnexpectedTypeError. - # If there're not enough data, this method raises EOFError. - # - # @return [Integer] size of the array - # - def read_array_header - end - - # - # Reads a header of an map and returns its size. - # It converts a serialized map into a stream of key-value pairs. - # - # If the serialized object is not a map, it raises MessagePack::UnexpectedTypeError. - # If there're not enough data, this method raises EOFError. - # - # @return [Integer] size of the map - # - def read_map_header - end - - # - # Appends data into the internal buffer. - # This method is equivalent to unpacker.buffer.append(data). - # - # @param data [String] - # @return [Unpacker] self - # - def feed(data) - end - - # - # Repeats to deserialize objects. - # - # It repeats until the io or internal buffer does not include any complete objects. - # - # If an IO is set, it repeats to read data from the IO when the buffer - # becomes empty until the IO raises EOFError. - # - # This method could raise same errors with _read_ excepting EOFError. - # - # @yieldparam object [Object] deserialized object - # @return nil - # - def each(&block) - end - - # - # Appends data into the internal buffer and repeats to deserialize objects. - # This method is equivalent to unpacker.feed(data) && unpacker.each { ... }. - # - # @param data [String] - # @yieldparam object [Object] deserialized object - # @return nil - # - def feed_each(data, &block) - end - - # - # Clears the internal buffer and resets deserialization state of the unpacker. - # - # @return nil - # - def reset - end - end - -end diff --git a/ext/java/org/msgpack/jruby/Buffer.java b/ext/java/org/msgpack/jruby/Buffer.java deleted file mode 100644 index bd5c72a5..00000000 --- a/ext/java/org/msgpack/jruby/Buffer.java +++ /dev/null @@ -1,233 +0,0 @@ -package org.msgpack.jruby; - - -import java.nio.ByteBuffer; - -import org.jruby.Ruby; -import org.jruby.RubyClass; -import org.jruby.RubyObject; -import org.jruby.RubyHash; -import org.jruby.RubyIO; -import org.jruby.RubyInteger; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.anno.JRubyClass; -import org.jruby.anno.JRubyMethod; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.ObjectAllocator; -import org.jruby.util.ByteList; - -import org.jcodings.Encoding; - - -@JRubyClass(name="MessagePack::Buffer") -public class Buffer extends RubyObject { - private static final long serialVersionUID = 8441244627425629412L; - private transient IRubyObject io; - private transient ByteBuffer buffer; - private boolean writeMode; - private transient Encoding binaryEncoding; - - private static final int CACHE_LINE_SIZE = 64; - private static final int ARRAY_HEADER_SIZE = 24; - - public Buffer(Ruby runtime, RubyClass type) { - super(runtime, type); - } - - static class BufferAllocator implements ObjectAllocator { - public IRubyObject allocate(Ruby runtime, RubyClass type) { - return new Buffer(runtime, type); - } - } - - @JRubyMethod(name = "initialize", optional = 2) - public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) { - if (args.length > 0) { - IRubyObject io = args[0]; - if (io.respondsTo("close") && (io.respondsTo("read") || (io.respondsTo("write") && io.respondsTo("flush")))) { - this.io = io; - } - } - this.buffer = ByteBuffer.allocate(CACHE_LINE_SIZE - ARRAY_HEADER_SIZE); - this.writeMode = true; - this.binaryEncoding = ctx.runtime.getEncodingService().getAscii8bitEncoding(); - return this; - } - - private void ensureRemainingCapacity(int c) { - if (!writeMode) { - buffer.compact(); - writeMode = true; - } - if (buffer.remaining() < c) { - int newLength = Math.max(buffer.capacity() + (buffer.capacity() >> 1), buffer.capacity() + c); - newLength += CACHE_LINE_SIZE - ((ARRAY_HEADER_SIZE + newLength) % CACHE_LINE_SIZE); - buffer = ByteBuffer.allocate(newLength).put(buffer.array(), 0, buffer.position()); - } - } - - private void ensureReadMode() { - if (writeMode) { - buffer.flip(); - writeMode = false; - } - } - - private int rawSize() { - if (writeMode) { - return buffer.position(); - } else { - return buffer.limit() - buffer.position(); - } - } - - @JRubyMethod(name = "clear") - public IRubyObject clear(ThreadContext ctx) { - if (!writeMode) { - buffer.compact(); - writeMode = true; - } - buffer.clear(); - return ctx.runtime.getNil(); - } - - @JRubyMethod(name = "size") - public IRubyObject size(ThreadContext ctx) { - return ctx.runtime.newFixnum(rawSize()); - } - - @JRubyMethod(name = "empty?") - public IRubyObject isEmpty(ThreadContext ctx) { - return rawSize() == 0 ? ctx.runtime.getTrue() : ctx.runtime.getFalse(); - } - - private IRubyObject bufferWrite(ThreadContext ctx, IRubyObject str) { - ByteList bytes = str.asString().getByteList(); - int length = bytes.length(); - ensureRemainingCapacity(length); - buffer.put(bytes.unsafeBytes(), bytes.begin(), length); - return ctx.runtime.newFixnum(length); - - } - - @JRubyMethod(name = "write", alias = {"<<"}) - public IRubyObject write(ThreadContext ctx, IRubyObject str) { - if (io == null) { - return bufferWrite(ctx, str); - } else { - return io.callMethod(ctx, "write", str); - } - } - - private void feed(ThreadContext ctx) { - if (io != null) { - bufferWrite(ctx, io.callMethod(ctx, "read")); - } - } - - private IRubyObject readCommon(ThreadContext ctx, IRubyObject[] args, boolean raiseOnUnderflow) { - feed(ctx); - int length = rawSize(); - if (args != null && args.length == 1) { - length = (int) args[0].convertToInteger().getLongValue(); - } - if (raiseOnUnderflow && rawSize() < length) { - throw ctx.runtime.newEOFError(); - } - int readLength = Math.min(length, rawSize()); - if (readLength == 0 && length > 0) { - return ctx.runtime.getNil(); - } else if (readLength == 0) { - return ctx.runtime.newString(); - } else { - ensureReadMode(); - byte[] bytes = new byte[readLength]; - buffer.get(bytes); - ByteList byteList = new ByteList(bytes, binaryEncoding); - return ctx.runtime.newString(byteList); - } - } - - @JRubyMethod(name = "read", optional = 1) - public IRubyObject read(ThreadContext ctx, IRubyObject[] args) { - return readCommon(ctx, args, false); - } - - @JRubyMethod(name = "read_all", optional = 1) - public IRubyObject readAll(ThreadContext ctx, IRubyObject[] args) { - return readCommon(ctx, args, true); - } - - private IRubyObject skipCommon(ThreadContext ctx, IRubyObject _length, boolean raiseOnUnderflow) { - feed(ctx); - int length = (int) _length.convertToInteger().getLongValue(); - if (raiseOnUnderflow && rawSize() < length) { - throw ctx.runtime.newEOFError(); - } - ensureReadMode(); - int skipLength = Math.min(length, rawSize()); - buffer.position(buffer.position() + skipLength); - return ctx.runtime.newFixnum(skipLength); - } - - @JRubyMethod(name = "skip") - public IRubyObject skip(ThreadContext ctx, IRubyObject length) { - return skipCommon(ctx, length, false); - } - - @JRubyMethod(name = "skip_all") - public IRubyObject skipAll(ThreadContext ctx, IRubyObject length) { - return skipCommon(ctx, length, true); - } - - public boolean hasIo() { - return io != null; - } - - @JRubyMethod(name = "to_s", alias = {"to_str"}) - public IRubyObject toS(ThreadContext ctx) { - ensureReadMode(); - int length = buffer.limit() - buffer.position(); - ByteList str = new ByteList(buffer.array(), buffer.position(), length, binaryEncoding, true); - return ctx.runtime.newString(str); - } - - @JRubyMethod(name = "to_a") - public IRubyObject toA(ThreadContext ctx) { - return ctx.runtime.newArray(toS(ctx)); - } - - @JRubyMethod(name = "io") - public IRubyObject getIo(ThreadContext ctx) { - return io == null ? ctx.runtime.getNil() : io; - } - - @JRubyMethod(name = "flush") - public IRubyObject flush(ThreadContext ctx) { - if (io == null) { - return ctx.runtime.getNil(); - } else { - return io.callMethod(ctx, "flush"); - } - } - - @JRubyMethod(name = "close") - public IRubyObject close(ThreadContext ctx) { - if (io == null) { - return ctx.runtime.getNil(); - } else { - return io.callMethod(ctx, "close"); - } - } - - @JRubyMethod(name = "write_to") - public IRubyObject writeTo(ThreadContext ctx, IRubyObject io) { - return io.callMethod(ctx, "write", readCommon(ctx, null, false)); - } - - public ByteList getBytes() { - byte[] bytes = new byte[rawSize()]; - buffer.get(bytes); - return new ByteList(bytes, binaryEncoding); - } -} diff --git a/ext/java/org/msgpack/jruby/Decoder.java b/ext/java/org/msgpack/jruby/Decoder.java deleted file mode 100644 index 9ea35b49..00000000 --- a/ext/java/org/msgpack/jruby/Decoder.java +++ /dev/null @@ -1,307 +0,0 @@ -package org.msgpack.jruby; - - -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.nio.BufferUnderflowException; -import java.util.Iterator; -import java.util.Arrays; - -import org.jruby.Ruby; -import org.jruby.RubyObject; -import org.jruby.RubyClass; -import org.jruby.RubyBignum; -import org.jruby.RubyString; -import org.jruby.RubyArray; -import org.jruby.RubyHash; -import org.jruby.RubyInteger; -import org.jruby.exceptions.RaiseException; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.util.ByteList; - -import org.jcodings.Encoding; -import org.jcodings.specific.UTF8Encoding; - -import static org.msgpack.jruby.Types.*; - - -public class Decoder implements Iterator<IRubyObject> { - private final Ruby runtime; - private final Encoding binaryEncoding; - private final Encoding utf8Encoding; - private final RubyClass unpackErrorClass; - private final RubyClass underflowErrorClass; - private final RubyClass malformedFormatErrorClass; - private final RubyClass stackErrorClass; - private final RubyClass unexpectedTypeErrorClass; - private final RubyClass unknownExtTypeErrorClass; - - private Unpacker unpacker; - private ByteBuffer buffer; - private boolean symbolizeKeys; - private boolean freeze; - private boolean allowUnknownExt; - - public Decoder(Ruby runtime) { - this(runtime, null, new byte[] {}, 0, 0, false, false, false); - } - - public Decoder(Ruby runtime, Unpacker unpacker) { - this(runtime, unpacker, new byte[] {}, 0, 0, false, false, false); - } - - public Decoder(Ruby runtime, byte[] bytes) { - this(runtime, null, bytes, 0, bytes.length, false, false, false); - } - - public Decoder(Ruby runtime, Unpacker unpacker, byte[] bytes) { - this(runtime, unpacker, bytes, 0, bytes.length, false, false, false); - } - - public Decoder(Ruby runtime, Unpacker unpacker, byte[] bytes, boolean symbolizeKeys, boolean freeze, boolean allowUnknownExt) { - this(runtime, unpacker, bytes, 0, bytes.length, symbolizeKeys, freeze, allowUnknownExt); - } - - public Decoder(Ruby runtime, Unpacker unpacker, byte[] bytes, int offset, int length) { - this(runtime, unpacker, bytes, offset, length, false, false, false); - } - - public Decoder(Ruby runtime, Unpacker unpacker, byte[] bytes, int offset, int length, boolean symbolizeKeys, boolean freeze, boolean allowUnknownExt) { - this.runtime = runtime; - this.unpacker = unpacker; - this.symbolizeKeys = symbolizeKeys; - this.freeze = freeze; - this.allowUnknownExt = allowUnknownExt; - this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding(); - this.utf8Encoding = UTF8Encoding.INSTANCE; - this.unpackErrorClass = runtime.getModule("MessagePack").getClass("UnpackError"); - this.underflowErrorClass = runtime.getModule("MessagePack").getClass("UnderflowError"); - this.malformedFormatErrorClass = runtime.getModule("MessagePack").getClass("MalformedFormatError"); - this.stackErrorClass = runtime.getModule("MessagePack").getClass("StackError"); - this.unexpectedTypeErrorClass = runtime.getModule("MessagePack").getClass("UnexpectedTypeError"); - this.unknownExtTypeErrorClass = runtime.getModule("MessagePack").getClass("UnknownExtTypeError"); - this.symbolizeKeys = symbolizeKeys; - this.allowUnknownExt = allowUnknownExt; - feed(bytes, offset, length); - } - - public void feed(byte[] bytes) { - feed(bytes, 0, bytes.length); - } - - public void feed(byte[] bytes, int offset, int length) { - if (buffer == null) { - buffer = ByteBuffer.wrap(bytes, offset, length); - } else { - ByteBuffer newBuffer = ByteBuffer.allocate(buffer.remaining() + length); - newBuffer.put(buffer); - newBuffer.put(bytes, offset, length); - newBuffer.flip(); - buffer = newBuffer; - } - } - - public void reset() { - buffer = null; - } - - public int offset() { - return buffer.position(); - } - - private IRubyObject consumeUnsignedLong() { - long value = buffer.getLong(); - if (value < 0) { - return RubyBignum.newBignum(runtime, BigInteger.valueOf(value & ((1L<<63)-1)).setBit(63)); - } else { - return runtime.newFixnum(value); - } - } - - private IRubyObject consumeString(int size, Encoding encoding) { - byte[] bytes = readBytes(size); - ByteList byteList = new ByteList(bytes, encoding); - RubyString string = runtime.newString(byteList); - if (this.freeze) { - string = runtime.freezeAndDedupString(string); - } - return string; - } - - private IRubyObject consumeArray(int size) { - IRubyObject[] elements = new IRubyObject[size]; - for (int i = 0; i < size; i++) { - elements[i] = next(); - } - return runtime.newArray(elements); - } - - private IRubyObject consumeHash(int size) { - RubyHash hash = RubyHash.newHash(runtime); - for (int i = 0; i < size; i++) { - IRubyObject key = next(); - if (key instanceof RubyString) { - if (this.symbolizeKeys) { - key = ((RubyString) key).intern(); - } else { - key = runtime.freezeAndDedupString((RubyString) key); - } - } - - hash.fastASet(key, next()); - } - return hash; - } - - private IRubyObject consumeExtension(int size) { - int type = buffer.get(); - if (unpacker != null) { - ExtensionRegistry.ExtensionEntry entry = unpacker.lookupExtensionByTypeId(type); - if (entry != null) { - IRubyObject proc = entry.getUnpackerProc(); - if (entry.isRecursive()) { - return proc.callMethod(runtime.getCurrentContext(), "call", unpacker); - } else { - ByteList byteList = new ByteList(readBytes(size), runtime.getEncodingService().getAscii8bitEncoding()); - return proc.callMethod(runtime.getCurrentContext(), "call", runtime.newString(byteList)); - } - } - } - - if (this.allowUnknownExt) { - return ExtensionValue.newExtensionValue(runtime, type, readBytes(size)); - } - - throw runtime.newRaiseException(unknownExtTypeErrorClass, "unexpected extension type"); - } - - private byte[] readBytes(int size) { - byte[] payload = new byte[size]; - buffer.get(payload); - return payload; - } - - @Override - public void remove() { - throw new UnsupportedOperationException(); - } - - @Override - public boolean hasNext() { - return buffer.remaining() > 0; - } - - public IRubyObject read_array_header() { - int position = buffer.position(); - try { - byte b = buffer.get(); - if ((b & 0xf0) == 0x90) { - return runtime.newFixnum(b & 0x0f); - } else if (b == ARY16) { - return runtime.newFixnum(buffer.getShort() & 0xffff); - } else if (b == ARY32) { - return runtime.newFixnum(buffer.getInt()); - } - throw runtime.newRaiseException(unexpectedTypeErrorClass, "unexpected type"); - } catch (RaiseException re) { - buffer.position(position); - throw re; - } catch (BufferUnderflowException bue) { - buffer.position(position); - throw runtime.newRaiseException(underflowErrorClass, "Not enough bytes available"); - } - } - - public IRubyObject read_map_header() { - int position = buffer.position(); - try { - byte b = buffer.get(); - if ((b & 0xf0) == 0x80) { - return runtime.newFixnum(b & 0x0f); - } else if (b == MAP16) { - return runtime.newFixnum(buffer.getShort() & 0xffff); - } else if (b == MAP32) { - return runtime.newFixnum(buffer.getInt()); - } - throw runtime.newRaiseException(unexpectedTypeErrorClass, "unexpected type"); - } catch (RaiseException re) { - buffer.position(position); - throw re; - } catch (BufferUnderflowException bue) { - buffer.position(position); - throw runtime.newRaiseException(underflowErrorClass, "Not enough bytes available"); - } - } - - @Override - public IRubyObject next() { - IRubyObject next = consumeNext(); - if (freeze) { - next.setFrozen(true); - } - return next; - } - - private IRubyObject consumeNext() { - int position = buffer.position(); - try { - byte b = buffer.get(); - outer: switch ((b >> 4) & 0xf) { - case 0x8: return consumeHash(b & 0x0f); - case 0x9: return consumeArray(b & 0x0f); - case 0xa: - case 0xb: return consumeString(b & 0x1f, utf8Encoding); - case 0xc: - switch (b) { - case NIL: return runtime.getNil(); - case FALSE: return runtime.getFalse(); - case TRUE: return runtime.getTrue(); - case BIN8: return consumeString(buffer.get() & 0xff, binaryEncoding); - case BIN16: return consumeString(buffer.getShort() & 0xffff, binaryEncoding); - case BIN32: return consumeString(buffer.getInt(), binaryEncoding); - case VAREXT8: return consumeExtension(buffer.get() & 0xff); - case VAREXT16: return consumeExtension(buffer.getShort() & 0xffff); - case VAREXT32: return consumeExtension(buffer.getInt()); - case FLOAT32: return runtime.newFloat(buffer.getFloat()); - case FLOAT64: return runtime.newFloat(buffer.getDouble()); - case UINT8: return runtime.newFixnum(buffer.get() & 0xffL); - case UINT16: return runtime.newFixnum(buffer.getShort() & 0xffffL); - case UINT32: return runtime.newFixnum(buffer.getInt() & 0xffffffffL); - case UINT64: return consumeUnsignedLong(); - default: break outer; - } - case 0xd: - switch (b) { - case INT8: return runtime.newFixnum(buffer.get()); - case INT16: return runtime.newFixnum(buffer.getShort()); - case INT32: return runtime.newFixnum(buffer.getInt()); - case INT64: return runtime.newFixnum(buffer.getLong()); - case FIXEXT1: return consumeExtension(1); - case FIXEXT2: return consumeExtension(2); - case FIXEXT4: return consumeExtension(4); - case FIXEXT8: return consumeExtension(8); - case FIXEXT16: return consumeExtension(16); - case STR8: return consumeString(buffer.get() & 0xff, utf8Encoding); - case STR16: return consumeString(buffer.getShort() & 0xffff, utf8Encoding); - case STR32: return consumeString(buffer.getInt(), utf8Encoding); - case ARY16: return consumeArray(buffer.getShort() & 0xffff); - case ARY32: return consumeArray(buffer.getInt()); - case MAP16: return consumeHash(buffer.getShort() & 0xffff); - case MAP32: return consumeHash(buffer.getInt()); - default: break outer; - } - case 0xe: - case 0xf: return runtime.newFixnum((0x1f & b) - 0x20); - default: return runtime.newFixnum(b); - } - buffer.position(position); - throw runtime.newRaiseException(malformedFormatErrorClass, "Illegal byte sequence"); - } catch (RaiseException re) { - buffer.position(position); - throw re; - } catch (BufferUnderflowException bue) { - buffer.position(position); - throw runtime.newRaiseException(underflowErrorClass, "Not enough bytes available"); - } - } -} diff --git a/ext/java/org/msgpack/jruby/Encoder.java b/ext/java/org/msgpack/jruby/Encoder.java deleted file mode 100644 index 08fd01b7..00000000 --- a/ext/java/org/msgpack/jruby/Encoder.java +++ /dev/null @@ -1,456 +0,0 @@ -package org.msgpack.jruby; - - -import java.math.BigInteger; -import java.nio.ByteBuffer; -import java.util.Arrays; - -import org.jruby.Ruby; -import org.jruby.RubyObject; -import org.jruby.RubyModule; -import org.jruby.RubyNil; -import org.jruby.RubyBoolean; -import org.jruby.RubyNumeric; -import org.jruby.RubyBignum; -import org.jruby.RubyInteger; -import org.jruby.RubyFixnum; -import org.jruby.RubyFloat; -import org.jruby.RubyString; -import org.jruby.RubySymbol; -import org.jruby.RubyArray; -import org.jruby.RubyHash; -import org.jruby.RubyEncoding; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.util.ByteList; - -import org.jcodings.Encoding; -import org.jcodings.specific.UTF8Encoding; - -import static org.msgpack.jruby.Types.*; - -public class Encoder { - - private static final int CACHE_LINE_SIZE = 64; - private static final int ARRAY_HEADER_SIZE = 24; - - private final Ruby runtime; - private final Encoding binaryEncoding; - private final Encoding utf8Encoding; - private final boolean compatibilityMode; - private final ExtensionRegistry registry; - private final Packer packer; - - public boolean hasSymbolExtType; - private boolean hasBigintExtType; - private boolean recursiveExtension; - - private ByteBuffer buffer; - - public Encoder(Ruby runtime, Packer packer, boolean compatibilityMode, ExtensionRegistry registry, boolean hasSymbolExtType, boolean hasBigintExtType) { - this.packer = packer; - this.runtime = runtime; - this.buffer = ByteBuffer.allocate(CACHE_LINE_SIZE - ARRAY_HEADER_SIZE); - this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding(); - this.utf8Encoding = UTF8Encoding.INSTANCE; - this.compatibilityMode = compatibilityMode; - this.registry = registry; - this.hasSymbolExtType = hasSymbolExtType; - this.hasBigintExtType = hasBigintExtType; - } - - public boolean isCompatibilityMode() { - return compatibilityMode; - } - - private void ensureRemainingCapacity(int c) { - if (buffer.remaining() < c) { - int newLength = Math.max(buffer.capacity() + (buffer.capacity() >> 1), buffer.capacity() + c); - newLength += CACHE_LINE_SIZE - ((ARRAY_HEADER_SIZE + newLength) % CACHE_LINE_SIZE); - buffer = ByteBuffer.allocate(newLength).put(buffer.array(), 0, buffer.position()); - } - } - - private IRubyObject readRubyString() { - if (recursiveExtension) { - // If recursiveExtension is true, it means we re-entered encode, so we MUST NOT flush the buffer. - // Instead we return an empty string to act as a null object for the caller. The buffer will actually - // be flushed once we're done serializing the recursive extension. - // All other method that consume the buffer should do so through readRubyString or implement the same logic. - return runtime.newString(); - } else { - IRubyObject str = runtime.newString(new ByteList(buffer.array(), 0, buffer.position(), binaryEncoding, false)); - buffer.clear(); - return str; - } - } - - public IRubyObject encode(IRubyObject object) { - appendObject(object); - return readRubyString(); - } - - public IRubyObject encode(IRubyObject object, IRubyObject destination) { - appendObject(object, destination); - return readRubyString(); - } - - public IRubyObject encodeArrayHeader(int size) { - appendArrayHeader(size); - return readRubyString(); - } - - public IRubyObject encodeMapHeader(int size) { - appendHashHeader(size); - return readRubyString(); - } - - public IRubyObject encodeBinHeader(int size) { - appendStringHeader(size, true); - return readRubyString(); - } - - public IRubyObject encodeFloat32(RubyNumeric numeric) { - appendFloat32(numeric); - return readRubyString(); - } - - private void appendObject(IRubyObject object) { - appendObject(object, null); - } - - private void appendObject(IRubyObject object, IRubyObject destination) { - if (object == null || object instanceof RubyNil) { - ensureRemainingCapacity(1); - buffer.put(NIL); - } else if (object instanceof RubyBoolean) { - ensureRemainingCapacity(1); - buffer.put(((RubyBoolean) object).isTrue() ? TRUE : FALSE); - } else if (object instanceof RubyBignum) { - appendBignum((RubyBignum) object); - } else if (object instanceof RubyInteger) { - appendInteger((RubyInteger) object); - } else if (object instanceof RubyFloat) { - appendFloat((RubyFloat) object); - } else if (object instanceof RubyString) { - if (object.getType() == runtime.getString() || !tryAppendWithExtTypeLookup(object)) { - appendString((RubyString) object); - } - } else if (object instanceof RubySymbol) { - if (hasSymbolExtType) { - appendOther(object, destination); - } else { - appendString(((RubySymbol) object).asString()); - } - } else if (object instanceof RubyArray) { - if (object.getType() == runtime.getArray() || !tryAppendWithExtTypeLookup(object)) { - appendArray((RubyArray) object); - } - } else if (object instanceof RubyHash) { - if (object.getType() == runtime.getHash() || !tryAppendWithExtTypeLookup(object)) { - appendHash((RubyHash) object); - } - } else if (object instanceof ExtensionValue) { - appendExtensionValue((ExtensionValue) object); - } else { - appendOther(object, destination); - } - } - - private void appendBignum(RubyBignum object) { - BigInteger value = object.getBigIntegerValue(); - if (value.compareTo(RubyBignum.LONG_MIN) < 0 || value.compareTo(RubyBignum.LONG_MAX) > 0) { - if (value.bitLength() > 64 || (value.bitLength() > 63 && value.signum() < 0)) { - if (hasBigintExtType && tryAppendWithExtTypeLookup(object)) { - return; - } - throw runtime.newRangeError(String.format("Cannot pack big integer: %s", value)); - } - ensureRemainingCapacity(9); - buffer.put(value.signum() < 0 ? INT64 : UINT64); - byte[] b = value.toByteArray(); - buffer.put(b, b.length - 8, 8); - } else { - appendInteger(object); - } - } - - private void appendInteger(RubyInteger object) { - long value = object.getLongValue(); - if (value < 0) { - if (value < Short.MIN_VALUE) { - if (value < Integer.MIN_VALUE) { - ensureRemainingCapacity(9); - buffer.put(INT64); - buffer.putLong(value); - } else { - ensureRemainingCapacity(5); - buffer.put(INT32); - buffer.putInt((int) value); - } - } else if (value >= -0x20L) { - ensureRemainingCapacity(1); - byte b = (byte) (value | 0xe0); - buffer.put(b); - } else if (value < Byte.MIN_VALUE) { - ensureRemainingCapacity(3); - buffer.put(INT16); - buffer.putShort((short) value); - } else { - ensureRemainingCapacity(2); - buffer.put(INT8); - buffer.put((byte) value); - } - } else { - if (value < 0x10000L) { - if (value < 128L) { - ensureRemainingCapacity(1); - buffer.put((byte) value); - } else if (value < 0x100L) { - ensureRemainingCapacity(2); - buffer.put(UINT8); - buffer.put((byte) value); - } else { - ensureRemainingCapacity(3); - buffer.put(UINT16); - buffer.putShort((short) value); - } - } else if (value < 0x100000000L) { - ensureRemainingCapacity(5); - buffer.put(UINT32); - buffer.putInt((int) value); - } else { - ensureRemainingCapacity(9); - buffer.put(INT64); - buffer.putLong(value); - } - } - } - - private void appendFloat(RubyFloat object) { - double value = object.getDoubleValue(); - //TODO: msgpack-ruby original does encode this value as Double, not float - // float f = (float) value; - // if (Double.compare(f, value) == 0) { - // ensureRemainingCapacity(5); - // buffer.put(FLOAT32); - // buffer.putFloat(f); - // } else { - ensureRemainingCapacity(9); - buffer.put(FLOAT64); - buffer.putDouble(value); - // } - } - - private void appendFloat32(RubyNumeric object) { - float value = (float) object.getDoubleValue(); - ensureRemainingCapacity(5); - buffer.put(FLOAT32); - buffer.putFloat(value); - } - - private void appendStringHeader(int length, boolean binary) { - if (length < 32 && !binary) { - ensureRemainingCapacity(1 + length); - buffer.put((byte) (length | FIXSTR)); - } else if (length <= 0xff && !compatibilityMode) { - ensureRemainingCapacity(2 + length); - buffer.put(binary ? BIN8 : STR8); - buffer.put((byte) length); - } else if (length <= 0xffff) { - ensureRemainingCapacity(3 + length); - buffer.put(binary ? BIN16 : STR16); - buffer.putShort((short) length); - } else { - ensureRemainingCapacity(5 + length); - buffer.put(binary ? BIN32 : STR32); - buffer.putInt(length); - } - } - - private void appendString(RubyString object) { - Encoding encoding = object.getEncoding(); - boolean binary = !compatibilityMode && encoding == binaryEncoding; - if (encoding != utf8Encoding && encoding != binaryEncoding) { - object = (RubyString)(object).encode(runtime.getCurrentContext(), runtime.getEncodingService().getEncoding(utf8Encoding)); - } - ByteList bytes = object.getByteList(); - int length = bytes.length(); - appendStringHeader(length, binary); - buffer.put(bytes.unsafeBytes(), bytes.begin(), length); - } - - private void appendArray(RubyArray<?> object) { - appendArrayHeader(object); - appendArrayElements(object); - } - - private void appendArrayHeader(RubyArray<?> object) { - appendArrayHeader(object.size()); - } - - private void appendArrayHeader(int size) { - if (size < 16) { - ensureRemainingCapacity(1); - buffer.put((byte) (size | 0x90)); - } else if (size < 0x10000) { - ensureRemainingCapacity(3); - buffer.put(ARY16); - buffer.putShort((short) size); - } else { - ensureRemainingCapacity(5); - buffer.put(ARY32); - buffer.putInt(size); - } - } - - private void appendArrayElements(RubyArray<?> object) { - int size = object.size(); - for (int i = 0; i < size; i++) { - appendObject(object.eltOk(i)); - } - } - - private void appendHash(RubyHash object) { - appendHashHeader(object); - appendHashElements(object); - } - - private void appendHashHeader(RubyHash object) { - appendHashHeader(object.size()); - } - - private void appendHashHeader(int size) { - if (size < 16) { - ensureRemainingCapacity(1); - buffer.put((byte) (size | 0x80)); - } else if (size < 0x10000) { - ensureRemainingCapacity(3); - buffer.put(MAP16); - buffer.putShort((short) size); - } else { - ensureRemainingCapacity(5); - buffer.put(MAP32); - buffer.putInt(size); - } - } - - private void appendHashElements(RubyHash object) { - int size = object.size(); - HashVisitor visitor = new HashVisitor(size); - object.visitAll(visitor); - if (visitor.remain != 0) { - object.getRuntime().newConcurrencyError("Hash size changed while packing"); - } - } - - private class HashVisitor extends RubyHash.Visitor { - public int remain; - - public HashVisitor(int size) { - remain = size; - } - - public void visit(IRubyObject key, IRubyObject value) { - if (remain-- > 0) { - appendObject(key); - appendObject(value); - } - } - } - - private void appendExt(int type, ByteList payloadBytes) { - int payloadSize = payloadBytes.length(); - int outputSize = 0; - boolean fixSize = payloadSize == 1 || payloadSize == 2 || payloadSize == 4 || payloadSize == 8 || payloadSize == 16; - if (fixSize) { - outputSize = 2 + payloadSize; - } else if (payloadSize < 0x100) { - outputSize = 3 + payloadSize; - } else if (payloadSize < 0x10000) { - outputSize = 4 + payloadSize; - } else { - outputSize = 6 + payloadSize; - } - ensureRemainingCapacity(outputSize); - if (payloadSize == 1) { - buffer.put(FIXEXT1); - } else if (payloadSize == 2) { - buffer.put(FIXEXT2); - } else if (payloadSize == 4) { - buffer.put(FIXEXT4); - } else if (payloadSize == 8) { - buffer.put(FIXEXT8); - } else if (payloadSize == 16) { - buffer.put(FIXEXT16); - } else if (payloadSize < 0x100) { - buffer.put(VAREXT8); - buffer.put((byte) payloadSize); - } else if (payloadSize < 0x10000) { - buffer.put(VAREXT16); - buffer.putShort((short) payloadSize); - } else { - buffer.put(VAREXT32); - buffer.putInt(payloadSize); - } - buffer.put((byte) type); - buffer.put(payloadBytes.unsafeBytes(), payloadBytes.begin(), payloadSize); - } - - private void appendExtensionValue(ExtensionValue object) { - long type = ((RubyFixnum)object.get_type()).getLongValue(); - if (type < -128 || type > 127) { - throw object.getRuntime().newRangeError(String.format("integer %d too big to convert to `signed char'", type)); - } - ByteList payloadBytes = ((RubyString)object.payload()).getByteList(); - appendExt((int) type, payloadBytes); - } - - private boolean tryAppendWithExtTypeLookup(IRubyObject object) { - if (registry != null) { - ExtensionRegistry.ExtensionEntry entry = registry.lookupExtensionForObject(object); - if (entry != null) { - IRubyObject proc = entry.getPackerProc(); - int type = entry.getTypeId(); - - if (entry.isRecursive()) { - ByteBuffer oldBuffer = buffer; - buffer = ByteBuffer.allocate(CACHE_LINE_SIZE - ARRAY_HEADER_SIZE); - boolean previousRecursiveExtension = recursiveExtension; - recursiveExtension = true; - - ByteList payload; - try { - IRubyObject args[] = { object, packer }; - proc.callMethod(runtime.getCurrentContext(), "call", args); - payload = new ByteList(buffer.array(), 0, buffer.position(), binaryEncoding, false); - } finally { - recursiveExtension = previousRecursiveExtension; - buffer = oldBuffer; - } - appendExt(type, payload); - } else { - RubyString bytes = proc.callMethod(runtime.getCurrentContext(), "call", object).asString(); - appendExt(type, bytes.getByteList()); - } - return true; - } - } - return false; - } - - private void appendOther(IRubyObject object, IRubyObject destination) { - if (!tryAppendWithExtTypeLookup(object)) { appendCustom(object, destination); } - } - - private void appendCustom(IRubyObject object, IRubyObject destination) { - if (destination == null) { - IRubyObject result = object.callMethod(runtime.getCurrentContext(), "to_msgpack"); - ByteList bytes = result.asString().getByteList(); - int length = bytes.length(); - ensureRemainingCapacity(length); - buffer.put(bytes.unsafeBytes(), bytes.begin(), length); - } else { - object.callMethod(runtime.getCurrentContext(), "to_msgpack", destination); - } - } -} diff --git a/ext/java/org/msgpack/jruby/ExtensionRegistry.java b/ext/java/org/msgpack/jruby/ExtensionRegistry.java deleted file mode 100644 index aa31c882..00000000 --- a/ext/java/org/msgpack/jruby/ExtensionRegistry.java +++ /dev/null @@ -1,167 +0,0 @@ -package org.msgpack.jruby; - -import org.jruby.Ruby; -import org.jruby.RubyHash; -import org.jruby.RubyArray; -import org.jruby.RubyModule; -import org.jruby.RubyFixnum; -import org.jruby.RubySymbol; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.builtin.IRubyObject; - -import java.util.Map; -import java.util.HashMap; - -public class ExtensionRegistry { - private final Map<RubyModule, ExtensionEntry> extensionsByModule; - private final Map<RubyModule, ExtensionEntry> extensionsByAncestor; - private final ExtensionEntry[] extensionsByTypeId; - - public ExtensionRegistry() { - this(new HashMap<RubyModule, ExtensionEntry>(), new ExtensionEntry[256]); - } - - private ExtensionRegistry(Map<RubyModule, ExtensionEntry> extensionsByModule, ExtensionEntry[] extensionsByTypeId) { - this.extensionsByModule = new HashMap<RubyModule, ExtensionEntry>(extensionsByModule); - this.extensionsByAncestor = new HashMap<RubyModule, ExtensionEntry>(); - this.extensionsByTypeId = extensionsByTypeId.clone(); - } - - public ExtensionRegistry dup() { - return new ExtensionRegistry(extensionsByModule, extensionsByTypeId); - } - - public IRubyObject toInternalPackerRegistry(ThreadContext ctx) { - RubyHash hash = RubyHash.newHash(ctx.runtime); - for (RubyModule extensionModule : extensionsByModule.keySet()) { - ExtensionEntry entry = extensionsByModule.get(extensionModule); - if (entry.hasPacker()) { - hash.put(extensionModule, entry.toPackerTuple(ctx)); - } - } - return hash; - } - - public IRubyObject toInternalUnpackerRegistry(ThreadContext ctx) { - RubyHash hash = RubyHash.newHash(ctx.runtime); - for (int typeIdIndex = 0 ; typeIdIndex < 256 ; typeIdIndex++) { - ExtensionEntry entry = extensionsByTypeId[typeIdIndex]; - if (entry != null && entry.hasUnpacker()) { - IRubyObject typeId = RubyFixnum.newFixnum(ctx.runtime, typeIdIndex - 128); - hash.put(typeId, entry.toUnpackerTuple(ctx)); - } - } - return hash; - } - - public void put(RubyModule mod, int typeId, boolean recursive, IRubyObject packerProc, IRubyObject unpackerProc) { - ExtensionEntry entry = new ExtensionEntry(mod, typeId, recursive, packerProc, unpackerProc); - extensionsByModule.put(mod, entry); - extensionsByTypeId[typeId + 128] = entry; - extensionsByAncestor.clear(); - } - - public ExtensionEntry lookupExtensionByTypeId(int typeId) { - ExtensionEntry e = extensionsByTypeId[typeId + 128]; - if (e != null && e.hasUnpacker()) { - return e; - } - return null; - } - - public ExtensionEntry lookupExtensionForObject(IRubyObject object) { - RubyModule lookupClass = null; - ExtensionEntry entry = null; - /* - * Objects of type Integer (Fixnum, Bignum), Float, Symbol and frozen - * String have no singleton class and raise a TypeError when trying to get - * it. - */ - lookupClass = object.getMetaClass(); - entry = extensionsByModule.get(lookupClass); - if (entry != null && entry.hasPacker()) { - return entry; - } - - RubyModule realClass = object.getType(); - if (realClass != lookupClass) { - entry = extensionsByModule.get(realClass); - if (entry != null && entry.hasPacker()) { - return entry; - } - } - - entry = findEntryByModuleOrAncestor(lookupClass); - if (entry != null && entry.hasPacker()) { - return entry; - } - return null; - } - - private ExtensionEntry findEntryByModuleOrAncestor(final RubyModule mod) { - ThreadContext ctx = mod.getRuntime().getCurrentContext(); - for (RubyModule extensionModule : extensionsByModule.keySet()) { - RubyArray<?> ancestors = (RubyArray)mod.callMethod(ctx, "ancestors"); - if (ancestors.callMethod(ctx, "include?", extensionModule).isTrue()) { - return extensionsByModule.get(extensionModule); - } - } - return null; - } - - public static class ExtensionEntry { - private final RubyModule mod; - private final int typeId; - private final boolean recursive; - private final IRubyObject packerProc; - private final IRubyObject unpackerProc; - - public ExtensionEntry(RubyModule mod, int typeId, boolean recursive, IRubyObject packerProc, IRubyObject unpackerProc) { - this.mod = mod; - this.typeId = typeId; - this.recursive = recursive; - this.packerProc = packerProc; - this.unpackerProc = unpackerProc; - } - - public RubyModule getExtensionModule() { - return mod; - } - - public int getTypeId() { - return typeId; - } - - public boolean isRecursive() { - return recursive; - } - - public boolean hasPacker() { - return packerProc != null && !packerProc.isNil(); - } - - public boolean hasUnpacker() { - return unpackerProc != null && !unpackerProc.isNil(); - } - - public IRubyObject getPackerProc() { - return packerProc; - } - - public IRubyObject getUnpackerProc() { - return unpackerProc; - } - - public RubyArray<?> toPackerTuple(ThreadContext ctx) { - return ctx.runtime.newArray(new IRubyObject[] {ctx.runtime.newFixnum(typeId), packerProc}); - } - - public RubyArray<?> toUnpackerTuple(ThreadContext ctx) { - return ctx.runtime.newArray(new IRubyObject[] {mod, unpackerProc}); - } - - public IRubyObject[] toPackerProcTypeIdPair(ThreadContext ctx) { - return new IRubyObject[] {packerProc, ctx.runtime.newFixnum(typeId)}; - } - } -} diff --git a/ext/java/org/msgpack/jruby/ExtensionValue.java b/ext/java/org/msgpack/jruby/ExtensionValue.java deleted file mode 100644 index eeca8c27..00000000 --- a/ext/java/org/msgpack/jruby/ExtensionValue.java +++ /dev/null @@ -1,128 +0,0 @@ -package org.msgpack.jruby; - - -import java.util.Arrays; -import java.nio.ByteBuffer; - -import org.jruby.Ruby; -import org.jruby.RubyClass; -import org.jruby.RubyObject; -import org.jruby.RubyFixnum; -import org.jruby.RubyString; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.runtime.ObjectAllocator; -import org.jruby.runtime.ThreadContext; -import org.jruby.anno.JRubyClass; -import org.jruby.anno.JRubyMethod; -import org.jruby.util.ByteList; - -import static org.jruby.runtime.Visibility.PRIVATE; - -import org.jcodings.Encoding; - -import static org.msgpack.jruby.Types.*; - - -@JRubyClass(name="MessagePack::ExtensionValue") -public class ExtensionValue extends RubyObject { - private static final long serialVersionUID = 8451274621449322492L; - private transient final Encoding binaryEncoding; - - private RubyFixnum type; - private RubyString payload; - - public ExtensionValue(Ruby runtime, RubyClass type) { - super(runtime, type); - this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding(); - } - - public static class ExtensionValueAllocator implements ObjectAllocator { - public IRubyObject allocate(Ruby runtime, RubyClass klass) { - return new ExtensionValue(runtime, klass); - } - } - - public static ExtensionValue newExtensionValue(Ruby runtime, int type, byte[] payload) { - ExtensionValue v = new ExtensionValue(runtime, runtime.getModule("MessagePack").getClass("ExtensionValue")); - ByteList byteList = new ByteList(payload, runtime.getEncodingService().getAscii8bitEncoding()); - v.initialize(runtime.getCurrentContext(), runtime.newFixnum(type), runtime.newString(byteList)); - return v; - } - - @JRubyMethod(name = "initialize", required = 2, visibility = PRIVATE) - public IRubyObject initialize(ThreadContext ctx, IRubyObject type, IRubyObject payload) { - this.type = (RubyFixnum) type; - this.payload = (RubyString) payload; - return this; - } - - @JRubyMethod(name = {"to_s", "inspect"}) - @Override - public IRubyObject to_s() { - IRubyObject payloadStr = payload.callMethod(getRuntime().getCurrentContext(), "inspect"); - return getRuntime().newString(String.format("#<MessagePack::ExtensionValue @type=%d, @payload=%s>", type.getLongValue(), payloadStr)); - } - - @JRubyMethod(name = "hash") - @Override - public RubyFixnum hash() { - long hash = payload.hashCode() ^ (type.getLongValue() << 56); - return RubyFixnum.newFixnum(getRuntime(), hash); - } - - @JRubyMethod(name = "eql?") - public IRubyObject eql_p(ThreadContext ctx, IRubyObject o) { - Ruby runtime = ctx.runtime; - if (this == o) { - return runtime.getTrue(); - } - if (o instanceof ExtensionValue) { - ExtensionValue other = (ExtensionValue) o; - if (!this.type.eql_p(other.type).isTrue()) { - return runtime.getFalse(); - } else { - return this.payload.str_eql_p(ctx, other.payload); - } - } - return runtime.getFalse(); - } - - @JRubyMethod(name = "==") - public IRubyObject op_equal(ThreadContext ctx, IRubyObject o) { - Ruby runtime = ctx.runtime; - if (this == o) { - return runtime.getTrue(); - } - if (o instanceof ExtensionValue) { - ExtensionValue other = (ExtensionValue) o; - if (!this.type.op_equal(ctx, other.type).isTrue()) { - return runtime.getFalse(); - } else { - return this.payload.op_equal(ctx, other.payload); - } - } - return runtime.getFalse(); - } - - @JRubyMethod(name = "type") - public IRubyObject get_type() { - return type; - } - - @JRubyMethod - public IRubyObject payload() { - return payload; - } - - @JRubyMethod(name = "type=", required = 1) - public IRubyObject set_type(final IRubyObject tpe) { - type = (RubyFixnum)tpe; - return tpe; - } - - @JRubyMethod(name = "payload=", required = 1) - public IRubyObject set_payload(final IRubyObject pld) { - payload = (RubyString)pld; - return pld; - } -} diff --git a/ext/java/org/msgpack/jruby/Factory.java b/ext/java/org/msgpack/jruby/Factory.java deleted file mode 100644 index 5973f8fb..00000000 --- a/ext/java/org/msgpack/jruby/Factory.java +++ /dev/null @@ -1,130 +0,0 @@ -package org.msgpack.jruby; - - -import org.jruby.Ruby; -import org.jruby.RubyModule; -import org.jruby.RubyClass; -import org.jruby.RubyObject; -import org.jruby.RubyArray; -import org.jruby.RubyHash; -import org.jruby.RubyIO; -import org.jruby.RubyInteger; -import org.jruby.RubyFixnum; -import org.jruby.RubyString; -import org.jruby.RubySymbol; -import org.jruby.RubyProc; -import org.jruby.RubyMethod; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.anno.JRubyClass; -import org.jruby.anno.JRubyMethod; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.ObjectAllocator; -import org.jruby.util.ByteList; - -import static org.jruby.runtime.Visibility.PRIVATE; - -@JRubyClass(name="MessagePack::Factory") -public class Factory extends RubyObject { - private static final long serialVersionUID = 8441284623445322492L; - private transient final Ruby runtime; - private transient ExtensionRegistry extensionRegistry; - private boolean hasSymbolExtType; - private boolean hasBigIntExtType; - - public Factory(Ruby runtime, RubyClass type) { - super(runtime, type); - this.runtime = runtime; - this.extensionRegistry = new ExtensionRegistry(); - this.hasSymbolExtType = false; - this.hasBigIntExtType = false; - } - - static class FactoryAllocator implements ObjectAllocator { - public IRubyObject allocate(Ruby runtime, RubyClass type) { - return new Factory(runtime, type); - } - } - - public ExtensionRegistry extensionRegistry() { - return extensionRegistry.dup(); - } - - @JRubyMethod(name = "initialize") - public IRubyObject initialize(ThreadContext ctx) { - return this; - } - - @JRubyMethod(name = "dup") - public IRubyObject dup() { - Factory clone = (Factory)super.dup(); - clone.extensionRegistry = extensionRegistry(); - clone.hasSymbolExtType = hasSymbolExtType; - return clone; - } - - @JRubyMethod(name = "packer", optional = 2) - public Packer packer(ThreadContext ctx, IRubyObject[] args) { - return Packer.newPacker(ctx, extensionRegistry(), hasSymbolExtType, hasBigIntExtType, args); - } - - @JRubyMethod(name = "unpacker", optional = 2) - public Unpacker unpacker(ThreadContext ctx, IRubyObject[] args) { - return Unpacker.newUnpacker(ctx, extensionRegistry(), args); - } - - @JRubyMethod(name = "registered_types_internal", visibility = PRIVATE) - public IRubyObject registeredTypesInternal(ThreadContext ctx) { - return RubyArray.newArray(ctx.runtime, new IRubyObject[] { - extensionRegistry.toInternalPackerRegistry(ctx), - extensionRegistry.toInternalUnpackerRegistry(ctx) - }); - } - - @JRubyMethod(name = "register_type_internal", required = 3, visibility = PRIVATE) - public IRubyObject registerTypeInternal(ThreadContext ctx, IRubyObject type, IRubyObject mod, IRubyObject opts) { - testFrozen("MessagePack::Factory"); - - Ruby runtime = ctx.runtime; - RubyHash options = (RubyHash) opts; - - IRubyObject packerProc = options.fastARef(runtime.newSymbol("packer")); - IRubyObject unpackerProc = options.fastARef(runtime.newSymbol("unpacker")); - - long typeId = ((RubyFixnum) type).getLongValue(); - if (typeId < -128 || typeId > 127) { - throw runtime.newRangeError(String.format("integer %d too big to convert to `signed char'", typeId)); - } - - if (!(mod instanceof RubyModule)) { - throw runtime.newArgumentError(String.format("expected Module/Class but found %s.", mod.getType().getName())); - } - RubyModule extModule = (RubyModule) mod; - - boolean recursive = false; - if (options != null) { - IRubyObject recursiveExtensionArg = options.fastARef(runtime.newSymbol("recursive")); - if (recursiveExtensionArg != null && recursiveExtensionArg.isTrue()) { - recursive = true; - } - } - - extensionRegistry.put(extModule, (int) typeId, recursive, packerProc, unpackerProc); - - if (extModule == runtime.getSymbol() && !packerProc.isNil()) { - hasSymbolExtType = true; - } - - if (options != null) { - IRubyObject oversizedIntegerExtensionArg = options.fastARef(runtime.newSymbol("oversized_integer_extension")); - if (oversizedIntegerExtensionArg != null && oversizedIntegerExtensionArg.isTrue()) { - if (extModule == runtime.getModule("Integer")) { - hasBigIntExtType = true; - } else { - throw runtime.newArgumentError("oversized_integer_extension: true is only for Integer class"); - } - } - } - - return runtime.getNil(); - } -} diff --git a/ext/java/org/msgpack/jruby/MessagePackLibrary.java b/ext/java/org/msgpack/jruby/MessagePackLibrary.java deleted file mode 100644 index aef2caec..00000000 --- a/ext/java/org/msgpack/jruby/MessagePackLibrary.java +++ /dev/null @@ -1,45 +0,0 @@ -package org.msgpack.jruby; - - -import org.jruby.Ruby; -import org.jruby.RubyModule; -import org.jruby.RubyClass; -import org.jruby.RubyString; -import org.jruby.RubyNil; -import org.jruby.RubyBoolean; -import org.jruby.RubyHash; -import org.jruby.runtime.load.Library; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.Block; -import org.jruby.runtime.Visibility; -import org.jruby.anno.JRubyModule; -import org.jruby.anno.JRubyMethod; -import org.jruby.internal.runtime.methods.CallConfiguration; -import org.jruby.internal.runtime.methods.DynamicMethod; - - -public class MessagePackLibrary implements Library { - public void load(Ruby runtime, boolean wrap) { - RubyModule msgpackModule = runtime.defineModule("MessagePack"); - RubyClass standardErrorClass = runtime.getStandardError(); - RubyClass unpackErrorClass = msgpackModule.defineClassUnder("UnpackError", standardErrorClass, standardErrorClass.getAllocator()); - RubyClass underflowErrorClass = msgpackModule.defineClassUnder("UnderflowError", unpackErrorClass, unpackErrorClass.getAllocator()); - RubyClass malformedFormatErrorClass = msgpackModule.defineClassUnder("MalformedFormatError", unpackErrorClass, unpackErrorClass.getAllocator()); - RubyClass stackErrorClass = msgpackModule.defineClassUnder("StackError", unpackErrorClass, unpackErrorClass.getAllocator()); - RubyModule typeErrorModule = msgpackModule.defineModuleUnder("TypeError"); - RubyClass unexpectedTypeErrorClass = msgpackModule.defineClassUnder("UnexpectedTypeError", unpackErrorClass, unpackErrorClass.getAllocator()); - unexpectedTypeErrorClass.includeModule(typeErrorModule); - RubyClass unknownExtTypeErrorClass = msgpackModule.defineClassUnder("UnknownExtTypeError", unpackErrorClass, unpackErrorClass.getAllocator()); - RubyClass extensionValueClass = msgpackModule.defineClassUnder("ExtensionValue", runtime.getObject(), new ExtensionValue.ExtensionValueAllocator()); - extensionValueClass.defineAnnotatedMethods(ExtensionValue.class); - RubyClass packerClass = msgpackModule.defineClassUnder("Packer", runtime.getObject(), new Packer.PackerAllocator()); - packerClass.defineAnnotatedMethods(Packer.class); - RubyClass unpackerClass = msgpackModule.defineClassUnder("Unpacker", runtime.getObject(), new Unpacker.UnpackerAllocator()); - unpackerClass.defineAnnotatedMethods(Unpacker.class); - RubyClass bufferClass = msgpackModule.defineClassUnder("Buffer", runtime.getObject(), new Buffer.BufferAllocator()); - bufferClass.defineAnnotatedMethods(Buffer.class); - RubyClass factoryClass = msgpackModule.defineClassUnder("Factory", runtime.getObject(), new Factory.FactoryAllocator()); - factoryClass.defineAnnotatedMethods(Factory.class); - } -} diff --git a/ext/java/org/msgpack/jruby/Packer.java b/ext/java/org/msgpack/jruby/Packer.java deleted file mode 100644 index 040ec588..00000000 --- a/ext/java/org/msgpack/jruby/Packer.java +++ /dev/null @@ -1,266 +0,0 @@ -package org.msgpack.jruby; - - -import org.jruby.Ruby; -import org.jruby.RubyModule; -import org.jruby.RubyClass; -import org.jruby.RubyObject; -import org.jruby.RubyArray; -import org.jruby.RubyHash; -import org.jruby.RubyIO; -import org.jruby.RubyNumeric; -import org.jruby.RubyInteger; -import org.jruby.RubyFixnum; -import org.jruby.runtime.Block; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.anno.JRubyClass; -import org.jruby.anno.JRubyMethod; -import org.jruby.runtime.ThreadContext; -import org.jruby.runtime.ObjectAllocator; -import org.jruby.util.ByteList; -import org.jruby.util.TypeConverter; -import org.msgpack.jruby.ExtensionValue; - -import org.jcodings.Encoding; - -import static org.jruby.runtime.Visibility.PRIVATE; - -@JRubyClass(name="MessagePack::Packer") -public class Packer extends RubyObject { - private static final long serialVersionUID = 8451274621499362492L; - public transient ExtensionRegistry registry; - private Buffer buffer; - private transient Encoder encoder; - private boolean hasSymbolExtType; - private boolean hasBigintExtType; - private transient Encoding binaryEncoding; - - public Packer(Ruby runtime, RubyClass type, ExtensionRegistry registry, boolean hasSymbolExtType, boolean hasBigintExtType) { - super(runtime, type); - this.registry = registry; - this.hasSymbolExtType = hasSymbolExtType; - this.hasBigintExtType = hasBigintExtType; - } - - static class PackerAllocator implements ObjectAllocator { - public IRubyObject allocate(Ruby runtime, RubyClass type) { - return new Packer(runtime, type, null, false, false); - } - } - - @JRubyMethod(name = "initialize", optional = 2) - public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) { - boolean compatibilityMode = false; - Ruby runtime = ctx.runtime; - if (args.length > 0) { - RubyHash options = null; - if (args[args.length - 1] instanceof RubyHash) { - options = (RubyHash) args[args.length - 1]; - } else if (args.length > 1 && args[args.length - 2] instanceof RubyHash) { - options = (RubyHash) args[args.length - 2]; - } - - if (options != null) { - IRubyObject mode = options.fastARef(runtime.newSymbol("compatibility_mode")); - compatibilityMode = (mode != null) && mode.isTrue(); - } - } - if (registry == null) { - // registry is null when allocate -> initialize - // registry is already initialized (and somthing might be registered) when newPacker from Factory - this.registry = new ExtensionRegistry(); - } - this.encoder = new Encoder(runtime, this, compatibilityMode, registry, hasSymbolExtType, hasBigintExtType); - this.buffer = new Buffer(runtime, runtime.getModule("MessagePack").getClass("Buffer")); - this.buffer.initialize(ctx, args); - this.binaryEncoding = runtime.getEncodingService().getAscii8bitEncoding(); - return this; - } - - public static Packer newPacker(ThreadContext ctx, ExtensionRegistry extRegistry, boolean hasSymbolExtType, boolean hasBigintExtType, IRubyObject[] args) { - Packer packer = new Packer(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Packer"), extRegistry, hasSymbolExtType, hasBigintExtType); - packer.initialize(ctx, args); - return packer; - } - - @JRubyMethod(name = "compatibility_mode?") - public IRubyObject isCompatibilityMode(ThreadContext ctx) { - return encoder.isCompatibilityMode() ? ctx.runtime.getTrue() : ctx.runtime.getFalse(); - } - - @JRubyMethod(name = "registered_types_internal", visibility = PRIVATE) - public IRubyObject registeredTypesInternal(ThreadContext ctx) { - return registry.toInternalPackerRegistry(ctx); - } - - @JRubyMethod(name = "register_type_internal", required = 3, visibility = PRIVATE) - public IRubyObject registerType(ThreadContext ctx, IRubyObject type, IRubyObject mod, IRubyObject proc) { - testFrozen("MessagePack::Packer"); - - Ruby runtime = ctx.runtime; - - long typeId = ((RubyFixnum) type).getLongValue(); - if (typeId < -128 || typeId > 127) { - throw runtime.newRangeError(String.format("integer %d too big to convert to `signed char'", typeId)); - } - - if (!(mod instanceof RubyModule)) { - throw runtime.newArgumentError(String.format("expected Module/Class but found %s.", mod.getType().getName())); - } - RubyModule extModule = (RubyModule) mod; - - registry.put(extModule, (int) typeId, false, proc, null); - - if (extModule == runtime.getSymbol() && !proc.isNil()) { - encoder.hasSymbolExtType = true; - } - - return runtime.getNil(); - } - - @JRubyMethod(name = "write", alias = { "pack" }) - public IRubyObject write(ThreadContext ctx, IRubyObject obj) { - buffer.write(ctx, encoder.encode(obj, this)); - return this; - } - - @JRubyMethod(name = "write_float") - public IRubyObject writeFloat(ThreadContext ctx, IRubyObject obj) { - checkType(ctx, obj, org.jruby.RubyFloat.class); - return write(ctx, obj); - } - - @JRubyMethod(name = "write_array") - public IRubyObject writeArray(ThreadContext ctx, IRubyObject obj) { - checkType(ctx, obj, org.jruby.RubyArray.class); - return write(ctx, obj); - } - - @JRubyMethod(name = "write_string") - public IRubyObject writeString(ThreadContext ctx, IRubyObject obj) { - checkType(ctx, obj, org.jruby.RubyString.class); - return write(ctx, obj); - } - - @JRubyMethod(name = "write_bin") - public IRubyObject writeBin(ThreadContext ctx, IRubyObject obj) { - checkType(ctx, obj, org.jruby.RubyString.class); - obj = ((org.jruby.RubyString) obj).encode(ctx, ctx.runtime.getEncodingService().getEncoding(binaryEncoding)); - return write(ctx, obj); - } - - @JRubyMethod(name = "write_hash") - public IRubyObject writeHash(ThreadContext ctx, IRubyObject obj) { - checkType(ctx, obj, org.jruby.RubyHash.class); - return write(ctx, obj); - } - - @JRubyMethod(name = "write_symbol") - public IRubyObject writeSymbol(ThreadContext ctx, IRubyObject obj) { - checkType(ctx, obj, org.jruby.RubySymbol.class); - return write(ctx, obj); - } - - @JRubyMethod(name = "write_int") - public IRubyObject writeInt(ThreadContext ctx, IRubyObject obj) { - if (!(obj instanceof RubyFixnum)) { - checkType(ctx, obj, org.jruby.RubyBignum.class); - } - return write(ctx, obj); - } - - @JRubyMethod(name = "write_extension") - public IRubyObject writeExtension(ThreadContext ctx, IRubyObject obj) { - if (!(obj instanceof ExtensionValue)) { - throw ctx.runtime.newTypeError("Expected extension"); - } - return write(ctx, obj); - } - - @JRubyMethod(name = "write_true") - public IRubyObject writeTrue(ThreadContext ctx) { - return write(ctx, ctx.runtime.getTrue()); - } - - @JRubyMethod(name = "write_false") - public IRubyObject writeFalse(ThreadContext ctx) { - return write(ctx, ctx.runtime.getFalse()); - } - - @JRubyMethod(name = "write_nil") - public IRubyObject writeNil(ThreadContext ctx) { - write(ctx, null); - return this; - } - - @JRubyMethod(name = "write_float32") - public IRubyObject writeFloat32(ThreadContext ctx, IRubyObject numeric) { - Ruby runtime = ctx.runtime; - if (!(numeric instanceof RubyNumeric)) { - throw runtime.newArgumentError("Expected numeric"); - } - buffer.write(ctx, encoder.encodeFloat32((RubyNumeric) numeric)); - return this; - } - - @JRubyMethod(name = "write_array_header") - public IRubyObject writeArrayHeader(ThreadContext ctx, IRubyObject size) { - int s = (int) size.convertToInteger().getLongValue(); - buffer.write(ctx, encoder.encodeArrayHeader(s)); - return this; - } - - @JRubyMethod(name = "write_map_header") - public IRubyObject writeMapHeader(ThreadContext ctx, IRubyObject size) { - int s = (int) size.convertToInteger().getLongValue(); - buffer.write(ctx, encoder.encodeMapHeader(s)); - return this; - } - - @JRubyMethod(name = "write_bin_header") - public IRubyObject writeBinHeader(ThreadContext ctx, IRubyObject size) { - int s = (int) size.convertToInteger().getLongValue(); - buffer.write(ctx, encoder.encodeBinHeader(s)); - return this; - } - - @JRubyMethod(name = "full_pack") - public IRubyObject fullPack(ThreadContext ctx) { - if (buffer.hasIo()) { - return null; - } - return toS(ctx); - } - - @JRubyMethod(name = "to_s", alias = { "to_str" }) - public IRubyObject toS(ThreadContext ctx) { - return buffer.toS(ctx); - } - - @JRubyMethod(name = "buffer") - public IRubyObject buffer(ThreadContext ctx) { - return buffer; - } - - @JRubyMethod(name = "flush") - public IRubyObject flush(ThreadContext ctx) { - return buffer.flush(ctx); - } - - @JRubyMethod(name = "size") - public IRubyObject size(ThreadContext ctx) { - return buffer.size(ctx); - } - - @JRubyMethod(name = "clear", alias = { "reset" }) - public IRubyObject clear(ThreadContext ctx) { - return buffer.clear(ctx); - } - - private void checkType(ThreadContext ctx, IRubyObject obj, Class<? extends IRubyObject> expectedType) { - if (!expectedType.isInstance(obj)) { - String expectedName = expectedType.getName().substring("org.jruby.Ruby".length()); - throw ctx.runtime.newTypeError(String.format("wrong argument type %s (expected %s)", obj.getMetaClass().toString(), expectedName)); - } - } -} diff --git a/ext/java/org/msgpack/jruby/Types.java b/ext/java/org/msgpack/jruby/Types.java deleted file mode 100644 index e80d5708..00000000 --- a/ext/java/org/msgpack/jruby/Types.java +++ /dev/null @@ -1,37 +0,0 @@ -package org.msgpack.jruby; - - -public interface Types { - public static final byte FIXSTR = (byte) 0xa0; // This is actually not header byte, but prefix bit mask - public static final byte NIL = (byte) 0xc0; - public static final byte FALSE = (byte) 0xc2; - public static final byte TRUE = (byte) 0xc3; - public static final byte BIN8 = (byte) 0xc4; - public static final byte BIN16 = (byte) 0xc5; - public static final byte BIN32 = (byte) 0xc6; - public static final byte VAREXT8 = (byte) 0xc7; - public static final byte VAREXT16 = (byte) 0xc8; - public static final byte VAREXT32 = (byte) 0xc9; - public static final byte FLOAT32 = (byte) 0xca; - public static final byte FLOAT64 = (byte) 0xcb; - public static final byte UINT8 = (byte) 0xcc; - public static final byte UINT16 = (byte) 0xcd; - public static final byte UINT32 = (byte) 0xce; - public static final byte UINT64 = (byte) 0xcf; - public static final byte INT8 = (byte) 0xd0; - public static final byte INT16 = (byte) 0xd1; - public static final byte INT32 = (byte) 0xd2; - public static final byte INT64 = (byte) 0xd3; - public static final byte FIXEXT1 = (byte) 0xd4; - public static final byte FIXEXT2 = (byte) 0xd5; - public static final byte FIXEXT4 = (byte) 0xd6; - public static final byte FIXEXT8 = (byte) 0xd7; - public static final byte FIXEXT16 = (byte) 0xd8; - public static final byte STR8 = (byte) 0xd9; - public static final byte STR16 = (byte) 0xda; - public static final byte STR32 = (byte) 0xdb; - public static final byte ARY16 = (byte) 0xdc; - public static final byte ARY32 = (byte) 0xdd; - public static final byte MAP16 = (byte) 0xde; - public static final byte MAP32 = (byte) 0xdf; -} diff --git a/ext/java/org/msgpack/jruby/Unpacker.java b/ext/java/org/msgpack/jruby/Unpacker.java deleted file mode 100644 index 52af531f..00000000 --- a/ext/java/org/msgpack/jruby/Unpacker.java +++ /dev/null @@ -1,336 +0,0 @@ -package org.msgpack.jruby; - -import java.util.Arrays; - -import org.jruby.Ruby; -import org.jruby.RubyModule; -import org.jruby.RubyClass; -import org.jruby.RubyString; -import org.jruby.RubyObject; -import org.jruby.RubyArray; -import org.jruby.RubyHash; -import org.jruby.RubyNumeric; -import org.jruby.RubyFixnum; -import org.jruby.RubyProc; -import org.jruby.RubyIO; -import org.jruby.exceptions.RaiseException; -import org.jruby.runtime.builtin.IRubyObject; -import org.jruby.runtime.Block; -import org.jruby.runtime.ObjectAllocator; -import org.jruby.runtime.ThreadContext; -import org.jruby.anno.JRubyClass; -import org.jruby.anno.JRubyMethod; -import org.jruby.util.ByteList; - -import static org.jruby.runtime.Visibility.PRIVATE; - -@JRubyClass(name="MessagePack::Unpacker") -public class Unpacker extends RubyObject { - private static final long serialVersionUID = 8451264671199362492L; - private transient final ExtensionRegistry registry; - - private transient IRubyObject stream; - private transient IRubyObject data; - private transient Decoder decoder; - private final RubyClass underflowErrorClass; - private boolean symbolizeKeys; - private boolean freeze; - private boolean allowUnknownExt; - - public Unpacker(Ruby runtime, RubyClass type) { - this(runtime, type, new ExtensionRegistry()); - } - - public Unpacker(Ruby runtime, RubyClass type, ExtensionRegistry registry) { - super(runtime, type); - this.registry = registry; - this.underflowErrorClass = runtime.getModule("MessagePack").getClass("UnderflowError"); - } - - static class UnpackerAllocator implements ObjectAllocator { - public IRubyObject allocate(Ruby runtime, RubyClass klass) { - return new Unpacker(runtime, klass); - } - } - - @JRubyMethod(name = "initialize", optional = 2, visibility = PRIVATE) - public IRubyObject initialize(ThreadContext ctx, IRubyObject[] args) { - Ruby runtime = ctx.runtime; - - symbolizeKeys = false; - allowUnknownExt = false; - freeze = false; - - IRubyObject io = null; - RubyHash options = null; - - if (args.length >= 1) { - io = args[0]; - } - - if (args.length >= 2 && args[1] != runtime.getNil()) { - options = (RubyHash)args[1]; - } - - if (options == null && io != null && io instanceof RubyHash) { - options = (RubyHash)io; - io = null; - } - - if (options != null) { - IRubyObject sk = options.fastARef(runtime.newSymbol("symbolize_keys")); - if (sk != null) { - symbolizeKeys = sk.isTrue(); - } - IRubyObject f = options.fastARef(runtime.newSymbol("freeze")); - if (f != null) { - freeze = f.isTrue(); - } - IRubyObject au = options.fastARef(runtime.newSymbol("allow_unknown_ext")); - if (au != null) { - allowUnknownExt = au.isTrue(); - } - - } - - if (io != null && io != runtime.getNil()) { - setStream(ctx, io); - } - - return this; - } - - public static Unpacker newUnpacker(ThreadContext ctx, ExtensionRegistry extRegistry, IRubyObject[] args) { - Unpacker unpacker = new Unpacker(ctx.runtime, ctx.runtime.getModule("MessagePack").getClass("Unpacker"), extRegistry); - unpacker.initialize(ctx, args); - return unpacker; - } - - @JRubyMethod(name = "symbolize_keys?") - public IRubyObject isSymbolizeKeys(ThreadContext ctx) { - return symbolizeKeys ? ctx.runtime.getTrue() : ctx.runtime.getFalse(); - } - - @JRubyMethod(name = "freeze?") - public IRubyObject isFreeze(ThreadContext ctx) { - return freeze ? ctx.runtime.getTrue() : ctx.runtime.getFalse(); - } - - @JRubyMethod(name = "allow_unknown_ext?") - public IRubyObject isAllowUnknownExt(ThreadContext ctx) { - return allowUnknownExt ? ctx.runtime.getTrue() : ctx.runtime.getFalse(); - } - - @JRubyMethod(name = "registered_types_internal", visibility = PRIVATE) - public IRubyObject registeredTypesInternal(ThreadContext ctx) { - return registry.toInternalUnpackerRegistry(ctx); - } - - @JRubyMethod(name = "register_type_internal", required = 3, visibility = PRIVATE) - public IRubyObject registerTypeInternal(ThreadContext ctx, IRubyObject type, IRubyObject mod, IRubyObject proc) { - testFrozen("MessagePack::Unpacker"); - - Ruby runtime = ctx.runtime; - - long typeId = ((RubyFixnum) type).getLongValue(); - if (typeId < -128 || typeId > 127) { - throw runtime.newRangeError(String.format("integer %d too big to convert to `signed char'", typeId)); - } - - RubyModule extModule = null; - if (mod != runtime.getNil()) { - extModule = (RubyModule)mod; - } - - registry.put(extModule, (int) typeId, false, null, proc); - return runtime.getNil(); - } - - @JRubyMethod(required = 2) - public IRubyObject execute(ThreadContext ctx, IRubyObject data, IRubyObject offset) { - return executeLimit(ctx, data, offset, null); - } - - @JRubyMethod(name = "execute_limit", required = 3) - public IRubyObject executeLimit(ThreadContext ctx, IRubyObject str, IRubyObject off, IRubyObject lim) { - RubyString input = str.asString(); - int offset = RubyNumeric.fix2int(off); - int limit = lim == null || lim.isNil() ? -1 : RubyNumeric.fix2int(lim); - ByteList byteList = input.getByteList(); - if (limit == -1) { - limit = byteList.length() - offset; - } - Decoder decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin() + offset, limit, symbolizeKeys, freeze, allowUnknownExt); - try { - data = null; - data = decoder.next(); - } catch (RaiseException re) { - if (re.getException().getType() != underflowErrorClass) { - throw re; - } - } - return ctx.runtime.newFixnum(decoder.offset()); - } - - @JRubyMethod(name = "data") - public IRubyObject getData(ThreadContext ctx) { - if (data == null) { - return ctx.runtime.getNil(); - } else { - return data; - } - } - - @JRubyMethod(name = "finished?") - public IRubyObject finished_p(ThreadContext ctx) { - return data == null ? ctx.runtime.getFalse() : ctx.runtime.getTrue(); - } - - @JRubyMethod(required = 1, name = "feed", alias = { "feed_reference" }) - public IRubyObject feed(ThreadContext ctx, IRubyObject data) { - ByteList byteList = data.asString().getByteList(); - if (decoder == null) { - decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt); - } else { - decoder.feed(byteList.unsafeBytes(), byteList.begin(), byteList.length()); - } - return this; - } - - @JRubyMethod(name = "full_unpack") - public IRubyObject fullUnpack(ThreadContext ctx) { - return decoder.next(); - } - - @JRubyMethod(name = "feed_each", required = 1) - public IRubyObject feedEach(ThreadContext ctx, IRubyObject data, Block block) { - feed(ctx, data); - if (block.isGiven()) { - each(ctx, block); - return ctx.runtime.getNil(); - } else { - return callMethod(ctx, "to_enum"); - } - } - - @JRubyMethod - public IRubyObject each(ThreadContext ctx, Block block) { - if (block.isGiven()) { - if (decoder != null) { - try { - while (decoder.hasNext()) { - block.yield(ctx, decoder.next()); - } - } catch (RaiseException re) { - if (re.getException().getType() != underflowErrorClass) { - throw re; - } - } - } - return this; - } else { - return callMethod(ctx, "to_enum"); - } - } - - @JRubyMethod - public IRubyObject fill(ThreadContext ctx) { - return ctx.runtime.getNil(); - } - - @JRubyMethod - public IRubyObject reset(ThreadContext ctx) { - if (decoder != null) { - decoder.reset(); - } - return ctx.runtime.getNil(); - } - - @JRubyMethod(name = "read", alias = { "unpack" }) - public IRubyObject read(ThreadContext ctx) { - if (decoder == null) { - throw ctx.runtime.newEOFError(); - } - try { - return decoder.next(); - } catch (RaiseException re) { - if (re.getException().getType() != underflowErrorClass) { - throw re; - } else { - throw ctx.runtime.newEOFError(); - } - } - } - - @JRubyMethod(name = "skip") - public IRubyObject skip(ThreadContext ctx) { - throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation"); - } - - @JRubyMethod(name = "skip_nil") - public IRubyObject skipNil(ThreadContext ctx) { - throw ctx.runtime.newNotImplementedError("Not supported yet in JRuby implementation"); - } - - @JRubyMethod - public IRubyObject read_array_header(ThreadContext ctx) { - if (decoder != null) { - try { - return decoder.read_array_header(); - } catch (RaiseException re) { - if (re.getException().getType() != underflowErrorClass) { - throw re; - } else { - throw ctx.runtime.newEOFError(); - } - } - } - return ctx.runtime.getNil(); - } - - @JRubyMethod - public IRubyObject read_map_header(ThreadContext ctx) { - if (decoder != null) { - try { - return decoder.read_map_header(); - } catch (RaiseException re) { - if (re.getException().getType() != underflowErrorClass) { - throw re; - } else { - throw ctx.runtime.newEOFError(); - } - } - } - return ctx.runtime.getNil(); - } - - @JRubyMethod(name = "stream") - public IRubyObject getStream(ThreadContext ctx) { - if (stream == null) { - return ctx.runtime.getNil(); - } else { - return stream; - } - } - - @JRubyMethod(name = "stream=", required = 1) - public IRubyObject setStream(ThreadContext ctx, IRubyObject stream) { - RubyString str; - if (stream instanceof RubyIO) { - str = stream.callMethod(ctx, "read").asString(); - } else if (stream.respondsTo("read")) { - str = stream.callMethod(ctx, "read").asString(); - } else { - throw ctx.runtime.newTypeError(stream, "IO"); - } - ByteList byteList = str.getByteList(); - this.stream = stream; - this.decoder = null; - this.decoder = new Decoder(ctx.runtime, this, byteList.unsafeBytes(), byteList.begin(), byteList.length(), symbolizeKeys, freeze, allowUnknownExt); - return getStream(ctx); - } - - public ExtensionRegistry.ExtensionEntry lookupExtensionByTypeId(int typeId) { - return registry.lookupExtensionByTypeId(typeId); - } -} diff --git a/ext/msgpack/buffer.c b/ext/msgpack/buffer.c deleted file mode 100644 index d1583702..00000000 --- a/ext/msgpack/buffer.c +++ /dev/null @@ -1,669 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "buffer.h" -#include "rmem.h" - -int msgpack_rb_encindex_utf8; -int msgpack_rb_encindex_usascii; -int msgpack_rb_encindex_ascii8bit; - -ID s_uminus; - -static msgpack_rmem_t s_rmem; - -void msgpack_buffer_static_init(void) -{ - s_uminus = rb_intern("-@"); - - msgpack_rb_encindex_utf8 = rb_utf8_encindex(); - msgpack_rb_encindex_usascii = rb_usascii_encindex(); - msgpack_rb_encindex_ascii8bit = rb_ascii8bit_encindex(); - - msgpack_rmem_init(&s_rmem); -} - -void msgpack_buffer_static_destroy(void) -{ - msgpack_rmem_destroy(&s_rmem); -} - -void msgpack_buffer_init(msgpack_buffer_t* b) -{ - memset(b, 0, sizeof(msgpack_buffer_t)); - - b->head = &b->tail; - b->write_reference_threshold = MSGPACK_BUFFER_STRING_WRITE_REFERENCE_DEFAULT; - b->read_reference_threshold = MSGPACK_BUFFER_STRING_READ_REFERENCE_DEFAULT; - b->io_buffer_size = MSGPACK_BUFFER_IO_BUFFER_SIZE_DEFAULT; - b->io = Qnil; - b->io_buffer = Qnil; -} - -static void _msgpack_buffer_chunk_destroy(msgpack_buffer_chunk_t* c) -{ - if(c->mem != NULL) { - if(c->rmem) { - if(!msgpack_rmem_free(&s_rmem, c->mem)) { - rb_bug("Failed to free an rmem pointer, memory leak?"); - } - } else { - xfree(c->mem); - } - /* no needs to update rmem_owner because chunks will not be - * free()ed (left in free_list) and thus *rmem_owner is - * always valid. */ - } - c->first = NULL; - c->last = NULL; - c->mem = NULL; -} - -void msgpack_buffer_destroy(msgpack_buffer_t* b) -{ - /* head is always available */ - msgpack_buffer_chunk_t* c = b->head; - while(c != &b->tail) { - msgpack_buffer_chunk_t* n = c->next; - _msgpack_buffer_chunk_destroy(c); - xfree(c); - c = n; - } - _msgpack_buffer_chunk_destroy(c); - - c = b->free_list; - while(c != NULL) { - msgpack_buffer_chunk_t* n = c->next; - xfree(c); - c = n; - } -} - -size_t msgpack_buffer_memsize(const msgpack_buffer_t* b) -{ - size_t memsize = 0; - msgpack_buffer_chunk_t* c = b->head; - - while(c) { - memsize += sizeof(msgpack_buffer_chunk_t); - if(c->mapped_string != NO_MAPPED_STRING) { - memsize += (c->last - c->first); - } - c = c->next; - } - - return memsize; -} - -void msgpack_buffer_mark(void *ptr) -{ - msgpack_buffer_t* b = ptr; - /* head is always available */ - msgpack_buffer_chunk_t* c = b->head; - while(c != &b->tail) { - rb_gc_mark(c->mapped_string); - c = c->next; - } - rb_gc_mark(c->mapped_string); - - rb_gc_mark(b->io); - rb_gc_mark(b->io_buffer); -} - -bool _msgpack_buffer_shift_chunk(msgpack_buffer_t* b) -{ - _msgpack_buffer_chunk_destroy(b->head); - - if(b->head == &b->tail) { - /* list becomes empty. don't add head to free_list - * because head should be always available */ - b->tail_buffer_end = NULL; - b->read_buffer = NULL; - return false; - } - - /* add head to free_list */ - msgpack_buffer_chunk_t* next_head = b->head->next; - b->head->next = b->free_list; - b->free_list = b->head; - - b->head = next_head; - b->read_buffer = next_head->first; - - return true; -} - -void msgpack_buffer_clear(msgpack_buffer_t* b) -{ - while(_msgpack_buffer_shift_chunk(b)) { - ; - } -} - -size_t msgpack_buffer_read_to_string_nonblock(msgpack_buffer_t* b, VALUE string, size_t length) -{ - size_t avail = msgpack_buffer_top_readable_size(b); - - /* optimize */ - if(length <= avail && RSTRING_LEN(string) == 0 && - b->head->mapped_string != NO_MAPPED_STRING && - length >= b->read_reference_threshold) { - VALUE s = _msgpack_buffer_refer_head_mapped_string(b, length); - rb_str_replace(string, s); - /* here doesn't have to call ENCODING_SET because - * encoding of s is always ASCII-8BIT */ - _msgpack_buffer_consumed(b, length); - return length; - } - - size_t const length_orig = length; - - while(true) { - if(length <= avail) { - rb_str_buf_cat(string, b->read_buffer, length); - _msgpack_buffer_consumed(b, length); - return length_orig; - } - - rb_str_buf_cat(string, b->read_buffer, avail); - length -= avail; - - if(!_msgpack_buffer_shift_chunk(b)) { - return length_orig - length; - } - - avail = msgpack_buffer_top_readable_size(b); - } -} - -size_t msgpack_buffer_read_nonblock(msgpack_buffer_t* b, char* buffer, size_t length) -{ - /* buffer == NULL means skip */ - size_t const length_orig = length; - - while(true) { - size_t avail = msgpack_buffer_top_readable_size(b); - - if(length <= avail) { - if(buffer != NULL) { - memcpy(buffer, b->read_buffer, length); - } - _msgpack_buffer_consumed(b, length); - return length_orig; - } - - if(buffer != NULL) { - memcpy(buffer, b->read_buffer, avail); - buffer += avail; - } - length -= avail; - - if(!_msgpack_buffer_shift_chunk(b)) { - return length_orig - length; - } - } -} - -size_t msgpack_buffer_all_readable_size(const msgpack_buffer_t* b) -{ - size_t sz = msgpack_buffer_top_readable_size(b); - - if(b->head == &b->tail) { - return sz; - } - - msgpack_buffer_chunk_t* c = b->head->next; - - while(true) { - sz += c->last - c->first; - if(c == &b->tail) { - return sz; - } - c = c->next; - } -} - -bool _msgpack_buffer_read_all2(msgpack_buffer_t* b, char* buffer, size_t length) -{ - if(!msgpack_buffer_ensure_readable(b, length)) { - return false; - } - - msgpack_buffer_read_nonblock(b, buffer, length); - return true; -} - - -static inline msgpack_buffer_chunk_t* _msgpack_buffer_alloc_new_chunk(msgpack_buffer_t* b) -{ - msgpack_buffer_chunk_t* chunk = b->free_list; - if (chunk) { - b->free_list = b->free_list->next; - } else { - chunk = xmalloc(sizeof(msgpack_buffer_chunk_t)); - } - memset(chunk, 0, sizeof(msgpack_buffer_chunk_t)); - return chunk; -} - -static inline void _msgpack_buffer_add_new_chunk(msgpack_buffer_t* b) -{ - if(b->head == &b->tail) { - if(b->tail.first == NULL) { - /* empty buffer */ - return; - } - - msgpack_buffer_chunk_t* nc = _msgpack_buffer_alloc_new_chunk(b); - - *nc = b->tail; - b->head = nc; - nc->next = &b->tail; - - } else { - /* search node before tail */ - msgpack_buffer_chunk_t* before_tail = b->head; - while(before_tail->next != &b->tail) { - before_tail = before_tail->next; - } - - msgpack_buffer_chunk_t* nc = _msgpack_buffer_alloc_new_chunk(b); - - if(b->rmem_last == b->tail_buffer_end) { - /* reuse unused rmem space */ - size_t unused = b->tail_buffer_end - b->tail.last; - b->rmem_last -= unused; - } - - /* rebuild tail */ - *nc = b->tail; - before_tail->next = nc; - nc->next = &b->tail; - } -} - -static inline void _msgpack_buffer_append_reference(msgpack_buffer_t* b, VALUE string) -{ - VALUE mapped_string; - if(ENCODING_GET_INLINED(string) == msgpack_rb_encindex_ascii8bit && RB_OBJ_FROZEN_RAW(string)) { - mapped_string = string; - } else { - mapped_string = rb_str_dup(string); - ENCODING_SET(mapped_string, msgpack_rb_encindex_ascii8bit); - } - - _msgpack_buffer_add_new_chunk(b); - - char* data; - size_t length; - RSTRING_GETMEM(mapped_string, data, length); - - b->tail.first = (char*) data; - b->tail.last = (char*) data + length; - b->tail.mapped_string = mapped_string; - b->tail.mem = NULL; - - /* msgpack_buffer_writable_size should return 0 for mapped chunk */ - b->tail_buffer_end = b->tail.last; - - /* consider read_buffer */ - if(b->head == &b->tail) { - b->read_buffer = b->tail.first; - } -} - -void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string) -{ - if(b->io != Qnil) { - msgpack_buffer_flush(b); - if (ENCODING_GET_INLINED(string) == msgpack_rb_encindex_ascii8bit) { - rb_funcall(b->io, b->io_write_all_method, 1, string); - } else { - msgpack_buffer_append(b, RSTRING_PTR(string), RSTRING_LEN(string)); - } - } else { - _msgpack_buffer_append_reference(b, string); - } -} - -static inline void* _msgpack_buffer_chunk_malloc( - msgpack_buffer_t* b, msgpack_buffer_chunk_t* c, - size_t required_size, size_t* allocated_size) -{ - if(required_size <= MSGPACK_RMEM_PAGE_SIZE) { - c->rmem = true; - - if((size_t)(b->rmem_end - b->rmem_last) < required_size) { - /* alloc new rmem page */ - *allocated_size = MSGPACK_RMEM_PAGE_SIZE; - char* buffer = msgpack_rmem_alloc(&s_rmem); - c->mem = buffer; - - /* update rmem owner */ - b->rmem_owner = &c->mem; - b->rmem_last = b->rmem_end = buffer + MSGPACK_RMEM_PAGE_SIZE; - - return buffer; - } else { - /* reuse unused rmem */ - *allocated_size = (size_t)(b->rmem_end - b->rmem_last); - char* buffer = b->rmem_last; - b->rmem_last = b->rmem_end; - - /* update rmem owner */ - c->mem = *b->rmem_owner; - *b->rmem_owner = NULL; - b->rmem_owner = &c->mem; - - return buffer; - } - } - - // TODO alignment? - *allocated_size = required_size; - void* mem = xmalloc(required_size); - c->mem = mem; - c->rmem = false; - return mem; -} - -static inline void* _msgpack_buffer_chunk_realloc( - msgpack_buffer_t* b, msgpack_buffer_chunk_t* c, - void* mem, size_t required_size, size_t* current_size) -{ - if(mem == NULL) { - return _msgpack_buffer_chunk_malloc(b, c, required_size, current_size); - } - - size_t next_size = *current_size * 2; - while(next_size < required_size) { - next_size *= 2; - } - *current_size = next_size; - mem = xrealloc(mem, next_size); - - c->mem = mem; - return mem; -} - -void _msgpack_buffer_expand(msgpack_buffer_t* b, const char* data, size_t length, bool flush_to_io) -{ - if(flush_to_io && b->io != Qnil) { - msgpack_buffer_flush(b); - if(msgpack_buffer_writable_size(b) >= length) { - /* data == NULL means ensure_writable */ - if(data != NULL) { - size_t tail_avail = msgpack_buffer_writable_size(b); - memcpy(b->tail.last, data, length); - b->tail.last += tail_avail; - } - return; - } - } - - /* data == NULL means ensure_writable */ - if(data != NULL) { - size_t tail_avail = msgpack_buffer_writable_size(b); - memcpy(b->tail.last, data, tail_avail); - b->tail.last += tail_avail; - data += tail_avail; - length -= tail_avail; - } - - size_t capacity = b->tail.last - b->tail.first; - - /* can't realloc mapped chunk or rmem page */ - if(b->tail.mapped_string != NO_MAPPED_STRING || capacity <= MSGPACK_RMEM_PAGE_SIZE) { - /* allocate new chunk */ - _msgpack_buffer_add_new_chunk(b); - - char* mem = _msgpack_buffer_chunk_malloc(b, &b->tail, length, &capacity); - - char* last = mem; - if(data != NULL) { - memcpy(mem, data, length); - last += length; - } - - /* rebuild tail chunk */ - b->tail.first = mem; - b->tail.last = last; - b->tail.mapped_string = NO_MAPPED_STRING; - b->tail_buffer_end = mem + capacity; - - /* consider read_buffer */ - if(b->head == &b->tail) { - b->read_buffer = b->tail.first; - } - - } else { - /* realloc malloc()ed chunk or NULL */ - size_t tail_filled = b->tail.last - b->tail.first; - char* mem = _msgpack_buffer_chunk_realloc(b, &b->tail, - b->tail.first, tail_filled+length, &capacity); - - char* last = mem + tail_filled; - if(data != NULL) { - memcpy(last, data, length); - last += length; - } - - /* consider read_buffer */ - if(b->head == &b->tail) { - size_t read_offset = b->read_buffer - b->head->first; - b->read_buffer = mem + read_offset; - } - - /* rebuild tail chunk */ - b->tail.first = mem; - b->tail.last = last; - b->tail_buffer_end = mem + capacity; - } -} - -static inline VALUE _msgpack_buffer_head_chunk_as_string(msgpack_buffer_t* b) -{ - size_t length = b->head->last - b->read_buffer; - if(length == 0) { - return rb_str_buf_new(0); - } - - if(b->head->mapped_string != NO_MAPPED_STRING) { - return _msgpack_buffer_refer_head_mapped_string(b, length); - } - - return rb_str_new(b->read_buffer, length); -} - -static inline VALUE _msgpack_buffer_chunk_as_string(msgpack_buffer_chunk_t* c) -{ - size_t chunk_size = c->last - c->first; - if(chunk_size == 0) { - return rb_str_buf_new(0); - } - - if(c->mapped_string != NO_MAPPED_STRING) { - return rb_str_dup(c->mapped_string); - } - - return rb_str_new(c->first, chunk_size); -} - -VALUE msgpack_buffer_all_as_string(msgpack_buffer_t* b) -{ - if(b->head == &b->tail) { - return _msgpack_buffer_head_chunk_as_string(b); - } - - size_t length = msgpack_buffer_all_readable_size(b); - VALUE string = rb_str_new(NULL, length); - char* buffer = RSTRING_PTR(string); - - size_t avail = msgpack_buffer_top_readable_size(b); - memcpy(buffer, b->read_buffer, avail); - buffer += avail; - length -= avail; - - msgpack_buffer_chunk_t* c = b->head->next; - - while(true) { - avail = c->last - c->first; - memcpy(buffer, c->first, avail); - - if(length <= avail) { - return string; - } - buffer += avail; - length -= avail; - - c = c->next; - } -} - -VALUE msgpack_buffer_all_as_string_array(msgpack_buffer_t* b) -{ - if(b->head == &b->tail) { - VALUE s = msgpack_buffer_all_as_string(b); - VALUE ary = rb_ary_new3(1, s); - return ary; - } - - /* TODO optimize ary construction */ - VALUE ary = rb_ary_new(); - - VALUE s = _msgpack_buffer_head_chunk_as_string(b); - rb_ary_push(ary, s); - - msgpack_buffer_chunk_t* c = b->head->next; - - while(true) { - s = _msgpack_buffer_chunk_as_string(c); - rb_ary_push(ary, s); - if(c == &b->tail) { - return ary; - } - c = c->next; - } - - return ary; -} - -size_t msgpack_buffer_flush_to_io(msgpack_buffer_t* b, VALUE io, ID write_method, bool consume) -{ - if(msgpack_buffer_top_readable_size(b) == 0) { - return 0; - } - - VALUE s = _msgpack_buffer_head_chunk_as_string(b); - rb_funcall(io, write_method, 1, s); - size_t sz = RSTRING_LEN(s); - - if(consume) { - while(_msgpack_buffer_shift_chunk(b)) { - s = _msgpack_buffer_chunk_as_string(b->head); - rb_funcall(io, write_method, 1, s); - sz += RSTRING_LEN(s); - } - return sz; - - } else { - if(b->head == &b->tail) { - return sz; - } - msgpack_buffer_chunk_t* c = b->head->next; - while(true) { - s = _msgpack_buffer_chunk_as_string(c); - rb_funcall(io, write_method, 1, s); - sz += RSTRING_LEN(s); - if(c == &b->tail) { - return sz; - } - c = c->next; - } - } -} - -size_t _msgpack_buffer_feed_from_io(msgpack_buffer_t* b) -{ - if(b->io_buffer == Qnil) { - b->io_buffer = rb_funcall(b->io, b->io_partial_read_method, 1, SIZET2NUM(b->io_buffer_size)); - if(b->io_buffer == Qnil) { - rb_raise(rb_eEOFError, "IO reached end of file"); - } - StringValue(b->io_buffer); - } else { - VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(b->io_buffer_size), b->io_buffer); - if(ret == Qnil) { - rb_raise(rb_eEOFError, "IO reached end of file"); - } - } - - size_t len = RSTRING_LEN(b->io_buffer); - if(len == 0) { - rb_raise(rb_eEOFError, "IO reached end of file"); - } - - /* TODO zero-copy optimize? */ - msgpack_buffer_append_nonblock(b, RSTRING_PTR(b->io_buffer), len); - - return len; -} - -size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string, size_t length) -{ -#define MIN(x, y) (((x) < (y)) ? (x) : (y)) - - if(RSTRING_LEN(string) == 0) { - /* direct read */ - VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(MIN(b->io_buffer_size, length)), string); - if(ret == Qnil) { - return 0; - } - return RSTRING_LEN(string); - } - - /* copy via io_buffer */ - if(b->io_buffer == Qnil) { - b->io_buffer = rb_str_buf_new(0); - } - - VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(MIN(b->io_buffer_size, length)), b->io_buffer); - if(ret == Qnil) { - return 0; - } - size_t rl = RSTRING_LEN(b->io_buffer); - - rb_str_buf_cat(string, (const void*)RSTRING_PTR(b->io_buffer), rl); - return rl; - -#undef MIN -} - -size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length) -{ - if(b->io_buffer == Qnil) { - b->io_buffer = rb_str_buf_new(0); - } - - VALUE ret = rb_funcall(b->io, b->io_partial_read_method, 2, SIZET2NUM(length), b->io_buffer); - if(ret == Qnil) { - return 0; - } - return RSTRING_LEN(b->io_buffer); -} - diff --git a/ext/msgpack/buffer.h b/ext/msgpack/buffer.h deleted file mode 100644 index 1c8efe54..00000000 --- a/ext/msgpack/buffer.h +++ /dev/null @@ -1,604 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_BUFFER_H__ -#define MSGPACK_RUBY_BUFFER_H__ - -#include "compat.h" -#include "sysdep.h" - -#ifndef MSGPACK_BUFFER_STRING_WRITE_REFERENCE_DEFAULT -#define MSGPACK_BUFFER_STRING_WRITE_REFERENCE_DEFAULT (512*1024) -#endif - -/* at least 23 (RSTRING_EMBED_LEN_MAX) bytes */ -#ifndef MSGPACK_BUFFER_STRING_WRITE_REFERENCE_MINIMUM -#define MSGPACK_BUFFER_STRING_WRITE_REFERENCE_MINIMUM 256 -#endif - -#ifndef MSGPACK_BUFFER_STRING_READ_REFERENCE_DEFAULT -#define MSGPACK_BUFFER_STRING_READ_REFERENCE_DEFAULT 256 -#endif - -/* at least 23 (RSTRING_EMBED_LEN_MAX) bytes */ -#ifndef MSGPACK_BUFFER_STRING_READ_REFERENCE_MINIMUM -#define MSGPACK_BUFFER_STRING_READ_REFERENCE_MINIMUM 256 -#endif - -#ifndef MSGPACK_BUFFER_IO_BUFFER_SIZE_DEFAULT -#define MSGPACK_BUFFER_IO_BUFFER_SIZE_DEFAULT (32*1024) -#endif - -#ifndef MSGPACK_BUFFER_IO_BUFFER_SIZE_MINIMUM -#define MSGPACK_BUFFER_IO_BUFFER_SIZE_MINIMUM (1024) -#endif - -#define NO_MAPPED_STRING ((VALUE)0) - -#ifndef RB_ENC_INTERNED_STR_NULL_CHECK -#define RB_ENC_INTERNED_STR_NULL_CHECK 0 -#endif - -extern int msgpack_rb_encindex_utf8; -extern int msgpack_rb_encindex_usascii; -extern int msgpack_rb_encindex_ascii8bit; - -extern ID s_uminus; - -struct msgpack_buffer_chunk_t; -typedef struct msgpack_buffer_chunk_t msgpack_buffer_chunk_t; - -struct msgpack_buffer_t; -typedef struct msgpack_buffer_t msgpack_buffer_t; - -/* - * msgpack_buffer_chunk_t - * +----------------+ - * | filled | free | - * +---------+------+ - * ^ first ^ last - */ -struct msgpack_buffer_chunk_t { - char* first; - char* last; - void* mem; - msgpack_buffer_chunk_t* next; - VALUE mapped_string; /* RBString or NO_MAPPED_STRING */ - bool rmem; -}; - -struct msgpack_buffer_t { - char* read_buffer; - char* tail_buffer_end; - - msgpack_buffer_chunk_t tail; - msgpack_buffer_chunk_t* head; - msgpack_buffer_chunk_t* free_list; - - char* rmem_last; - char* rmem_end; - void** rmem_owner; - - VALUE io; - VALUE io_buffer; - ID io_write_all_method; - ID io_partial_read_method; - - size_t write_reference_threshold; - size_t read_reference_threshold; - size_t io_buffer_size; -}; - -/* - * initialization functions - */ -void msgpack_buffer_static_init(void); - -void msgpack_buffer_static_destroy(void); - -void msgpack_buffer_init(msgpack_buffer_t* b); - -void msgpack_buffer_destroy(msgpack_buffer_t* b); - -void msgpack_buffer_mark(void* b); - -void msgpack_buffer_clear(msgpack_buffer_t* b); - -size_t msgpack_buffer_memsize(const msgpack_buffer_t* b); - -static inline void msgpack_buffer_set_write_reference_threshold(msgpack_buffer_t* b, size_t length) -{ - if(length < MSGPACK_BUFFER_STRING_WRITE_REFERENCE_MINIMUM) { - length = MSGPACK_BUFFER_STRING_WRITE_REFERENCE_MINIMUM; - } - b->write_reference_threshold = length; -} - -static inline void msgpack_buffer_set_read_reference_threshold(msgpack_buffer_t* b, size_t length) -{ - if(length < MSGPACK_BUFFER_STRING_READ_REFERENCE_MINIMUM) { - length = MSGPACK_BUFFER_STRING_READ_REFERENCE_MINIMUM; - } - b->read_reference_threshold = length; -} - -static inline void msgpack_buffer_set_io_buffer_size(msgpack_buffer_t* b, size_t length) -{ - if(length < MSGPACK_BUFFER_IO_BUFFER_SIZE_MINIMUM) { - length = MSGPACK_BUFFER_IO_BUFFER_SIZE_MINIMUM; - } - b->io_buffer_size = length; -} - -static inline void msgpack_buffer_reset_io(msgpack_buffer_t* b) -{ - b->io = Qnil; -} - -static inline bool msgpack_buffer_has_io(msgpack_buffer_t* b) -{ - return b->io != Qnil; -} - -static inline void msgpack_buffer_reset(msgpack_buffer_t* b) -{ - msgpack_buffer_clear(b); - msgpack_buffer_reset_io(b); -} - - -/* - * writer functions - */ - -static inline size_t msgpack_buffer_writable_size(const msgpack_buffer_t* b) -{ - return b->tail_buffer_end - b->tail.last; -} - -static inline void msgpack_buffer_write_1(msgpack_buffer_t* b, int byte) -{ - (*b->tail.last++) = (char) byte; -} - -static inline void msgpack_buffer_write_2(msgpack_buffer_t* b, int byte1, unsigned char byte2) -{ - *(b->tail.last++) = (char) byte1; - *(b->tail.last++) = (char) byte2; -} - -static inline void msgpack_buffer_write_byte_and_data(msgpack_buffer_t* b, int byte, const void* data, size_t length) -{ - (*b->tail.last++) = (char) byte; - - memcpy(b->tail.last, data, length); - b->tail.last += length; -} - -void _msgpack_buffer_expand(msgpack_buffer_t* b, const char* data, size_t length, bool use_flush); - -size_t msgpack_buffer_flush_to_io(msgpack_buffer_t* b, VALUE io, ID write_method, bool consume); - -static inline size_t msgpack_buffer_flush(msgpack_buffer_t* b) -{ - if(b->io == Qnil) { - return 0; - } - return msgpack_buffer_flush_to_io(b, b->io, b->io_write_all_method, true); -} - -static inline void msgpack_buffer_ensure_writable(msgpack_buffer_t* b, size_t require) -{ - if(msgpack_buffer_writable_size(b) < require) { - _msgpack_buffer_expand(b, NULL, require, true); - } -} - -static inline void _msgpack_buffer_append_impl(msgpack_buffer_t* b, const char* data, size_t length, bool flush_to_io) -{ - if(length == 0) { - return; - } - - if(length <= msgpack_buffer_writable_size(b)) { - memcpy(b->tail.last, data, length); - b->tail.last += length; - return; - } - - _msgpack_buffer_expand(b, data, length, flush_to_io); -} - -static inline void msgpack_buffer_append(msgpack_buffer_t* b, const char* data, size_t length) -{ - _msgpack_buffer_append_impl(b, data, length, true); -} - -static inline void msgpack_buffer_append_nonblock(msgpack_buffer_t* b, const char* data, size_t length) -{ - _msgpack_buffer_append_impl(b, data, length, false); -} - -void _msgpack_buffer_append_long_string(msgpack_buffer_t* b, VALUE string); - -static inline size_t msgpack_buffer_append_string(msgpack_buffer_t* b, VALUE string) -{ - size_t length; - char *ptr; - RSTRING_GETMEM(string, ptr, length); - - if(length > b->write_reference_threshold) { - _msgpack_buffer_append_long_string(b, string); - } else { - msgpack_buffer_append(b, ptr, length); - } - - return length; -} - -static inline size_t msgpack_buffer_append_string_reference(msgpack_buffer_t* b, VALUE string) -{ - size_t length = RSTRING_LEN(string); - if (length > 0) { - _msgpack_buffer_append_long_string(b, string); - } - return length; -} - - -/* - * IO functions - */ -size_t _msgpack_buffer_feed_from_io(msgpack_buffer_t* b); - -size_t _msgpack_buffer_read_from_io_to_string(msgpack_buffer_t* b, VALUE string, size_t length); - -size_t _msgpack_buffer_skip_from_io(msgpack_buffer_t* b, size_t length); - - -/* - * reader functions - */ - -static inline size_t msgpack_buffer_top_readable_size(const msgpack_buffer_t* b) -{ - return b->head->last - b->read_buffer; -} - -size_t msgpack_buffer_all_readable_size(const msgpack_buffer_t* b); - -bool _msgpack_buffer_shift_chunk(msgpack_buffer_t* b); - -static inline void _msgpack_buffer_consumed(msgpack_buffer_t* b, size_t length) -{ - b->read_buffer += length; - if(b->read_buffer >= b->head->last) { - _msgpack_buffer_shift_chunk(b); - } -} - -static inline int msgpack_buffer_peek_top_1(msgpack_buffer_t* b) -{ - return (int) (unsigned char) b->read_buffer[0]; -} - -static inline int msgpack_buffer_read_top_1(msgpack_buffer_t* b) -{ - int r = (int) (unsigned char) b->read_buffer[0]; - - _msgpack_buffer_consumed(b, 1); - - return r; -} - -static inline int msgpack_buffer_read_1(msgpack_buffer_t* b) -{ - if(msgpack_buffer_top_readable_size(b) <= 0) { - if(b->io == Qnil) { - return -1; - } - _msgpack_buffer_feed_from_io(b); - } - - int r = (int) (unsigned char) b->read_buffer[0]; - _msgpack_buffer_consumed(b, 1); - - return r; -} - - -/* - * bulk read / skip functions - */ - -size_t msgpack_buffer_read_nonblock(msgpack_buffer_t* b, char* buffer, size_t length); - -static inline bool msgpack_buffer_ensure_readable(msgpack_buffer_t* b, size_t require) -{ - if(msgpack_buffer_top_readable_size(b) < require) { - size_t sz = msgpack_buffer_all_readable_size(b); - if(sz < require) { - if(b->io == Qnil) { - return false; - } - do { - size_t rl = _msgpack_buffer_feed_from_io(b); - sz += rl; - } while(sz < require); - } - } - return true; -} - -bool _msgpack_buffer_read_all2(msgpack_buffer_t* b, char* buffer, size_t length); - -static inline bool msgpack_buffer_read_all(msgpack_buffer_t* b, char* buffer, size_t length) -{ - size_t avail = msgpack_buffer_top_readable_size(b); - if(avail < length) { - return _msgpack_buffer_read_all2(b, buffer, length); - } - - memcpy(buffer, b->read_buffer, length); - _msgpack_buffer_consumed(b, length); - return true; -} - -static inline size_t msgpack_buffer_skip_nonblock(msgpack_buffer_t* b, size_t length) -{ - size_t avail = msgpack_buffer_top_readable_size(b); - if(avail < length) { - return msgpack_buffer_read_nonblock(b, NULL, length); - } - _msgpack_buffer_consumed(b, length); - return length; -} - -size_t msgpack_buffer_read_to_string_nonblock(msgpack_buffer_t* b, VALUE string, size_t length); - -static inline size_t msgpack_buffer_read_to_string(msgpack_buffer_t* b, VALUE string, size_t length) -{ - if(length == 0) { - return 0; - } - - size_t avail = msgpack_buffer_top_readable_size(b); - if(avail > 0) { - return msgpack_buffer_read_to_string_nonblock(b, string, length); - } else if(b->io != Qnil) { - return _msgpack_buffer_read_from_io_to_string(b, string, length); - } else { - return 0; - } -} - -static inline size_t msgpack_buffer_skip(msgpack_buffer_t* b, size_t length) -{ - if(length == 0) { - return 0; - } - - size_t avail = msgpack_buffer_top_readable_size(b); - if(avail > 0) { - return msgpack_buffer_skip_nonblock(b, length); - } else if(b->io != Qnil) { - return _msgpack_buffer_skip_from_io(b, length); - } else { - return 0; - } -} - - -VALUE msgpack_buffer_all_as_string(msgpack_buffer_t* b); - -VALUE msgpack_buffer_all_as_string_array(msgpack_buffer_t* b); - -static inline VALUE _msgpack_buffer_refer_head_mapped_string(msgpack_buffer_t* b, size_t length) -{ - size_t offset = b->read_buffer - b->head->first; - return rb_str_substr(b->head->mapped_string, offset, length); -} - -static inline VALUE msgpack_buffer_read_top_as_string(msgpack_buffer_t* b, size_t length, bool will_be_frozen, bool utf8) -{ - /* optimize */ - if(!will_be_frozen && - b->head->mapped_string != NO_MAPPED_STRING && - length >= b->read_reference_threshold) { - VALUE result = _msgpack_buffer_refer_head_mapped_string(b, length); - if (utf8) ENCODING_SET(result, msgpack_rb_encindex_utf8); - _msgpack_buffer_consumed(b, length); - return result; - } - - VALUE result; - -#ifdef HAVE_RB_ENC_INTERNED_STR - if (will_be_frozen) { - if (RB_ENC_INTERNED_STR_NULL_CHECK && length == 0) { - result = rb_enc_interned_str("", length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding()); - } else { - result = rb_enc_interned_str(b->read_buffer, length, utf8 ? rb_utf8_encoding() : rb_ascii8bit_encoding()); - } - } else { - if (utf8) { - result = rb_utf8_str_new(b->read_buffer, length); - } else { - result = rb_str_new(b->read_buffer, length); - } - } - _msgpack_buffer_consumed(b, length); - return result; - -#else - - if (utf8) { - result = rb_utf8_str_new(b->read_buffer, length); - } else { - result = rb_str_new(b->read_buffer, length); - } - - if (will_be_frozen) { -#if STR_UMINUS_DEDUPE_FROZEN - // Starting from MRI 2.8 it is preferable to freeze the string - // before deduplication so that it can be interned directly - // otherwise it would be duplicated first which is wasteful. - rb_str_freeze(result); -#endif //STR_UMINUS_DEDUPE_FROZEN - // MRI 2.5 and older do not deduplicate strings that are already - // frozen. - result = rb_funcall(result, s_uminus, 0); - } - _msgpack_buffer_consumed(b, length); - return result; - -#endif // HAVE_RB_ENC_INTERNED_STR -} - -static inline VALUE msgpack_buffer_read_top_as_symbol(msgpack_buffer_t* b, size_t length, bool utf8) -{ - return rb_str_intern(msgpack_buffer_read_top_as_string(b, length, true, utf8)); -} - -// Hash keys are likely to be repeated, and are frozen. -// As such we can re-use them if we keep a cache of the ones we've seen so far, -// and save much more expensive lookups into the global fstring table. -// This cache implementation is deliberately simple, as we're optimizing for compactness, -// to be able to fit easily embeded inside msgpack_unpacker_t. -// As such, binary search into a sorted array gives a good tradeoff between compactness and -// performance. -#define MSGPACK_KEY_CACHE_CAPACITY 63 - -typedef struct msgpack_key_cache_t msgpack_key_cache_t; -struct msgpack_key_cache_t { - int length; - VALUE entries[MSGPACK_KEY_CACHE_CAPACITY]; -}; - -static inline VALUE build_interned_string(const char *str, const long length) -{ -# ifdef HAVE_RB_ENC_INTERNED_STR - return rb_enc_interned_str(str, length, rb_utf8_encoding()); -# else - VALUE rstring = rb_utf8_str_new(str, length); - return rb_funcall(rb_str_freeze(rstring), s_uminus, 0); -# endif -} - -static inline VALUE build_symbol(const char *str, const long length) -{ - return rb_str_intern(build_interned_string(str, length)); -} - -static void rvalue_cache_insert_at(msgpack_key_cache_t *cache, int index, VALUE rstring) -{ - MEMMOVE(&cache->entries[index + 1], &cache->entries[index], VALUE, cache->length - index); - cache->length++; - cache->entries[index] = rstring; -} - -static inline int rstring_cache_cmp(const char *str, const long length, VALUE rstring) -{ - long rstring_length = RSTRING_LEN(rstring); - if (length == rstring_length) { - return memcmp(str, RSTRING_PTR(rstring), length); - } else { - return (int)(length - rstring_length); - } -} - -static VALUE rstring_cache_fetch(msgpack_key_cache_t *cache, const char *str, const long length) -{ - int low = 0; - int high = cache->length - 1; - int mid = 0; - int last_cmp = 0; - - while (low <= high) { - mid = (high + low) >> 1; - VALUE entry = cache->entries[mid]; - last_cmp = rstring_cache_cmp(str, length, entry); - - if (last_cmp == 0) { - return entry; - } else if (last_cmp > 0) { - low = mid + 1; - } else { - high = mid - 1; - } - } - - VALUE rstring = build_interned_string(str, length); - - if (cache->length < MSGPACK_KEY_CACHE_CAPACITY) { - if (last_cmp > 0) { - mid += 1; - } - - rvalue_cache_insert_at(cache, mid, rstring); - } - return rstring; -} - -static VALUE rsymbol_cache_fetch(msgpack_key_cache_t *cache, const char *str, const long length) -{ - int low = 0; - int high = cache->length - 1; - int mid = 0; - int last_cmp = 0; - - while (low <= high) { - mid = (high + low) >> 1; - VALUE entry = cache->entries[mid]; - last_cmp = rstring_cache_cmp(str, length, rb_sym2str(entry)); - - if (last_cmp == 0) { - return entry; - } else if (last_cmp > 0) { - low = mid + 1; - } else { - high = mid - 1; - } - } - - VALUE rsymbol = build_symbol(str, length); - - if (cache->length < MSGPACK_KEY_CACHE_CAPACITY) { - if (last_cmp > 0) { - mid += 1; - } - - rvalue_cache_insert_at(cache, mid, rsymbol); - } - return rsymbol; -} - -static inline VALUE msgpack_buffer_read_top_as_interned_symbol(msgpack_buffer_t* b, msgpack_key_cache_t *cache, size_t length) -{ - VALUE result = rsymbol_cache_fetch(cache, b->read_buffer, length); - _msgpack_buffer_consumed(b, length); - return result; -} - -static inline VALUE msgpack_buffer_read_top_as_interned_string(msgpack_buffer_t* b, msgpack_key_cache_t *cache, size_t length) -{ - VALUE result = rstring_cache_fetch(cache, b->read_buffer, length); - _msgpack_buffer_consumed(b, length); - return result; -} - -#endif diff --git a/ext/msgpack/buffer_class.c b/ext/msgpack/buffer_class.c deleted file mode 100644 index 3e6f6f42..00000000 --- a/ext/msgpack/buffer_class.c +++ /dev/null @@ -1,616 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "compat.h" -#include "ruby.h" -#include "buffer.h" -#include "buffer_class.h" - -VALUE cMessagePack_Buffer = Qnil; -VALUE cMessagePack_HeldBuffer = Qnil; - -static ID s_read; -static ID s_readpartial; -static ID s_write; -static ID s_append; -static ID s_close; -static ID s_at_owner; - -static VALUE sym_read_reference_threshold; -static VALUE sym_write_reference_threshold; -static VALUE sym_io_buffer_size; - -typedef struct msgpack_held_buffer_t msgpack_held_buffer_t; -struct msgpack_held_buffer_t { - size_t size; - VALUE mapped_strings[]; -}; - -static void HeldBuffer_mark(void *data) -{ - msgpack_held_buffer_t* held_buffer = (msgpack_held_buffer_t*)data; - for (size_t index = 0; index < held_buffer->size; index++) { - rb_gc_mark(held_buffer->mapped_strings[index]); - } -} - -static size_t HeldBuffer_memsize(const void *data) -{ - const msgpack_held_buffer_t* held_buffer = (msgpack_held_buffer_t*)data; - return sizeof(size_t) + sizeof(VALUE) * held_buffer->size; -} - -static const rb_data_type_t held_buffer_data_type = { - .wrap_struct_name = "msgpack:held_buffer", - .function = { - .dmark = HeldBuffer_mark, - .dfree = RUBY_TYPED_DEFAULT_FREE, - .dsize = HeldBuffer_memsize, - }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY -}; - -VALUE MessagePack_Buffer_hold(msgpack_buffer_t* buffer) -{ - size_t mapped_strings_count = 0; - msgpack_buffer_chunk_t* c = buffer->head; - while (c != &buffer->tail) { - if (c->mapped_string != NO_MAPPED_STRING) { - mapped_strings_count++; - } - c = c->next; - } - if (c->mapped_string != NO_MAPPED_STRING) { - mapped_strings_count++; - } - - if (mapped_strings_count == 0) { - return Qnil; - } - - msgpack_held_buffer_t* held_buffer = xmalloc(sizeof(msgpack_held_buffer_t) + mapped_strings_count * sizeof(VALUE)); - - c = buffer->head; - mapped_strings_count = 0; - while (c != &buffer->tail) { - if (c->mapped_string != NO_MAPPED_STRING) { - held_buffer->mapped_strings[mapped_strings_count] = c->mapped_string; - mapped_strings_count++; - } - c = c->next; - } - if (c->mapped_string != NO_MAPPED_STRING) { - held_buffer->mapped_strings[mapped_strings_count] = c->mapped_string; - mapped_strings_count++; - } - held_buffer->size = mapped_strings_count; - return TypedData_Wrap_Struct(cMessagePack_HeldBuffer, &held_buffer_data_type, held_buffer); -} - - -#define CHECK_STRING_TYPE(value) \ - value = rb_check_string_type(value); \ - if( NIL_P(value) ) { \ - rb_raise(rb_eTypeError, "instance of String needed"); \ - } - -static void Buffer_free(void* data) -{ - if(data == NULL) { - return; - } - msgpack_buffer_t* b = (msgpack_buffer_t*) data; - msgpack_buffer_destroy(b); - xfree(b); -} - -static size_t Buffer_memsize(const void *data) -{ - return sizeof(msgpack_buffer_t) + msgpack_buffer_memsize(data); -} - -static const rb_data_type_t buffer_data_type = { - .wrap_struct_name = "msgpack:buffer", - .function = { - .dmark = msgpack_buffer_mark, - .dfree = Buffer_free, - .dsize = Buffer_memsize, - }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY -}; - -static const rb_data_type_t buffer_view_data_type = { - .wrap_struct_name = "msgpack:buffer_view", - .function = { - .dmark = NULL, - .dfree = NULL, - .dsize = NULL, - }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY -}; - -static inline msgpack_buffer_t *MessagePack_Buffer_get(VALUE object) -{ - msgpack_buffer_t *buffer; - bool view = RTEST(rb_ivar_get(object, s_at_owner)); - TypedData_Get_Struct(object, msgpack_buffer_t, view ? &buffer_view_data_type : &buffer_data_type, buffer); - if (!buffer) { - rb_raise(rb_eArgError, "Uninitialized Buffer object"); - } - return buffer; -} - -static VALUE Buffer_alloc(VALUE klass) -{ - msgpack_buffer_t* b; - VALUE buffer = TypedData_Make_Struct(klass, msgpack_buffer_t, &buffer_data_type, b); - msgpack_buffer_init(b); - rb_ivar_set(buffer, s_at_owner, Qnil); - return buffer; -} - -static ID get_partial_read_method(VALUE io) -{ - if(io != Qnil && rb_respond_to(io, s_readpartial)) { - return s_readpartial; - } - return s_read; -} - -static ID get_write_all_method(VALUE io) -{ - if(io != Qnil) { - if(rb_respond_to(io, s_write)) { - return s_write; - } else if(rb_respond_to(io, s_append)) { - return s_append; - } - } - return s_write; -} - -void MessagePack_Buffer_set_options(msgpack_buffer_t* b, VALUE io, VALUE options) -{ - b->io = io; - b->io_partial_read_method = get_partial_read_method(io); - b->io_write_all_method = get_write_all_method(io); - - if(options != Qnil) { - VALUE v; - - v = rb_hash_aref(options, sym_read_reference_threshold); - if(v != Qnil) { - msgpack_buffer_set_read_reference_threshold(b, NUM2SIZET(v)); - } - - v = rb_hash_aref(options, sym_write_reference_threshold); - if(v != Qnil) { - msgpack_buffer_set_write_reference_threshold(b, NUM2SIZET(v)); - } - - v = rb_hash_aref(options, sym_io_buffer_size); - if(v != Qnil) { - msgpack_buffer_set_io_buffer_size(b, NUM2SIZET(v)); - } - } -} - -VALUE MessagePack_Buffer_wrap(msgpack_buffer_t* b, VALUE owner) -{ - VALUE buffer = TypedData_Wrap_Struct(cMessagePack_Buffer, &buffer_view_data_type, b); - rb_ivar_set(buffer, s_at_owner, owner); - return buffer; -} - -static VALUE Buffer_initialize(int argc, VALUE* argv, VALUE self) -{ - VALUE io = Qnil; - VALUE options = Qnil; - - if(argc == 0 || (argc == 1 && argv[0] == Qnil)) { - /* Qnil */ - - } else if(argc == 1) { - VALUE v = argv[0]; - if(rb_type(v) == T_HASH) { - options = v; - } else { - io = v; - } - - } else if(argc == 2) { - io = argv[0]; - options = argv[1]; - if(rb_type(options) != T_HASH) { - rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(io)); - } - - } else { - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..1)", argc); - } - - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - - MessagePack_Buffer_set_options(b, io, options); - - return self; -} - -static VALUE Buffer_clear(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - msgpack_buffer_clear(b); - return Qnil; -} - -static VALUE Buffer_size(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - size_t size = msgpack_buffer_all_readable_size(b); - return SIZET2NUM(size); -} - -static VALUE Buffer_empty_p(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - if(msgpack_buffer_top_readable_size(b) == 0) { - return Qtrue; - } else { - return Qfalse; - } -} - -static VALUE Buffer_write(VALUE self, VALUE string_or_buffer) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - - VALUE string = string_or_buffer; // TODO optimize if string_or_buffer is a Buffer - StringValue(string); - - size_t length = msgpack_buffer_append_string(b, string); - - return SIZET2NUM(length); -} - -static VALUE Buffer_append(VALUE self, VALUE string_or_buffer) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - - VALUE string = string_or_buffer; // TODO optimize if string_or_buffer is a Buffer - StringValue(string); - - msgpack_buffer_append_string(b, string); - - return self; -} - - -#define MAKE_EMPTY_STRING(orig) \ - if(orig == Qnil) { \ - orig = rb_str_buf_new(0); \ - } else { \ - rb_str_resize(orig, 0); \ - } - -static VALUE read_until_eof_rescue(VALUE args) -{ - msgpack_buffer_t* b = (void*) ((VALUE*) args)[0]; - VALUE out = ((VALUE*) args)[1]; - unsigned long max = ((VALUE*) args)[2]; - size_t* sz = (void*) ((VALUE*) args)[3]; - - while(true) { - size_t rl; - if(max == 0) { - if(out == Qnil) { - rl = msgpack_buffer_skip(b, b->io_buffer_size); - } else { - rl = msgpack_buffer_read_to_string(b, out, b->io_buffer_size); - } - if(rl == 0) { - break; - } - *sz += rl; - - } else { - if(out == Qnil) { - rl = msgpack_buffer_skip(b, max); - } else { - rl = msgpack_buffer_read_to_string(b, out, max); - } - if(rl == 0) { - break; - } - *sz += rl; - if(max <= rl) { - break; - } else { - max -= rl; - } - } - } - - return Qnil; -} - -static VALUE read_until_eof_error(VALUE args, VALUE error) -{ - /* ignore EOFError */ - UNUSED(args); - UNUSED(error); - return Qnil; -} - -static inline size_t read_until_eof(msgpack_buffer_t* b, VALUE out, unsigned long max) -{ - if(msgpack_buffer_has_io(b)) { - size_t sz = 0; - VALUE args[4] = { (VALUE)(void*) b, out, (VALUE) max, (VALUE)(void*) &sz }; - rb_rescue2(read_until_eof_rescue, (VALUE)(void*) args, - read_until_eof_error, (VALUE)(void*) args, - rb_eEOFError, NULL); - return sz; - - } else { - if(max == 0) { - max = ULONG_MAX; - } - if(out == Qnil) { - return msgpack_buffer_skip_nonblock(b, max); - } else { - return msgpack_buffer_read_to_string_nonblock(b, out, max); - } - } -} - -static inline VALUE read_all(msgpack_buffer_t* b, VALUE out) -{ - if(out == Qnil && !msgpack_buffer_has_io(b)) { - /* same as to_s && clear; optimize */ - VALUE str = msgpack_buffer_all_as_string(b); - msgpack_buffer_clear(b); - return str; - } - - MAKE_EMPTY_STRING(out); - read_until_eof(b, out, 0); - return out; -} - -static VALUE Buffer_skip(VALUE self, VALUE sn) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - - unsigned long n = FIX2ULONG(sn); - - /* do nothing */ - if(n == 0) { - return INT2NUM(0); - } - - size_t sz = read_until_eof(b, Qnil, n); - return SIZET2NUM(sz); -} - -static VALUE Buffer_skip_all(VALUE self, VALUE sn) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - - unsigned long n = FIX2ULONG(sn); - - /* do nothing */ - if(n == 0) { - return self; - } - - if(!msgpack_buffer_ensure_readable(b, n)) { - rb_raise(rb_eEOFError, "end of buffer reached"); - } - - msgpack_buffer_skip_nonblock(b, n); - - return self; -} - -static VALUE Buffer_read_all(int argc, VALUE* argv, VALUE self) -{ - VALUE out = Qnil; - unsigned long n = 0; - bool all = false; - - switch(argc) { - case 2: - out = argv[1]; - /* pass through */ - case 1: - n = FIX2ULONG(argv[0]); - break; - case 0: - all = true; - break; - default: - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); - } - - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - - if(out != Qnil) { - CHECK_STRING_TYPE(out); - } - - if(all) { - return read_all(b, out); - } - - if(n == 0) { - /* do nothing */ - MAKE_EMPTY_STRING(out); - return out; - } - - if(!msgpack_buffer_ensure_readable(b, n)) { - rb_raise(rb_eEOFError, "end of buffer reached"); - } - - MAKE_EMPTY_STRING(out); - msgpack_buffer_read_to_string_nonblock(b, out, n); - - return out; -} - -static VALUE Buffer_read(int argc, VALUE* argv, VALUE self) -{ - VALUE out = Qnil; - unsigned long n = -1; - bool all = false; - - switch(argc) { - case 2: - out = argv[1]; - /* pass through */ - case 1: - n = FIX2ULONG(argv[0]); - break; - case 0: - all = true; - break; - default: - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); - } - - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - - if(out != Qnil) { - CHECK_STRING_TYPE(out); - } - - if(all) { - return read_all(b, out); - } - - if(n == 0) { - /* do nothing */ - MAKE_EMPTY_STRING(out); - return out; - } - - if(!msgpack_buffer_has_io(b) && out == Qnil && - msgpack_buffer_all_readable_size(b) <= n) { - /* same as to_s && clear; optimize */ - VALUE str = msgpack_buffer_all_as_string(b); - msgpack_buffer_clear(b); - - if(RSTRING_LEN(str) == 0) { - return Qnil; - } else { - return str; - } - } - - MAKE_EMPTY_STRING(out); - read_until_eof(b, out, n); - - if(RSTRING_LEN(out) == 0) { - return Qnil; - } else { - return out; - } -} - -static VALUE Buffer_to_str(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - return msgpack_buffer_all_as_string(b); -} - -static VALUE Buffer_to_a(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - return msgpack_buffer_all_as_string_array(b); -} - -static VALUE Buffer_flush(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - msgpack_buffer_flush(b); - return self; -} - -static VALUE Buffer_io(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - return b->io; -} - -static VALUE Buffer_close(VALUE self) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - if(b->io != Qnil) { - return rb_funcall(b->io, s_close, 0); - } - return Qnil; -} - -static VALUE Buffer_write_to(VALUE self, VALUE io) -{ - msgpack_buffer_t *b = MessagePack_Buffer_get(self); - size_t sz = msgpack_buffer_flush_to_io(b, io, s_write, true); - return SIZET2NUM(sz); -} - -void MessagePack_Buffer_module_init(VALUE mMessagePack) -{ - s_read = rb_intern("read"); - s_readpartial = rb_intern("readpartial"); - s_write = rb_intern("write"); - s_append = rb_intern("<<"); - s_close = rb_intern("close"); - s_at_owner = rb_intern("@owner"); - - sym_read_reference_threshold = ID2SYM(rb_intern("read_reference_threshold")); - sym_write_reference_threshold = ID2SYM(rb_intern("write_reference_threshold")); - sym_io_buffer_size = ID2SYM(rb_intern("io_buffer_size")); - - msgpack_buffer_static_init(); - - cMessagePack_HeldBuffer = rb_define_class_under(mMessagePack, "HeldBuffer", rb_cBasicObject); - rb_undef_alloc_func(cMessagePack_HeldBuffer); - - cMessagePack_Buffer = rb_define_class_under(mMessagePack, "Buffer", rb_cObject); - - rb_define_alloc_func(cMessagePack_Buffer, Buffer_alloc); - - rb_define_method(cMessagePack_Buffer, "initialize", Buffer_initialize, -1); - rb_define_method(cMessagePack_Buffer, "clear", Buffer_clear, 0); - rb_define_method(cMessagePack_Buffer, "size", Buffer_size, 0); - rb_define_method(cMessagePack_Buffer, "empty?", Buffer_empty_p, 0); - rb_define_method(cMessagePack_Buffer, "write", Buffer_write, 1); - rb_define_method(cMessagePack_Buffer, "<<", Buffer_append, 1); - rb_define_method(cMessagePack_Buffer, "skip", Buffer_skip, 1); - rb_define_method(cMessagePack_Buffer, "skip_all", Buffer_skip_all, 1); - rb_define_method(cMessagePack_Buffer, "read", Buffer_read, -1); - rb_define_method(cMessagePack_Buffer, "read_all", Buffer_read_all, -1); - rb_define_method(cMessagePack_Buffer, "io", Buffer_io, 0); - rb_define_method(cMessagePack_Buffer, "flush", Buffer_flush, 0); - rb_define_method(cMessagePack_Buffer, "close", Buffer_close, 0); - rb_define_method(cMessagePack_Buffer, "write_to", Buffer_write_to, 1); - rb_define_method(cMessagePack_Buffer, "to_str", Buffer_to_str, 0); - rb_define_alias(cMessagePack_Buffer, "to_s", "to_str"); - rb_define_method(cMessagePack_Buffer, "to_a", Buffer_to_a, 0); -} - diff --git a/ext/msgpack/buffer_class.h b/ext/msgpack/buffer_class.h deleted file mode 100644 index db4d9ce8..00000000 --- a/ext/msgpack/buffer_class.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_BUFFER_CLASS_H__ -#define MSGPACK_RUBY_BUFFER_CLASS_H__ - -#include "buffer.h" - -extern VALUE cMessagePack_Buffer; - -void MessagePack_Buffer_module_init(VALUE mMessagePack); - -VALUE MessagePack_Buffer_wrap(msgpack_buffer_t* b, VALUE owner); -VALUE MessagePack_Buffer_hold(msgpack_buffer_t* b); - -void MessagePack_Buffer_set_options(msgpack_buffer_t* b, VALUE io, VALUE options); - -#endif - diff --git a/ext/msgpack/compat.h b/ext/msgpack/compat.h deleted file mode 100644 index b12ca06d..00000000 --- a/ext/msgpack/compat.h +++ /dev/null @@ -1,26 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_COMPAT_H__ -#define MSGPACK_RUBY_COMPAT_H__ - -#include <stdbool.h> -#include "ruby.h" -#include "ruby/encoding.h" - -#endif - diff --git a/ext/msgpack/extconf.rb b/ext/msgpack/extconf.rb deleted file mode 100644 index b1b921c8..00000000 --- a/ext/msgpack/extconf.rb +++ /dev/null @@ -1,53 +0,0 @@ -require 'mkmf' - -have_func("rb_enc_interned_str", "ruby.h") # Ruby 3.0+ -have_func("rb_hash_new_capa", "ruby.h") # Ruby 3.2+ -have_func("rb_proc_call_with_block", "ruby.h") # CRuby (TruffleRuby doesn't have it) -have_func("rb_gc_mark_locations", "ruby.h") # Missing on TruffleRuby - -append_cflags([ - "-fvisibility=hidden", - "-I..", - "-Wall", - "-std=gnu99" -]) - -if ENV["MSGPACK_DEBUG"] - append_cflags(RbConfig::CONFIG["debugflags"]) if RbConfig::CONFIG["debugflags"] - append_cflags("-DRUBY_DEBUG=1") -end - -if RUBY_VERSION.start_with?('3.0.') && RUBY_VERSION <= '3.0.5' - # https://bugs.ruby-lang.org/issues/18772 - append_cflags("-DRB_ENC_INTERNED_STR_NULL_CHECK=1") -end - -# checking if Hash#[]= (rb_hash_aset) dedupes string keys (Ruby 2.6+) -h = {} -x = {} -r = rand.to_s -h[%W(#{r}).join('')] = :foo -x[%W(#{r}).join('')] = :foo -if x.keys[0].equal?(h.keys[0]) - append_cflags("-DHASH_ASET_DEDUPE=1") -else - append_cflags("-DHASH_ASET_DEDUPE=0") -end - -# checking if String#-@ (str_uminus) directly interns frozen strings... ' (Ruby 3.0+) -begin - s = rand.to_s.freeze - if (-s).equal?(s) && (-s.dup).equal?(s) - append_cflags("-DSTR_UMINUS_DEDUPE_FROZEN=1") - else - append_cflags("-DSTR_UMINUS_DEDUPE_FROZEN=0") - end -rescue NoMethodError - append_cflags("-DSTR_UMINUS_DEDUPE_FROZEN=0") -end - -if warnflags = CONFIG['warnflags'] - warnflags.slice!(/ -Wdeclaration-after-statement/) -end - -create_makefile('msgpack/msgpack') diff --git a/ext/msgpack/extension_value_class.c b/ext/msgpack/extension_value_class.c deleted file mode 100644 index 20e78f80..00000000 --- a/ext/msgpack/extension_value_class.c +++ /dev/null @@ -1,34 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "factory_class.h" - -VALUE cMessagePack_ExtensionValue; - -VALUE MessagePack_ExtensionValue_new(int ext_type, VALUE payload) -{ - return rb_struct_new(cMessagePack_ExtensionValue, INT2FIX(ext_type), payload); -} - -void MessagePack_ExtensionValue_module_init(VALUE mMessagePack) -{ - /* rb_struct_define_under is not available ruby < 2.1 */ - //cMessagePack_ExtensionValue = rb_struct_define_under(mMessagePack, "ExtensionValue", "type", "payload", NULL); - cMessagePack_ExtensionValue = rb_struct_define(NULL, "type", "payload", NULL); - rb_define_const(mMessagePack, "ExtensionValue", cMessagePack_ExtensionValue); -} diff --git a/ext/msgpack/extension_value_class.h b/ext/msgpack/extension_value_class.h deleted file mode 100644 index a77035b5..00000000 --- a/ext/msgpack/extension_value_class.h +++ /dev/null @@ -1,31 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2015 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_EXTENSION_VALUE_CLASS_H__ -#define MSGPACK_RUBY_EXTENSION_VALUE_CLASS_H__ - -#include "compat.h" -#include "sysdep.h" - -extern VALUE cMessagePack_ExtensionValue; - -VALUE MessagePack_ExtensionValue_new(int ext_type, VALUE payload); - -void MessagePack_ExtensionValue_module_init(VALUE mMessagePack); - -#endif - diff --git a/ext/msgpack/factory_class.c b/ext/msgpack/factory_class.c deleted file mode 100644 index 1eeb0081..00000000 --- a/ext/msgpack/factory_class.c +++ /dev/null @@ -1,276 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "factory_class.h" -#include "packer_ext_registry.h" -#include "unpacker_ext_registry.h" -#include "buffer_class.h" -#include "packer_class.h" -#include "unpacker_class.h" - -VALUE cMessagePack_Factory; - -struct msgpack_factory_t; -typedef struct msgpack_factory_t msgpack_factory_t; - -struct msgpack_factory_t { - msgpack_packer_ext_registry_t pkrg; - msgpack_unpacker_ext_registry_t *ukrg; - bool has_bigint_ext_type; - bool has_symbol_ext_type; - bool optimized_symbol_ext_type; - int symbol_ext_type; -}; - -static void Factory_free(void *ptr) -{ - msgpack_factory_t *fc = ptr; - - if(fc == NULL) { - return; - } - msgpack_packer_ext_registry_destroy(&fc->pkrg); - msgpack_unpacker_ext_registry_release(fc->ukrg); - xfree(fc); -} - -void Factory_mark(void *ptr) -{ - msgpack_factory_t *fc = ptr; - msgpack_packer_ext_registry_mark(&fc->pkrg); - msgpack_unpacker_ext_registry_mark(fc->ukrg); -} - -static size_t Factory_memsize(const void *ptr) -{ - const msgpack_factory_t *fc = ptr; - size_t total_size = sizeof(msgpack_factory_t); - - if (fc->ukrg) { - total_size += sizeof(msgpack_unpacker_ext_registry_t) / (fc->ukrg->borrow_count + 1); - } - - return total_size; -} - -static const rb_data_type_t factory_data_type = { - .wrap_struct_name = "msgpack:factory", - .function = { - .dmark = Factory_mark, - .dfree = Factory_free, - .dsize = Factory_memsize, - }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY | RUBY_TYPED_WB_PROTECTED -}; - -static inline msgpack_factory_t *Factory_get(VALUE object) -{ - msgpack_factory_t *factory; - TypedData_Get_Struct(object, msgpack_factory_t, &factory_data_type, factory); - if (!factory) { - rb_raise(rb_eArgError, "Uninitialized Factory object"); - } - return factory; -} - -static VALUE Factory_alloc(VALUE klass) -{ - msgpack_factory_t *fc; - return TypedData_Make_Struct(klass, msgpack_factory_t, &factory_data_type, fc); -} - -static VALUE Factory_initialize(int argc, VALUE* argv, VALUE self) -{ - msgpack_factory_t *fc = Factory_get(self); - - msgpack_packer_ext_registry_init(self, &fc->pkrg); - // fc->ukrg is lazily initialized - - fc->has_symbol_ext_type = false; - - switch (argc) { - case 0: - break; - default: - // TODO options is not supported yet - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0)", argc); - } - - return Qnil; -} - -static VALUE Factory_dup(VALUE self) -{ - VALUE clone = Factory_alloc(rb_obj_class(self)); - - msgpack_factory_t *fc = Factory_get(self); - msgpack_factory_t *cloned_fc = Factory_get(clone); - - cloned_fc->has_symbol_ext_type = fc->has_symbol_ext_type; - cloned_fc->pkrg = fc->pkrg; - msgpack_unpacker_ext_registry_borrow(fc->ukrg, &cloned_fc->ukrg); - msgpack_packer_ext_registry_dup(clone, &fc->pkrg, &cloned_fc->pkrg); - - return clone; -} - -static VALUE Factory_freeze(VALUE self) { - if(!rb_obj_frozen_p(self)) { - msgpack_factory_t *fc = Factory_get(self); - - if (RTEST(fc->pkrg.hash)) { - rb_hash_freeze(fc->pkrg.hash); - if (!RTEST(fc->pkrg.cache)) { - // If the factory is frozen, we can safely share the packer cache between - // all packers. So we eagerly create it now so it's available when #packer - // is called. - RB_OBJ_WRITE(self, &fc->pkrg.cache, rb_hash_new()); - } - } - - rb_obj_freeze(self); - } - - return self; -} - -VALUE MessagePack_Factory_packer(int argc, VALUE* argv, VALUE self) -{ - msgpack_factory_t *fc = Factory_get(self); - - VALUE packer = MessagePack_Packer_alloc(cMessagePack_Packer); - MessagePack_Packer_initialize(argc, argv, packer); - - msgpack_packer_t* pk = MessagePack_Packer_get(packer); - msgpack_packer_ext_registry_destroy(&pk->ext_registry); - msgpack_packer_ext_registry_borrow(packer, &fc->pkrg, &pk->ext_registry); - pk->has_bigint_ext_type = fc->has_bigint_ext_type; - pk->has_symbol_ext_type = fc->has_symbol_ext_type; - - return packer; -} - -VALUE MessagePack_Factory_unpacker(int argc, VALUE* argv, VALUE self) -{ - msgpack_factory_t *fc = Factory_get(self); - - VALUE unpacker = MessagePack_Unpacker_alloc(cMessagePack_Unpacker); - MessagePack_Unpacker_initialize(argc, argv, unpacker); - - msgpack_unpacker_t* uk = MessagePack_Unpacker_get(unpacker); - msgpack_unpacker_ext_registry_borrow(fc->ukrg, &uk->ext_registry); - uk->optimized_symbol_ext_type = fc->optimized_symbol_ext_type; - uk->symbol_ext_type = fc->symbol_ext_type; - - return unpacker; -} - -static VALUE Factory_registered_types_internal(VALUE self) -{ - msgpack_factory_t *fc = Factory_get(self); - - VALUE uk_mapping = rb_hash_new(); - if (fc->ukrg) { - for(int i=0; i < 256; i++) { - if(!NIL_P(fc->ukrg->array[i])) { - rb_hash_aset(uk_mapping, INT2FIX(i - 128), fc->ukrg->array[i]); - } - } - } - - return rb_ary_new3( - 2, - RTEST(fc->pkrg.hash) ? rb_hash_dup(fc->pkrg.hash) : rb_hash_new(), - uk_mapping - ); -} - -static VALUE Factory_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE ext_module, VALUE options) -{ - msgpack_factory_t *fc = Factory_get(self); - - Check_Type(rb_ext_type, T_FIXNUM); - - if(rb_type(ext_module) != T_MODULE && rb_type(ext_module) != T_CLASS) { - rb_raise(rb_eArgError, "expected Module/Class but found %s.", rb_obj_classname(ext_module)); - } - - int flags = 0; - - VALUE packer_proc = Qnil; - VALUE unpacker_proc = Qnil; - if(!NIL_P(options)) { - Check_Type(options, T_HASH); - packer_proc = rb_hash_aref(options, ID2SYM(rb_intern("packer"))); - unpacker_proc = rb_hash_aref(options, ID2SYM(rb_intern("unpacker"))); - } - - if (OBJ_FROZEN(self)) { - rb_raise(rb_eFrozenError, "can't modify frozen MessagePack::Factory"); - } - - int ext_type = NUM2INT(rb_ext_type); - if(ext_type < -128 || ext_type > 127) { - rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type); - } - - if(ext_module == rb_cSymbol) { - if(NIL_P(options) || RTEST(rb_hash_aref(options, ID2SYM(rb_intern("packer"))))) { - fc->has_symbol_ext_type = true; - } - if(RTEST(options) && RTEST(rb_hash_aref(options, ID2SYM(rb_intern("optimized_symbols_parsing"))))) { - fc->optimized_symbol_ext_type = true; - } - } - - if(RTEST(options)) { - if(RTEST(rb_hash_aref(options, ID2SYM(rb_intern("oversized_integer_extension"))))) { - if(ext_module == rb_cInteger) { - fc->has_bigint_ext_type = true; - } else { - rb_raise(rb_eArgError, "oversized_integer_extension: true is only for Integer class"); - } - } - - if(RTEST(rb_hash_aref(options, ID2SYM(rb_intern("recursive"))))) { - flags |= MSGPACK_EXT_RECURSIVE; - } - } - - msgpack_packer_ext_registry_put(self, &fc->pkrg, ext_module, ext_type, flags, packer_proc); - msgpack_unpacker_ext_registry_put(self, &fc->ukrg, ext_module, ext_type, flags, unpacker_proc); - - return Qnil; -} - -void MessagePack_Factory_module_init(VALUE mMessagePack) -{ - cMessagePack_Factory = rb_define_class_under(mMessagePack, "Factory", rb_cObject); - - rb_define_alloc_func(cMessagePack_Factory, Factory_alloc); - - rb_define_method(cMessagePack_Factory, "initialize", Factory_initialize, -1); - rb_define_method(cMessagePack_Factory, "dup", Factory_dup, 0); - rb_define_method(cMessagePack_Factory, "freeze", Factory_freeze, 0); - - rb_define_method(cMessagePack_Factory, "packer", MessagePack_Factory_packer, -1); - rb_define_method(cMessagePack_Factory, "unpacker", MessagePack_Factory_unpacker, -1); - - rb_define_private_method(cMessagePack_Factory, "registered_types_internal", Factory_registered_types_internal, 0); - rb_define_private_method(cMessagePack_Factory, "register_type_internal", Factory_register_type_internal, 3); -} diff --git a/ext/msgpack/factory_class.h b/ext/msgpack/factory_class.h deleted file mode 100644 index e4f233c0..00000000 --- a/ext/msgpack/factory_class.h +++ /dev/null @@ -1,33 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2015 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_FACTORY_CLASS_H__ -#define MSGPACK_RUBY_FACTORY_CLASS_H__ - -#include "compat.h" -#include "sysdep.h" - -extern VALUE cMessagePack_Factory; - -extern VALUE MessagePack_Factory_packer(int argc, VALUE* argv, VALUE self); - -extern VALUE MessagePack_Factory_unpacker(int argc, VALUE* argv, VALUE self); - -void MessagePack_Factory_module_init(VALUE mMessagePack); - -#endif - diff --git a/ext/msgpack/packer.c b/ext/msgpack/packer.c deleted file mode 100644 index 8e8dd966..00000000 --- a/ext/msgpack/packer.c +++ /dev/null @@ -1,199 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "packer.h" -#include "buffer_class.h" - -#if !defined(HAVE_RB_PROC_CALL_WITH_BLOCK) -#define rb_proc_call_with_block(recv, argc, argv, block) rb_funcallv(recv, rb_intern("call"), argc, argv) -#endif - -void msgpack_packer_init(msgpack_packer_t* pk) -{ - msgpack_buffer_init(PACKER_BUFFER_(pk)); -} - -void msgpack_packer_destroy(msgpack_packer_t* pk) -{ - msgpack_buffer_destroy(PACKER_BUFFER_(pk)); -} - -void msgpack_packer_mark(msgpack_packer_t* pk) -{ - /* See MessagePack_Buffer_wrap */ - /* msgpack_buffer_mark(PACKER_BUFFER_(pk)); */ - rb_gc_mark(pk->buffer_ref); - rb_gc_mark(pk->to_msgpack_arg); -} - -void msgpack_packer_reset(msgpack_packer_t* pk) -{ - msgpack_buffer_clear(PACKER_BUFFER_(pk)); - - pk->buffer_ref = Qnil; -} - - -void msgpack_packer_write_array_value(msgpack_packer_t* pk, VALUE v) -{ - /* actual return type of RARRAY_LEN is long */ - unsigned long len = RARRAY_LEN(v); - if(len > 0xffffffffUL) { - rb_raise(rb_eArgError, "size of array is too long to pack: %lu bytes should be <= %lu", len, 0xffffffffUL); - } - unsigned int len32 = (unsigned int)len; - msgpack_packer_write_array_header(pk, len32); - - unsigned int i; - for(i=0; i < len32; ++i) { - VALUE e = rb_ary_entry(v, i); - msgpack_packer_write_value(pk, e); - } -} - -static int write_hash_foreach(VALUE key, VALUE value, VALUE pk_value) -{ - if (key == Qundef) { - return ST_CONTINUE; - } - msgpack_packer_t* pk = (msgpack_packer_t*) pk_value; - msgpack_packer_write_value(pk, key); - msgpack_packer_write_value(pk, value); - return ST_CONTINUE; -} - -void msgpack_packer_write_hash_value(msgpack_packer_t* pk, VALUE v) -{ - /* actual return type of RHASH_SIZE is long (if SIZEOF_LONG == SIZEOF_VOIDP - * or long long (if SIZEOF_LONG_LONG == SIZEOF_VOIDP. See st.h. */ - unsigned long len = RHASH_SIZE(v); - if(len > 0xffffffffUL) { - rb_raise(rb_eArgError, "size of array is too long to pack: %ld bytes should be <= %lu", len, 0xffffffffUL); - } - unsigned int len32 = (unsigned int)len; - msgpack_packer_write_map_header(pk, len32); - - rb_hash_foreach(v, write_hash_foreach, (VALUE) pk); -} - -struct msgpack_call_proc_args_t; -typedef struct msgpack_call_proc_args_t msgpack_call_proc_args_t; -struct msgpack_call_proc_args_t { - VALUE proc; - VALUE args[2]; -}; - -VALUE msgpack_packer_try_calling_proc(VALUE value) -{ - msgpack_call_proc_args_t *args = (msgpack_call_proc_args_t *)value; - return rb_proc_call_with_block(args->proc, 2, args->args, Qnil); -} - -bool msgpack_packer_try_write_with_ext_type_lookup(msgpack_packer_t* pk, VALUE v) -{ - int ext_type, ext_flags; - - VALUE proc = msgpack_packer_ext_registry_lookup(&pk->ext_registry, v, &ext_type, &ext_flags); - - if(proc == Qnil) { - return false; - } - - if(ext_flags & MSGPACK_EXT_RECURSIVE) { - VALUE held_buffer = MessagePack_Buffer_hold(&pk->buffer); - - msgpack_buffer_t parent_buffer = pk->buffer; - msgpack_buffer_init(PACKER_BUFFER_(pk)); - - int exception_occured = 0; - msgpack_call_proc_args_t args = { proc, { v, pk->to_msgpack_arg } }; - rb_protect(msgpack_packer_try_calling_proc, (VALUE)&args, &exception_occured); - - if (exception_occured) { - msgpack_buffer_destroy(PACKER_BUFFER_(pk)); - pk->buffer = parent_buffer; - rb_jump_tag(exception_occured); // re-raise the exception - } else { - VALUE payload = msgpack_buffer_all_as_string(PACKER_BUFFER_(pk)); - StringValue(payload); - msgpack_buffer_destroy(PACKER_BUFFER_(pk)); - pk->buffer = parent_buffer; - msgpack_packer_write_ext(pk, ext_type, payload); - } - - RB_GC_GUARD(held_buffer); - } else { - VALUE payload = rb_proc_call_with_block(proc, 1, &v, Qnil); - StringValue(payload); - msgpack_packer_write_ext(pk, ext_type, payload); - } - - return true; -} - -void msgpack_packer_write_other_value(msgpack_packer_t* pk, VALUE v) -{ - if(!(msgpack_packer_try_write_with_ext_type_lookup(pk, v))) { - rb_funcall(v, pk->to_msgpack_method, 1, pk->to_msgpack_arg); - } -} - -void msgpack_packer_write_value(msgpack_packer_t* pk, VALUE v) -{ - switch(rb_type(v)) { - case T_NIL: - msgpack_packer_write_nil(pk); - break; - case T_TRUE: - msgpack_packer_write_true(pk); - break; - case T_FALSE: - msgpack_packer_write_false(pk); - break; - case T_FIXNUM: - msgpack_packer_write_fixnum_value(pk, v); - break; - case T_SYMBOL: - msgpack_packer_write_symbol_value(pk, v); - break; - case T_STRING: - if(rb_class_of(v) == rb_cString || !msgpack_packer_try_write_with_ext_type_lookup(pk, v)) { - msgpack_packer_write_string_value(pk, v); - } - break; - case T_ARRAY: - if(rb_class_of(v) == rb_cArray || !msgpack_packer_try_write_with_ext_type_lookup(pk, v)) { - msgpack_packer_write_array_value(pk, v); - } - break; - case T_HASH: - if(rb_class_of(v) == rb_cHash || !msgpack_packer_try_write_with_ext_type_lookup(pk, v)) { - msgpack_packer_write_hash_value(pk, v); - } - break; - case T_BIGNUM: - msgpack_packer_write_bignum_value(pk, v); - break; - case T_FLOAT: - msgpack_packer_write_float_value(pk, v); - break; - default: - msgpack_packer_write_other_value(pk, v); - } -} - diff --git a/ext/msgpack/packer.h b/ext/msgpack/packer.h deleted file mode 100644 index f3441f5f..00000000 --- a/ext/msgpack/packer.h +++ /dev/null @@ -1,513 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_PACKER_H__ -#define MSGPACK_RUBY_PACKER_H__ - -#include "buffer.h" -#include "packer_ext_registry.h" - -#ifndef MSGPACK_PACKER_IO_FLUSH_THRESHOLD_TO_WRITE_STRING_BODY -#define MSGPACK_PACKER_IO_FLUSH_THRESHOLD_TO_WRITE_STRING_BODY (1024) -#endif - -#ifndef UNREACHABLE_RETURN -// Ruby 2.5 -#define UNREACHABLE_RETURN() return -#endif - -struct msgpack_packer_t; -typedef struct msgpack_packer_t msgpack_packer_t; - -struct msgpack_packer_t { - msgpack_buffer_t buffer; - - ID to_msgpack_method; - VALUE to_msgpack_arg; - - VALUE buffer_ref; - - bool compatibility_mode; - bool has_bigint_ext_type; - bool has_symbol_ext_type; - - /* options */ - bool comaptibility_mode; - msgpack_packer_ext_registry_t ext_registry; -}; - -#define PACKER_BUFFER_(pk) (&(pk)->buffer) - -void msgpack_packer_init(msgpack_packer_t* pk); - -void msgpack_packer_destroy(msgpack_packer_t* pk); - -void msgpack_packer_mark(msgpack_packer_t* pk); - -bool msgpack_packer_try_write_with_ext_type_lookup(msgpack_packer_t* pk, VALUE v); - -static inline void msgpack_packer_set_to_msgpack_method(msgpack_packer_t* pk, - ID to_msgpack_method, VALUE to_msgpack_arg) -{ - pk->to_msgpack_method = to_msgpack_method; - pk->to_msgpack_arg = to_msgpack_arg; -} - -void msgpack_packer_reset(msgpack_packer_t* pk); - -static inline void msgpack_packer_set_compat(msgpack_packer_t* pk, bool enable) -{ - pk->compatibility_mode = enable; -} - -static inline void msgpack_packer_write_nil(msgpack_packer_t* pk) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1); - msgpack_buffer_write_1(PACKER_BUFFER_(pk), 0xc0); -} - -static inline void msgpack_packer_write_true(msgpack_packer_t* pk) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1); - msgpack_buffer_write_1(PACKER_BUFFER_(pk), 0xc3); -} - -static inline void msgpack_packer_write_false(msgpack_packer_t* pk) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1); - msgpack_buffer_write_1(PACKER_BUFFER_(pk), 0xc2); -} - -static inline void _msgpack_packer_write_fixint(msgpack_packer_t* pk, int8_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1); - msgpack_buffer_write_1(PACKER_BUFFER_(pk), v); -} - -static inline void _msgpack_packer_write_uint8(msgpack_packer_t* pk, uint8_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xcc, v); -} - -static inline void _msgpack_packer_write_uint16(msgpack_packer_t* pk, uint16_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3); - uint16_t be = _msgpack_be16(v); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xcd, (const void*)&be, 2); -} - -static inline void _msgpack_packer_write_uint32(msgpack_packer_t* pk, uint32_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5); - uint32_t be = _msgpack_be32(v); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xce, (const void*)&be, 4); -} - -static inline void _msgpack_packer_write_uint64(msgpack_packer_t* pk, uint64_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9); - uint64_t be = _msgpack_be64(v); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xcf, (const void*)&be, 8); -} - -static inline void _msgpack_packer_write_int8(msgpack_packer_t* pk, int8_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd0, v); -} - -static inline void _msgpack_packer_write_int16(msgpack_packer_t* pk, int16_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3); - uint16_t be = _msgpack_be16(v); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd1, (const void*)&be, 2); -} - -static inline void _msgpack_packer_write_int32(msgpack_packer_t* pk, int32_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5); - uint32_t be = _msgpack_be32(v); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd2, (const void*)&be, 4); -} - -static inline void _msgpack_packer_write_int64(msgpack_packer_t* pk, int64_t v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9); - uint64_t be = _msgpack_be64(v); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd3, (const void*)&be, 8); -} - -static inline void _msgpack_packer_write_long32(msgpack_packer_t* pk, long v) -{ - if(v < -0x20L) { - if(v < -0x8000L) { - _msgpack_packer_write_int32(pk, (int32_t) v); - } else if(v < -0x80L) { - _msgpack_packer_write_int16(pk, (int16_t) v); - } else { - _msgpack_packer_write_int8(pk, (int8_t) v); - } - } else if(v <= 0x7fL) { - _msgpack_packer_write_fixint(pk, (int8_t) v); - } else { - if(v <= 0xffL) { - _msgpack_packer_write_uint8(pk, (uint8_t) v); - } else if(v <= 0xffffL) { - _msgpack_packer_write_uint16(pk, (uint16_t) v); - } else { - _msgpack_packer_write_uint32(pk, (uint32_t) v); - } - } -} - -static inline void _msgpack_packer_write_long_long64(msgpack_packer_t* pk, long long v) -{ - if(v < -0x20LL) { - if(v < -0x8000LL) { - if(v < -0x80000000LL) { - _msgpack_packer_write_int64(pk, (int64_t) v); - } else { - _msgpack_packer_write_int32(pk, (int32_t) v); - } - } else { - if(v < -0x80LL) { - _msgpack_packer_write_int16(pk, (int16_t) v); - } else { - _msgpack_packer_write_int8(pk, (int8_t) v); - } - } - } else if(v <= 0x7fLL) { - _msgpack_packer_write_fixint(pk, (int8_t) v); - } else { - if(v <= 0xffffLL) { - if(v <= 0xffLL) { - _msgpack_packer_write_uint8(pk, (uint8_t) v); - } else { - _msgpack_packer_write_uint16(pk, (uint16_t) v); - } - } else { - if(v <= 0xffffffffLL) { - _msgpack_packer_write_uint32(pk, (uint32_t) v); - } else { - _msgpack_packer_write_uint64(pk, (uint64_t) v); - } - } - } -} - -static inline void msgpack_packer_write_long(msgpack_packer_t* pk, long v) -{ -#if defined(SIZEOF_LONG) -# if SIZEOF_LONG <= 4 - _msgpack_packer_write_long32(pk, v); -# else - _msgpack_packer_write_long_long64(pk, v); -# endif - -#elif defined(LONG_MAX) -# if LONG_MAX <= 0x7fffffffL - _msgpack_packer_write_long32(pk, v); -# else - _msgpack_packer_write_long_long64(pk, v); -# endif - -#else - if(sizeof(long) <= 4) { - _msgpack_packer_write_long32(pk, v); - } else { - _msgpack_packer_write_long_long64(pk, v); - } -#endif -} - -static inline void msgpack_packer_write_long_long(msgpack_packer_t* pk, long long v) -{ - /* assuming sizeof(long long) == 8 */ - _msgpack_packer_write_long_long64(pk, v); -} - -static inline void msgpack_packer_write_u64(msgpack_packer_t* pk, uint64_t v) -{ - if(v <= 0xffULL) { - if(v <= 0x7fULL) { - _msgpack_packer_write_fixint(pk, (int8_t) v); - } else { - _msgpack_packer_write_uint8(pk, (uint8_t) v); - } - } else { - if(v <= 0xffffULL) { - _msgpack_packer_write_uint16(pk, (uint16_t) v); - } else if(v <= 0xffffffffULL) { - _msgpack_packer_write_uint32(pk, (uint32_t) v); - } else { - _msgpack_packer_write_uint64(pk, (uint64_t) v); - } - } -} - -static inline void msgpack_packer_write_float(msgpack_packer_t* pk, float v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5); - union { - float f; - uint32_t u32; - char mem[4]; - } castbuf = { v }; - castbuf.u32 = _msgpack_be_float(castbuf.u32); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xca, castbuf.mem, 4); -} - -static inline void msgpack_packer_write_double(msgpack_packer_t* pk, double v) -{ - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 9); - union { - double d; - uint64_t u64; - char mem[8]; - } castbuf = { v }; - castbuf.u64 = _msgpack_be_double(castbuf.u64); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xcb, castbuf.mem, 8); -} - -static inline void msgpack_packer_write_raw_header(msgpack_packer_t* pk, unsigned int n) -{ - if(n < 32) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1); - unsigned char h = 0xa0 | (uint8_t) n; - msgpack_buffer_write_1(PACKER_BUFFER_(pk), h); - } else if(n < 256 && !pk->compatibility_mode) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - unsigned char be = (uint8_t) n; - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xd9, (const void*)&be, 1); - } else if(n < 65536) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3); - uint16_t be = _msgpack_be16(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xda, (const void*)&be, 2); - } else { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5); - uint32_t be = _msgpack_be32(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdb, (const void*)&be, 4); - } -} - -static inline void msgpack_packer_write_bin_header(msgpack_packer_t* pk, unsigned int n) -{ - if(n < 256) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - unsigned char be = (uint8_t) n; - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc4, (const void*)&be, 1); - } else if(n < 65536) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3); - uint16_t be = _msgpack_be16(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc5, (const void*)&be, 2); - } else { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5); - uint32_t be = _msgpack_be32(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc6, (const void*)&be, 4); - } -} - -static inline void msgpack_packer_write_array_header(msgpack_packer_t* pk, unsigned int n) -{ - if(n < 16) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1); - unsigned char h = 0x90 | (uint8_t) n; - msgpack_buffer_write_1(PACKER_BUFFER_(pk), h); - } else if(n < 65536) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3); - uint16_t be = _msgpack_be16(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdc, (const void*)&be, 2); - } else { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5); - uint32_t be = _msgpack_be32(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdd, (const void*)&be, 4); - } -} - -static inline void msgpack_packer_write_map_header(msgpack_packer_t* pk, unsigned int n) -{ - if(n < 16) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 1); - unsigned char h = 0x80 | (uint8_t) n; - msgpack_buffer_write_1(PACKER_BUFFER_(pk), h); - } else if(n < 65536) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3); - uint16_t be = _msgpack_be16(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xde, (const void*)&be, 2); - } else { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 5); - uint32_t be = _msgpack_be32(n); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xdf, (const void*)&be, 4); - } -} - -static inline void msgpack_packer_write_ext(msgpack_packer_t* pk, int ext_type, VALUE payload) -{ - unsigned long len = RSTRING_LEN(payload); - switch (len) { - case 1: - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd4, ext_type); - break; - case 2: - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd5, ext_type); - break; - case 4: - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd6, ext_type); - break; - case 8: - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd7, ext_type); - break; - case 16: - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 2); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xd8, ext_type); - break; - default: - if(len < 256) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 3); - msgpack_buffer_write_2(PACKER_BUFFER_(pk), 0xc7, len); - msgpack_buffer_write_1(PACKER_BUFFER_(pk), ext_type); - } else if(len < 65536) { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 4); - uint16_t be = _msgpack_be16(len); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc8, (const void*)&be, 2); - msgpack_buffer_write_1(PACKER_BUFFER_(pk), ext_type); - } else { - msgpack_buffer_ensure_writable(PACKER_BUFFER_(pk), 6); - uint32_t be = _msgpack_be32(len); - msgpack_buffer_write_byte_and_data(PACKER_BUFFER_(pk), 0xc9, (const void*)&be, 4); - msgpack_buffer_write_1(PACKER_BUFFER_(pk), ext_type); - } - } - msgpack_buffer_append_string(PACKER_BUFFER_(pk), payload); -} - -static inline bool msgpack_packer_is_binary(VALUE v, int encindex) -{ - return encindex == msgpack_rb_encindex_ascii8bit; -} - -static inline bool msgpack_packer_is_utf8_compat_string(VALUE v, int encindex) -{ - return encindex == msgpack_rb_encindex_utf8 - || encindex == msgpack_rb_encindex_usascii - || ENC_CODERANGE_ASCIIONLY(v); -} - -static inline void msgpack_packer_write_string_value(msgpack_packer_t* pk, VALUE v) -{ - long len = RSTRING_LEN(v); - - if(RB_UNLIKELY(len > 0xffffffffL)) { - rb_raise(rb_eArgError, "size of string is too long to pack: %lu bytes should be <= %ld", len, 0xffffffffL); - UNREACHABLE_RETURN(); - } - - if (RB_UNLIKELY(pk->compatibility_mode)) { - msgpack_packer_write_raw_header(pk, (unsigned int)len); - msgpack_buffer_append_string(PACKER_BUFFER_(pk), v); - return; - } - - int encindex = ENCODING_GET_INLINED(v); - if(msgpack_packer_is_binary(v, encindex)) { - /* write ASCII-8BIT string using Binary type */ - msgpack_packer_write_bin_header(pk, (unsigned int)len); - msgpack_buffer_append_string(PACKER_BUFFER_(pk), v); - } else { - /* write UTF-8, US-ASCII, or 7bit-safe ascii-compatible string using String type directly */ - /* in compatibility mode, packer packs String values as is */ - if(RB_UNLIKELY(!msgpack_packer_is_utf8_compat_string(v, encindex))) { - /* transcode other strings to UTF-8 and write using String type */ - VALUE enc = rb_enc_from_encoding(rb_utf8_encoding()); /* rb_enc_from_encoding_index is not extern */ - v = rb_str_encode(v, enc, 0, Qnil); - len = RSTRING_LEN(v); - } - msgpack_packer_write_raw_header(pk, (unsigned int)len); - msgpack_buffer_append_string(PACKER_BUFFER_(pk), v); - } -} - -static inline void msgpack_packer_write_symbol_string_value(msgpack_packer_t* pk, VALUE v) -{ - msgpack_packer_write_string_value(pk, rb_sym2str(v)); -} - -void msgpack_packer_write_other_value(msgpack_packer_t* pk, VALUE v); - -static inline void msgpack_packer_write_symbol_value(msgpack_packer_t* pk, VALUE v) -{ - if (pk->has_symbol_ext_type) { - msgpack_packer_write_other_value(pk, v); - } else { - msgpack_packer_write_symbol_string_value(pk, v); - } -} - -static inline void msgpack_packer_write_fixnum_value(msgpack_packer_t* pk, VALUE v) -{ - msgpack_packer_write_long(pk, FIX2LONG(v)); -} - -static inline void msgpack_packer_write_bignum_value(msgpack_packer_t* pk, VALUE v) -{ - int leading_zero_bits; - size_t required_size = rb_absint_size(v, &leading_zero_bits); - - if(RBIGNUM_POSITIVE_P(v)) { - if(required_size > 8 && pk->has_bigint_ext_type) { - if(msgpack_packer_try_write_with_ext_type_lookup(pk, v)) { - return; - } - // if we didn't return here `msgpack_packer_write_u64` will raise a RangeError - } - - msgpack_packer_write_u64(pk, rb_big2ull(v)); - } else { - if(leading_zero_bits == 0) { - required_size += 1; - } - - if(required_size > 8 && pk->has_bigint_ext_type) { - if(msgpack_packer_try_write_with_ext_type_lookup(pk, v)) { - return; - } - // if we didn't return here `msgpack_packer_write_u64` will raise a RangeError - } - - msgpack_packer_write_long_long(pk, rb_big2ll(v)); - } -} - -static inline void msgpack_packer_write_float_value(msgpack_packer_t* pk, VALUE v) -{ - msgpack_packer_write_double(pk, rb_num2dbl(v)); -} - -void msgpack_packer_write_array_value(msgpack_packer_t* pk, VALUE v); - -void msgpack_packer_write_hash_value(msgpack_packer_t* pk, VALUE v); - -void msgpack_packer_write_value(msgpack_packer_t* pk, VALUE v); - - -#endif - diff --git a/ext/msgpack/packer_class.c b/ext/msgpack/packer_class.c deleted file mode 100644 index aebdf39d..00000000 --- a/ext/msgpack/packer_class.c +++ /dev/null @@ -1,442 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "compat.h" -#include "ruby.h" -#include "packer.h" -#include "packer_class.h" -#include "buffer_class.h" -#include "factory_class.h" - -VALUE cMessagePack_Packer; - -static ID s_to_msgpack; -static ID s_write; - -static VALUE sym_compatibility_mode; - -//static VALUE s_packer_value; -//static msgpack_packer_t* s_packer; - -static void Packer_free(void *ptr) -{ - msgpack_packer_t* pk = ptr; - if(pk == NULL) { - return; - } - msgpack_packer_ext_registry_destroy(&pk->ext_registry); - msgpack_packer_destroy(pk); - xfree(pk); -} - -static void Packer_mark(void *ptr) -{ - msgpack_packer_t* pk = ptr; - msgpack_buffer_mark(pk); - msgpack_packer_mark(pk); - msgpack_packer_ext_registry_mark(&pk->ext_registry); -} - -static size_t Packer_memsize(const void *ptr) -{ - const msgpack_packer_t* pk = ptr; - return sizeof(msgpack_packer_t) + msgpack_buffer_memsize(&pk->buffer); -} - -const rb_data_type_t packer_data_type = { - .wrap_struct_name = "msgpack:packer", - .function = { - .dmark = Packer_mark, - .dfree = Packer_free, - .dsize = Packer_memsize, - }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY -}; - - -VALUE MessagePack_Packer_alloc(VALUE klass) -{ - msgpack_packer_t* pk; - VALUE self = TypedData_Make_Struct(klass, msgpack_packer_t, &packer_data_type, pk); - msgpack_packer_init(pk); - msgpack_packer_set_to_msgpack_method(pk, s_to_msgpack, self); - return self; -} - -VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self) -{ - if(argc > 2) { - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); - } - - VALUE io = Qnil; - VALUE options = Qnil; - - if(argc >= 1) { - io = argv[0]; - } - - if(argc == 2) { - options = argv[1]; - } - - if (options == Qnil && rb_type(io) == T_HASH) { - options = io; - io = Qnil; - } - - if(options != Qnil) { - Check_Type(options, T_HASH); - } - - msgpack_packer_t *pk = MessagePack_Packer_get(self); - - msgpack_packer_ext_registry_init(self, &pk->ext_registry); - pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self); - - MessagePack_Buffer_set_options(PACKER_BUFFER_(pk), io, options); - - if(options != Qnil) { - VALUE v; - - v = rb_hash_aref(options, sym_compatibility_mode); - msgpack_packer_set_compat(pk, RTEST(v)); - } - - return self; -} - -static VALUE Packer_compatibility_mode_p(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - return pk->compatibility_mode ? Qtrue : Qfalse; -} - -static VALUE Packer_buffer(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - if (!RTEST(pk->buffer_ref)) { - pk->buffer_ref = MessagePack_Buffer_wrap(PACKER_BUFFER_(pk), self); - } - return pk->buffer_ref; -} - -static VALUE Packer_write(VALUE self, VALUE v) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_value(pk, v); - return self; -} - -static VALUE Packer_write_nil(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_nil(pk); - return self; -} - -static VALUE Packer_write_true(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_true(pk); - return self; -} - -static VALUE Packer_write_false(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_false(pk); - return self; -} - -static VALUE Packer_write_float(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_float_value(pk, obj); - return self; -} - -static VALUE Packer_write_string(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - Check_Type(obj, T_STRING); - msgpack_packer_write_string_value(pk, obj); - return self; -} - -static VALUE Packer_write_bin(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - Check_Type(obj, T_STRING); - - VALUE enc = rb_enc_from_encoding(rb_ascii8bit_encoding()); - obj = rb_str_encode(obj, enc, 0, Qnil); - - msgpack_packer_write_string_value(pk, obj); - return self; -} - -static VALUE Packer_write_array(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - Check_Type(obj, T_ARRAY); - msgpack_packer_write_array_value(pk, obj); - return self; -} - -static VALUE Packer_write_hash(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - Check_Type(obj, T_HASH); - msgpack_packer_write_hash_value(pk, obj); - return self; -} - -static VALUE Packer_write_symbol(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - Check_Type(obj, T_SYMBOL); - msgpack_packer_write_symbol_value(pk, obj); - return self; -} - -static VALUE Packer_write_int(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - - if (FIXNUM_P(obj)) { - msgpack_packer_write_fixnum_value(pk, obj); - } else { - Check_Type(obj, T_BIGNUM); - msgpack_packer_write_bignum_value(pk, obj); - } - return self; -} - -static VALUE Packer_write_extension(VALUE self, VALUE obj) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - Check_Type(obj, T_STRUCT); - - VALUE rb_ext_type = RSTRUCT_GET(obj, 0); - if(!RB_TYPE_P(rb_ext_type, T_FIXNUM)) { - rb_raise(rb_eRangeError, "integer %s too big to convert to `signed char'", RSTRING_PTR(rb_String(rb_ext_type))); - } - - int ext_type = FIX2INT(rb_ext_type); - if(ext_type < -128 || ext_type > 127) { - rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type); - } - VALUE payload = RSTRUCT_GET(obj, 1); - StringValue(payload); - msgpack_packer_write_ext(pk, ext_type, payload); - - return self; -} - -static VALUE Packer_write_array_header(VALUE self, VALUE n) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_array_header(pk, NUM2UINT(n)); - return self; -} - -static VALUE Packer_write_map_header(VALUE self, VALUE n) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_map_header(pk, NUM2UINT(n)); - return self; -} - -static VALUE Packer_write_bin_header(VALUE self, VALUE n) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_bin_header(pk, NUM2UINT(n)); - return self; -} - -static VALUE Packer_write_float32(VALUE self, VALUE numeric) -{ - if(!rb_obj_is_kind_of(numeric, rb_cNumeric)) { - rb_raise(rb_eArgError, "Expected numeric"); - } - - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_packer_write_float(pk, (float)rb_num2dbl(numeric)); - return self; -} - -static VALUE Packer_write_ext(VALUE self, VALUE type, VALUE data) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - int ext_type = NUM2INT(type); - if(ext_type < -128 || ext_type > 127) { - rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type); - } - StringValue(data); - msgpack_packer_write_ext(pk, ext_type, data); - return self; -} - -static VALUE Packer_flush(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_buffer_flush(PACKER_BUFFER_(pk)); - return self; -} - -static VALUE Packer_reset(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - msgpack_buffer_clear(PACKER_BUFFER_(pk)); - return Qnil; -} - -static VALUE Packer_size(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - size_t size = msgpack_buffer_all_readable_size(PACKER_BUFFER_(pk)); - return SIZET2NUM(size); -} - -static VALUE Packer_empty_p(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - if(msgpack_buffer_top_readable_size(PACKER_BUFFER_(pk)) == 0) { - return Qtrue; - } else { - return Qfalse; - } -} - -static VALUE Packer_to_str(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - return msgpack_buffer_all_as_string(PACKER_BUFFER_(pk)); -} - -static VALUE Packer_to_a(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - return msgpack_buffer_all_as_string_array(PACKER_BUFFER_(pk)); -} - -static VALUE Packer_write_to(VALUE self, VALUE io) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - size_t sz = msgpack_buffer_flush_to_io(PACKER_BUFFER_(pk), io, s_write, true); - return SIZET2NUM(sz); -} - -static VALUE Packer_registered_types_internal(VALUE self) -{ - msgpack_packer_t *pk = MessagePack_Packer_get(self); - if (RTEST(pk->ext_registry.hash)) { - return rb_hash_dup(pk->ext_registry.hash); - } - return rb_hash_new(); -} - -static VALUE Packer_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE ext_module, VALUE proc) -{ - if (OBJ_FROZEN(self)) { - rb_raise(rb_eFrozenError, "can't modify frozen MessagePack::Packer"); - } - - msgpack_packer_t *pk = MessagePack_Packer_get(self); - - int ext_type = NUM2INT(rb_ext_type); - if(ext_type < -128 || ext_type > 127) { - rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type); - } - - msgpack_packer_ext_registry_put(self, &pk->ext_registry, ext_module, ext_type, 0, proc); - - if (ext_module == rb_cSymbol) { - pk->has_symbol_ext_type = true; - } - - return Qnil; -} - -VALUE Packer_full_pack(VALUE self) -{ - VALUE retval; - - msgpack_packer_t *pk = MessagePack_Packer_get(self); - - if(msgpack_buffer_has_io(PACKER_BUFFER_(pk))) { - msgpack_buffer_flush(PACKER_BUFFER_(pk)); - retval = Qnil; - } else { - retval = msgpack_buffer_all_as_string(PACKER_BUFFER_(pk)); - } - - msgpack_buffer_clear(PACKER_BUFFER_(pk)); /* to free rmem before GC */ - - return retval; -} - -void MessagePack_Packer_module_init(VALUE mMessagePack) -{ - s_to_msgpack = rb_intern("to_msgpack"); - s_write = rb_intern("write"); - - sym_compatibility_mode = ID2SYM(rb_intern("compatibility_mode")); - cMessagePack_Packer = rb_define_class_under(mMessagePack, "Packer", rb_cObject); - - rb_define_alloc_func(cMessagePack_Packer, MessagePack_Packer_alloc); - - rb_define_method(cMessagePack_Packer, "initialize", MessagePack_Packer_initialize, -1); - rb_define_method(cMessagePack_Packer, "compatibility_mode?", Packer_compatibility_mode_p, 0); - rb_define_method(cMessagePack_Packer, "buffer", Packer_buffer, 0); - rb_define_method(cMessagePack_Packer, "write", Packer_write, 1); - rb_define_alias(cMessagePack_Packer, "pack", "write"); - rb_define_method(cMessagePack_Packer, "write_nil", Packer_write_nil, 0); - rb_define_method(cMessagePack_Packer, "write_true", Packer_write_true, 0); - rb_define_method(cMessagePack_Packer, "write_false", Packer_write_false, 0); - rb_define_method(cMessagePack_Packer, "write_float", Packer_write_float, 1); - rb_define_method(cMessagePack_Packer, "write_string", Packer_write_string, 1); - rb_define_method(cMessagePack_Packer, "write_bin", Packer_write_bin, 1); - rb_define_method(cMessagePack_Packer, "write_array", Packer_write_array, 1); - rb_define_method(cMessagePack_Packer, "write_hash", Packer_write_hash, 1); - rb_define_method(cMessagePack_Packer, "write_symbol", Packer_write_symbol, 1); - rb_define_method(cMessagePack_Packer, "write_int", Packer_write_int, 1); - rb_define_method(cMessagePack_Packer, "write_extension", Packer_write_extension, 1); - rb_define_method(cMessagePack_Packer, "write_array_header", Packer_write_array_header, 1); - rb_define_method(cMessagePack_Packer, "write_map_header", Packer_write_map_header, 1); - rb_define_method(cMessagePack_Packer, "write_bin_header", Packer_write_bin_header, 1); - rb_define_method(cMessagePack_Packer, "write_ext", Packer_write_ext, 2); - rb_define_method(cMessagePack_Packer, "write_float32", Packer_write_float32, 1); - rb_define_method(cMessagePack_Packer, "flush", Packer_flush, 0); - - /* delegation methods */ - rb_define_method(cMessagePack_Packer, "reset", Packer_reset, 0); - rb_define_alias(cMessagePack_Packer, "clear", "reset"); - rb_define_method(cMessagePack_Packer, "size", Packer_size, 0); - rb_define_method(cMessagePack_Packer, "empty?", Packer_empty_p, 0); - rb_define_method(cMessagePack_Packer, "write_to", Packer_write_to, 1); - rb_define_method(cMessagePack_Packer, "to_str", Packer_to_str, 0); - rb_define_alias(cMessagePack_Packer, "to_s", "to_str"); - rb_define_method(cMessagePack_Packer, "to_a", Packer_to_a, 0); - - rb_define_private_method(cMessagePack_Packer, "registered_types_internal", Packer_registered_types_internal, 0); - rb_define_method(cMessagePack_Packer, "register_type_internal", Packer_register_type_internal, 3); - - rb_define_method(cMessagePack_Packer, "full_pack", Packer_full_pack, 0); -} diff --git a/ext/msgpack/packer_class.h b/ext/msgpack/packer_class.h deleted file mode 100644 index ad897fc7..00000000 --- a/ext/msgpack/packer_class.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_PACKER_CLASS_H__ -#define MSGPACK_RUBY_PACKER_CLASS_H__ - -#include "packer.h" - -extern VALUE cMessagePack_Packer; - -extern const rb_data_type_t packer_data_type; - -static inline msgpack_packer_t *MessagePack_Packer_get(VALUE object) { - msgpack_packer_t *packer; - TypedData_Get_Struct(object, msgpack_packer_t, &packer_data_type, packer); - if (!packer) { - rb_raise(rb_eArgError, "Uninitialized Packer object"); - } - return packer; -} - -void MessagePack_Packer_module_init(VALUE mMessagePack); - -VALUE MessagePack_Packer_alloc(VALUE klass); - -VALUE MessagePack_Packer_initialize(int argc, VALUE* argv, VALUE self); - -#endif - diff --git a/ext/msgpack/packer_ext_registry.c b/ext/msgpack/packer_ext_registry.c deleted file mode 100644 index 7c30a104..00000000 --- a/ext/msgpack/packer_ext_registry.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2015 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "packer_ext_registry.h" - -void msgpack_packer_ext_registry_init(VALUE owner, msgpack_packer_ext_registry_t* pkrg) -{ - RB_OBJ_WRITE(owner, &pkrg->hash, Qnil); - RB_OBJ_WRITE(owner, &pkrg->cache, Qnil); -} - -void msgpack_packer_ext_registry_mark(msgpack_packer_ext_registry_t* pkrg) -{ - rb_gc_mark(pkrg->hash); - rb_gc_mark(pkrg->cache); -} - -void msgpack_packer_ext_registry_borrow(VALUE owner, msgpack_packer_ext_registry_t* src, - msgpack_packer_ext_registry_t* dst) -{ - if(RTEST(src->hash)) { - if(rb_obj_frozen_p(src->hash)) { - // If the type registry is frozen we can safely share it, and share the cache as well. - RB_OBJ_WRITE(owner, &dst->hash, src->hash); - RB_OBJ_WRITE(owner, &dst->cache, src->cache); - } else { - RB_OBJ_WRITE(owner, &dst->hash, rb_hash_dup(src->hash)); - RB_OBJ_WRITE(owner, &dst->cache, NIL_P(src->cache) ? Qnil : rb_hash_dup(src->cache)); - } - } else { - RB_OBJ_WRITE(owner, &dst->hash, Qnil); - RB_OBJ_WRITE(owner, &dst->cache, Qnil); - } -} - -void msgpack_packer_ext_registry_dup(VALUE owner, msgpack_packer_ext_registry_t* src, - msgpack_packer_ext_registry_t* dst) -{ - RB_OBJ_WRITE(owner, &dst->hash, NIL_P(src->hash) ? Qnil : rb_hash_dup(src->hash)); - RB_OBJ_WRITE(owner, &dst->cache, NIL_P(src->cache) ? Qnil : rb_hash_dup(src->cache)); -} - -void msgpack_packer_ext_registry_put(VALUE owner, msgpack_packer_ext_registry_t* pkrg, - VALUE ext_module, int ext_type, int flags, VALUE proc) -{ - if(NIL_P(pkrg->hash)) { - RB_OBJ_WRITE(owner, &pkrg->hash, rb_hash_new()); - } - - if(NIL_P(pkrg->cache)) { - RB_OBJ_WRITE(owner, &pkrg->cache, rb_hash_new()); - } else { - /* clear lookup cache not to miss added type */ - rb_hash_clear(pkrg->cache); - } - - VALUE entry = rb_ary_new3(3, INT2FIX(ext_type), proc, INT2FIX(flags)); - rb_hash_aset(pkrg->hash, ext_module, entry); -} diff --git a/ext/msgpack/packer_ext_registry.h b/ext/msgpack/packer_ext_registry.h deleted file mode 100644 index 779f3efa..00000000 --- a/ext/msgpack/packer_ext_registry.h +++ /dev/null @@ -1,140 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2015 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_PACKER_EXT_REGISTRY_H__ -#define MSGPACK_RUBY_PACKER_EXT_REGISTRY_H__ - -#include "compat.h" -#include "ruby.h" - -#define MSGPACK_EXT_RECURSIVE 0b0001 - -struct msgpack_packer_ext_registry_t; -typedef struct msgpack_packer_ext_registry_t msgpack_packer_ext_registry_t; - -struct msgpack_packer_ext_registry_t { - VALUE hash; - VALUE cache; // lookup cache for ext types inherited from a super class -}; - -void msgpack_packer_ext_registry_init(VALUE owner, msgpack_packer_ext_registry_t* pkrg); - -static inline void msgpack_packer_ext_registry_destroy(msgpack_packer_ext_registry_t* pkrg) -{ } - -void msgpack_packer_ext_registry_mark(msgpack_packer_ext_registry_t* pkrg); - -void msgpack_packer_ext_registry_borrow(VALUE owner, msgpack_packer_ext_registry_t* src, - msgpack_packer_ext_registry_t* dst); - -void msgpack_packer_ext_registry_dup(VALUE owner, msgpack_packer_ext_registry_t* src, - msgpack_packer_ext_registry_t* dst); - -void msgpack_packer_ext_registry_put(VALUE owner, msgpack_packer_ext_registry_t* pkrg, - VALUE ext_module, int ext_type, int flags, VALUE proc); - -static int msgpack_packer_ext_find_superclass(VALUE key, VALUE value, VALUE arg) -{ - VALUE *args = (VALUE *) arg; - if(key == Qundef) { - return ST_CONTINUE; - } - if(rb_class_inherited_p(args[0], key) == Qtrue) { - args[1] = key; - return ST_STOP; - } - return ST_CONTINUE; -} - -static inline VALUE msgpack_packer_ext_registry_fetch(msgpack_packer_ext_registry_t* pkrg, - VALUE lookup_class, int* ext_type_result, int* ext_flags_result) -{ - // fetch lookup_class from hash, which is a hash to register classes - VALUE type = rb_hash_lookup(pkrg->hash, lookup_class); - if(type != Qnil) { - *ext_type_result = FIX2INT(rb_ary_entry(type, 0)); - *ext_flags_result = FIX2INT(rb_ary_entry(type, 2)); - return rb_ary_entry(type, 1); - } - - // fetch lookup_class from cache, which stores results of searching ancestors from pkrg->hash - if (RTEST(pkrg->cache)) { - VALUE type_inht = rb_hash_lookup(pkrg->cache, lookup_class); - if(type_inht != Qnil) { - *ext_type_result = FIX2INT(rb_ary_entry(type_inht, 0)); - *ext_flags_result = FIX2INT(rb_ary_entry(type_inht, 2)); - return rb_ary_entry(type_inht, 1); - } - } - - return Qnil; -} - -static inline VALUE msgpack_packer_ext_registry_lookup(msgpack_packer_ext_registry_t* pkrg, - VALUE instance, int* ext_type_result, int* ext_flags_result) -{ - VALUE type; - - if (pkrg->hash == Qnil) { // No extensions registered - return Qnil; - } - - /* - * 1. check whether singleton_class or class of this instance is registered (or resolved in past) or not. - * - * Objects of type Integer (Fixnum, Bignum), Float, Symbol and frozen - * `rb_class_of` returns the singleton_class if the object has one, or the "real class" otherwise. - */ - VALUE lookup_class = rb_class_of(instance); - type = msgpack_packer_ext_registry_fetch(pkrg, lookup_class, ext_type_result, ext_flags_result); - if(type != Qnil) { - return type; - } - - /* - * 2. If the object had a singleton_class check if the real class of instance is registered - * (or resolved in past) or not. - */ - VALUE real_class = rb_obj_class(instance); - if(lookup_class != real_class) { - type = msgpack_packer_ext_registry_fetch(pkrg, real_class, ext_type_result, ext_flags_result); - if(type != Qnil) { - return type; - } - } - - /* - * 3. check all keys whether it is an ancestor of lookup_class, or not - */ - VALUE args[2]; - args[0] = lookup_class; - args[1] = Qnil; - rb_hash_foreach(pkrg->hash, msgpack_packer_ext_find_superclass, (VALUE) args); - - VALUE superclass = args[1]; - if(superclass != Qnil) { - VALUE superclass_type = rb_hash_lookup(pkrg->hash, superclass); - rb_hash_aset(pkrg->cache, lookup_class, superclass_type); - *ext_type_result = FIX2INT(rb_ary_entry(superclass_type, 0)); - *ext_flags_result = FIX2INT(rb_ary_entry(superclass_type, 2)); - return rb_ary_entry(superclass_type, 1); - } - - return Qnil; -} - -#endif diff --git a/ext/msgpack/rbinit.c b/ext/msgpack/rbinit.c deleted file mode 100644 index 104cc19e..00000000 --- a/ext/msgpack/rbinit.c +++ /dev/null @@ -1,35 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "buffer_class.h" -#include "packer_class.h" -#include "unpacker_class.h" -#include "factory_class.h" -#include "extension_value_class.h" - -RUBY_FUNC_EXPORTED void Init_msgpack(void) -{ - VALUE mMessagePack = rb_define_module("MessagePack"); - - MessagePack_Buffer_module_init(mMessagePack); - MessagePack_Packer_module_init(mMessagePack); - MessagePack_Unpacker_module_init(mMessagePack); - MessagePack_Factory_module_init(mMessagePack); - MessagePack_ExtensionValue_module_init(mMessagePack); -} - diff --git a/ext/msgpack/rmem.c b/ext/msgpack/rmem.c deleted file mode 100644 index a6206f9a..00000000 --- a/ext/msgpack/rmem.c +++ /dev/null @@ -1,93 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "rmem.h" - -void msgpack_rmem_init(msgpack_rmem_t* pm) -{ - memset(pm, 0, sizeof(msgpack_rmem_t)); - pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32); - pm->head.mask = 0xffffffff; /* all bit is 1 = available */ -} - -void msgpack_rmem_destroy(msgpack_rmem_t* pm) -{ - msgpack_rmem_chunk_t* c = pm->array_first; - msgpack_rmem_chunk_t* cend = pm->array_last; - for(; c != cend; c++) { - xfree(c->pages); - } - xfree(pm->head.pages); - xfree(pm->array_first); -} - -void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm) -{ - msgpack_rmem_chunk_t* c = pm->array_first; - msgpack_rmem_chunk_t* last = pm->array_last; - for(; c != last; c++) { - if(_msgpack_rmem_chunk_available(c)) { - void* mem = _msgpack_rmem_chunk_alloc(c); - - /* move to head */ - msgpack_rmem_chunk_t tmp = pm->head; - pm->head = *c; - *c = tmp; - return mem; - } - } - - if(c == pm->array_end) { - size_t capacity = c - pm->array_first; - size_t length = last - pm->array_first; - capacity = (capacity == 0) ? 8 : capacity * 2; - msgpack_rmem_chunk_t* array = xrealloc(pm->array_first, capacity * sizeof(msgpack_rmem_chunk_t)); - pm->array_first = array; - pm->array_last = array + length; - pm->array_end = array + capacity; - } - - /* allocate new chunk */ - c = pm->array_last++; - - /* move head to array */ - *c = pm->head; - - pm->head.pages = NULL; /* make sure we don't point to another chunk's pages in case xmalloc triggers GC */ - pm->head.mask = 0xffffffff & (~1); /* "& (~1)" means first chunk is already allocated */ - pm->head.pages = xmalloc(MSGPACK_RMEM_PAGE_SIZE * 32); - - return pm->head.pages; -} - -void _msgpack_rmem_chunk_free(msgpack_rmem_t* pm, msgpack_rmem_chunk_t* c) -{ - if(pm->array_first->mask == 0xffffffff) { - /* free and move to last */ - pm->array_last--; - xfree(c->pages); - *c = *pm->array_last; - return; - } - - /* move to first */ - msgpack_rmem_chunk_t tmp = *pm->array_first; - *pm->array_first = *c; - *c = tmp; -} - diff --git a/ext/msgpack/rmem.h b/ext/msgpack/rmem.h deleted file mode 100644 index a22b8f06..00000000 --- a/ext/msgpack/rmem.h +++ /dev/null @@ -1,109 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_RMEM_H__ -#define MSGPACK_RUBY_RMEM_H__ - -#include "compat.h" -#include "sysdep.h" - -#ifndef MSGPACK_RMEM_PAGE_SIZE -#define MSGPACK_RMEM_PAGE_SIZE (4*1024) -#endif - -struct msgpack_rmem_t; -typedef struct msgpack_rmem_t msgpack_rmem_t; - -struct msgpack_rmem_chunk_t; -typedef struct msgpack_rmem_chunk_t msgpack_rmem_chunk_t; - -/* - * a chunk contains 32 pages. - * size of each buffer is MSGPACK_RMEM_PAGE_SIZE bytes. - */ -struct msgpack_rmem_chunk_t { - unsigned int mask; - char* pages; -}; - -struct msgpack_rmem_t { - msgpack_rmem_chunk_t head; - msgpack_rmem_chunk_t* array_first; - msgpack_rmem_chunk_t* array_last; - msgpack_rmem_chunk_t* array_end; -}; - -/* assert MSGPACK_RMEM_PAGE_SIZE % sysconf(_SC_PAGE_SIZE) == 0 */ -void msgpack_rmem_init(msgpack_rmem_t* pm); - -void msgpack_rmem_destroy(msgpack_rmem_t* pm); - -void* _msgpack_rmem_alloc2(msgpack_rmem_t* pm); - -#define _msgpack_rmem_chunk_available(c) ((c)->mask != 0) - -static inline void* _msgpack_rmem_chunk_alloc(msgpack_rmem_chunk_t* c) -{ - _msgpack_bsp32(pos, c->mask); - (c)->mask &= ~(1 << pos); - return ((char*)(c)->pages) + (pos * (MSGPACK_RMEM_PAGE_SIZE)); -} - -static inline bool _msgpack_rmem_chunk_try_free(msgpack_rmem_chunk_t* c, void* mem) -{ - ptrdiff_t pdiff = ((char*)(mem)) - ((char*)(c)->pages); - if(0 <= pdiff && pdiff < MSGPACK_RMEM_PAGE_SIZE * 32) { - size_t pos = pdiff / MSGPACK_RMEM_PAGE_SIZE; - (c)->mask |= (1 << pos); - return true; - } - return false; -} - -static inline void* msgpack_rmem_alloc(msgpack_rmem_t* pm) -{ - if(_msgpack_rmem_chunk_available(&pm->head)) { - return _msgpack_rmem_chunk_alloc(&pm->head); - } - return _msgpack_rmem_alloc2(pm); -} - -void _msgpack_rmem_chunk_free(msgpack_rmem_t* pm, msgpack_rmem_chunk_t* c); - -static inline bool msgpack_rmem_free(msgpack_rmem_t* pm, void* mem) -{ - if(_msgpack_rmem_chunk_try_free(&pm->head, mem)) { - return true; - } - - /* search from last */ - msgpack_rmem_chunk_t* c = pm->array_last - 1; - msgpack_rmem_chunk_t* before_first = pm->array_first - 1; - for(; c != before_first; c--) { - if(_msgpack_rmem_chunk_try_free(c, mem)) { - if(c != pm->array_first && c->mask == 0xffffffff) { - _msgpack_rmem_chunk_free(pm, c); - } - return true; - } - } - return false; -} - - -#endif - diff --git a/ext/msgpack/sysdep.h b/ext/msgpack/sysdep.h deleted file mode 100644 index fc1c6bc8..00000000 --- a/ext/msgpack/sysdep.h +++ /dev/null @@ -1,118 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_SYSDEP_H__ -#define MSGPACK_RUBY_SYSDEP_H__ - -#include "sysdep_types.h" -#include "sysdep_endian.h" - - -#define UNUSED(var) ((void)var) - - -#ifdef __LITTLE_ENDIAN__ - -/* _msgpack_be16 */ -#ifdef _WIN32 -# if defined(ntohs) -# define _msgpack_be16(x) ntohs(x) -# elif defined(_byteswap_ushort) || (defined(_MSC_VER) && _MSC_VER >= 1400) -# define _msgpack_be16(x) ((uint16_t)_byteswap_ushort((unsigned short)x)) -# else -# define _msgpack_be16(x) ( \ - ( \ - ((((uint16_t)x) << 8) ) | \ - ((((uint16_t)x) >> 8) ) \ - ) \ - & 0x0000FFFF ) -# endif -#else -# define _msgpack_be16(x) ntohs(x) -#endif - -/* _msgpack_be32 */ -#ifdef _WIN32 -# if defined(ntohl) -# define _msgpack_be32(x) ntohl(x) -# elif defined(_byteswap_ulong) || (defined(_MSC_VER) && _MSC_VER >= 1400) -# define _msgpack_be32(x) ((uint32_t)_byteswap_ulong((unsigned long)x)) -# else -# define _msgpack_be32(x) \ - ( ((((uint32_t)x) << 24) ) | \ - ((((uint32_t)x) << 8) & 0x00ff0000U ) | \ - ((((uint32_t)x) >> 8) & 0x0000ff00U ) | \ - ((((uint32_t)x) >> 24) ) ) -# endif -#else -# define _msgpack_be32(x) ntohl(x) -#endif - -/* _msgpack_be64 */ -#if defined(_byteswap_uint64) || (defined(_MSC_VER) && _MSC_VER >= 1400) -# define _msgpack_be64(x) (_byteswap_uint64(x)) -#elif defined(bswap_64) -# define _msgpack_be64(x) bswap_64(x) -#elif defined(__DARWIN_OSSwapInt64) -# define _msgpack_be64(x) __DARWIN_OSSwapInt64(x) -#else -#define _msgpack_be64(x) \ - ( ((((uint64_t)x) << 56) ) | \ - ((((uint64_t)x) << 40) & 0x00ff000000000000ULL ) | \ - ((((uint64_t)x) << 24) & 0x0000ff0000000000ULL ) | \ - ((((uint64_t)x) << 8) & 0x000000ff00000000ULL ) | \ - ((((uint64_t)x) >> 8) & 0x00000000ff000000ULL ) | \ - ((((uint64_t)x) >> 24) & 0x0000000000ff0000ULL ) | \ - ((((uint64_t)x) >> 40) & 0x000000000000ff00ULL ) | \ - ((((uint64_t)x) >> 56) ) ) -#endif - -#else /* big endian */ -#define _msgpack_be16(x) (x) -#define _msgpack_be32(x) (x) -#define _msgpack_be64(x) (x) - -#endif - - -/* _msgpack_be_float */ -#define _msgpack_be_float(x) _msgpack_be32(x) - -/* _msgpack_be_double */ -#if defined(__arm__) && !(__ARM_EABI__) -/* ARM OABI */ -#define _msgpack_be_double(x) \ - ( (((x) & 0xFFFFFFFFUL) << 32UL) | ((x) >> 32UL) ) -#else -/* the other ABI */ -#define _msgpack_be_double(x) _msgpack_be64(x) -#endif - -/* _msgpack_bsp32 */ -#if defined(_MSC_VER) -#define _msgpack_bsp32(name, val) \ - long name; \ - _BitScanForward(&name, val) -#else -#define _msgpack_bsp32(name, val) \ - int name = __builtin_ctz(val) -/* TODO default impl for _msgpack_bsp32 */ -#endif - - -#endif - diff --git a/ext/msgpack/sysdep_endian.h b/ext/msgpack/sysdep_endian.h deleted file mode 100644 index c280f959..00000000 --- a/ext/msgpack/sysdep_endian.h +++ /dev/null @@ -1,50 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_SYSDEP_ENDIAN_H__ -#define MSGPACK_RUBY_SYSDEP_ENDIAN_H__ - -/* including arpa/inet.h requires an extra dll on win32 */ -#ifndef _WIN32 -#include <arpa/inet.h> /* __BYTE_ORDER */ -#endif - -/* - * Use following command to add consitions here: - * cpp -dM `echo "#include <arpa/inet.h>" > test.c; echo test.c` | grep ENDIAN - */ -#if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__) /* Mac OS X */ -# if defined(_LITTLE_ENDIAN) \ - || ( defined(__BYTE_ORDER) && defined(__LITTLE_ENDIAN) \ - && __BYTE_ORDER == __LITTLE_ENDIAN ) /* Linux */ \ - || ( defined(__BYTE_ORDER__) && defined(__ORDER_LITTLE_ENDIAN__) \ - && __BYTE_ORDER__ == __ORDER_LITTLE_ENDIAN__ ) /* Solaris */ -# define __LITTLE_ENDIAN__ -# elif defined(_BIG_ENDIAN) \ - || (defined(__BYTE_ORDER) && defined(__BIG_ENDIAN) \ - && __BYTE_ORDER == __BIG_ENDIAN) /* Linux */ \ - || (defined(__BYTE_ORDER__) && defined(__ORDER_BIG_ENDIAN__) \ - && __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__) /* Solaris */ -# define __BIG_ENDIAN__ -# elif defined(_WIN32) /* Win32 */ -# define __LITTLE_ENDIAN__ -# endif -#endif - - -#endif - diff --git a/ext/msgpack/sysdep_types.h b/ext/msgpack/sysdep_types.h deleted file mode 100644 index 1601e27a..00000000 --- a/ext/msgpack/sysdep_types.h +++ /dev/null @@ -1,46 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_SYSDEP_TYPES_H__ -#define MSGPACK_RUBY_SYSDEP_TYPES_H__ - -#include <string.h> -#include <stdlib.h> - -#include <stddef.h> - -#if defined(_MSC_VER) && _MSC_VER < 1600 -typedef __int8 int8_t; -typedef unsigned __int8 uint8_t; -typedef __int16 int16_t; -typedef unsigned __int16 uint16_t; -typedef __int32 int32_t; -typedef unsigned __int32 uint32_t; -typedef __int64 int64_t; -typedef unsigned __int64 uint64_t; - -#elif defined(_MSC_VER) // && _MSC_VER >= 1600 -#include <stdint.h> - -#else -#include <stdint.h> -#include <stdbool.h> -#endif - - -#endif - diff --git a/ext/msgpack/unpacker.c b/ext/msgpack/unpacker.c deleted file mode 100644 index b31f60a3..00000000 --- a/ext/msgpack/unpacker.c +++ /dev/null @@ -1,985 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "unpacker.h" -#include "rmem.h" -#include "extension_value_class.h" -#include <assert.h> -#include <limits.h> - -#if !defined(HAVE_RB_PROC_CALL_WITH_BLOCK) -#define rb_proc_call_with_block(recv, argc, argv, block) rb_funcallv(recv, rb_intern("call"), argc, argv) -#endif - -#ifndef HAVE_RB_GC_MARK_LOCATIONS -// For TruffleRuby -void rb_gc_mark_locations(const VALUE *start, const VALUE *end) -{ - VALUE *value = start; - - while (value < end) { - rb_gc_mark(*value); - value++; - } -} -#endif - -struct protected_proc_call_args { - VALUE proc; - int argc; - VALUE *argv; -}; - -static VALUE protected_proc_call_safe(VALUE _args) { - struct protected_proc_call_args *args = (struct protected_proc_call_args *)_args; - - return rb_proc_call_with_block(args->proc, args->argc, args->argv, Qnil); -} - -static VALUE protected_proc_call(VALUE proc, int argc, VALUE *argv, int *raised) { - struct protected_proc_call_args args = { - .proc = proc, - .argc = argc, - .argv = argv, - }; - return rb_protect(protected_proc_call_safe, (VALUE)&args, raised); -} - -static int RAW_TYPE_STRING = 256; -static int RAW_TYPE_BINARY = 257; -static int16_t INITIAL_BUFFER_CAPACITY_MAX = SHRT_MAX; - -static msgpack_rmem_t s_stack_rmem; - -#if !defined(HAVE_RB_HASH_NEW_CAPA) -static inline VALUE rb_hash_new_capa(long capa) -{ - return rb_hash_new(); -} -#endif - -static inline int16_t initial_buffer_size(long size) -{ - return (size > INITIAL_BUFFER_CAPACITY_MAX) ? INITIAL_BUFFER_CAPACITY_MAX : size; -} - -void msgpack_unpacker_static_init(void) -{ - assert(sizeof(msgpack_unpacker_stack_entry_t) * MSGPACK_UNPACKER_STACK_CAPACITY <= MSGPACK_RMEM_PAGE_SIZE); - - msgpack_rmem_init(&s_stack_rmem); -} - -void msgpack_unpacker_static_destroy(void) -{ - msgpack_rmem_destroy(&s_stack_rmem); -} - -#define HEAD_BYTE_REQUIRED 0xc1 - -static inline bool _msgpack_unpacker_stack_init(msgpack_unpacker_stack_t *stack) { - if (!stack->data) { - stack->capacity = MSGPACK_UNPACKER_STACK_CAPACITY; - stack->data = msgpack_rmem_alloc(&s_stack_rmem); - stack->depth = 0; - return true; - } - return false; -} - -static inline void _msgpack_unpacker_free_stack(msgpack_unpacker_stack_t* stack) { - if (stack->data) { - if (!msgpack_rmem_free(&s_stack_rmem, stack->data)) { - rb_bug("Failed to free an rmem pointer, memory leak?"); - } - stack->data = NULL; - stack->depth = 0; - } -} - -#define STACK_INIT(uk) bool stack_allocated = _msgpack_unpacker_stack_init(&uk->stack); -#define STACK_FREE(uk) if (stack_allocated) { _msgpack_unpacker_free_stack(&uk->stack); } - -void _msgpack_unpacker_init(msgpack_unpacker_t* uk) -{ - msgpack_buffer_init(UNPACKER_BUFFER_(uk)); - - uk->head_byte = HEAD_BYTE_REQUIRED; - - uk->last_object = Qnil; - uk->reading_raw = Qnil; -} - -void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk) -{ - _msgpack_unpacker_free_stack(&uk->stack); - msgpack_buffer_destroy(UNPACKER_BUFFER_(uk)); -} - -void msgpack_unpacker_mark_stack(msgpack_unpacker_stack_t* stack) -{ - if (stack->data) { - msgpack_unpacker_stack_entry_t* s = stack->data; - msgpack_unpacker_stack_entry_t* send = stack->data + stack->depth; - for(; s < send; s++) { - rb_gc_mark(s->object); - rb_gc_mark(s->key); - } - } -} - -void msgpack_unpacker_mark_key_cache(msgpack_key_cache_t *cache) -{ - const VALUE *entries = &cache->entries[0]; - rb_gc_mark_locations(entries, entries + cache->length); -} - -void msgpack_unpacker_mark(msgpack_unpacker_t* uk) -{ - rb_gc_mark(uk->last_object); - rb_gc_mark(uk->reading_raw); - msgpack_unpacker_mark_stack(&uk->stack); - msgpack_unpacker_mark_key_cache(&uk->key_cache); - /* See MessagePack_Buffer_wrap */ - /* msgpack_buffer_mark(UNPACKER_BUFFER_(uk)); */ - rb_gc_mark(uk->buffer_ref); - rb_gc_mark(uk->self); -} - -void _msgpack_unpacker_reset(msgpack_unpacker_t* uk) -{ - msgpack_buffer_clear(UNPACKER_BUFFER_(uk)); - - uk->head_byte = HEAD_BYTE_REQUIRED; - - /*memset(uk->stack, 0, sizeof(msgpack_unpacker_t) * uk->stack.depth);*/ - uk->stack.depth = 0; - uk->last_object = Qnil; - uk->reading_raw = Qnil; - uk->reading_raw_remaining = 0; -} - - -/* head byte functions */ -static int read_head_byte(msgpack_unpacker_t* uk) -{ - int r = msgpack_buffer_read_1(UNPACKER_BUFFER_(uk)); - if(r == -1) { - return PRIMITIVE_EOF; - } - return uk->head_byte = r; -} - -static inline int get_head_byte(msgpack_unpacker_t* uk) -{ - int b = uk->head_byte; - if(b == HEAD_BYTE_REQUIRED) { - b = read_head_byte(uk); - } - return b; -} - -static inline void reset_head_byte(msgpack_unpacker_t* uk) -{ - uk->head_byte = HEAD_BYTE_REQUIRED; -} - -static inline int object_complete(msgpack_unpacker_t* uk, VALUE object) -{ - if(uk->freeze) { - rb_obj_freeze(object); - } - - uk->last_object = object; - reset_head_byte(uk); - return PRIMITIVE_OBJECT_COMPLETE; -} - -static inline int object_complete_symbol(msgpack_unpacker_t* uk, VALUE object) -{ - uk->last_object = object; - reset_head_byte(uk); - return PRIMITIVE_OBJECT_COMPLETE; -} - -static inline int object_complete_ext(msgpack_unpacker_t* uk, int ext_type, VALUE str) -{ - if (uk->optimized_symbol_ext_type && ext_type == uk->symbol_ext_type) { - if (RB_UNLIKELY(NIL_P(str))) { // empty extension is returned as Qnil - return object_complete_symbol(uk, ID2SYM(rb_intern3("", 0, rb_utf8_encoding()))); - } - return object_complete_symbol(uk, rb_str_intern(str)); - } - - int ext_flags; - VALUE proc = msgpack_unpacker_ext_registry_lookup(uk->ext_registry, ext_type, &ext_flags); - - if(proc != Qnil) { - VALUE obj; - VALUE arg = (str == Qnil ? rb_str_buf_new(0) : str); - int raised; - obj = protected_proc_call(proc, 1, &arg, &raised); - if (raised) { - uk->last_object = rb_errinfo(); - return PRIMITIVE_RECURSIVE_RAISED; - } - return object_complete(uk, obj); - } - - if(uk->allow_unknown_ext) { - VALUE obj = MessagePack_ExtensionValue_new(ext_type, str == Qnil ? rb_str_buf_new(0) : str); - return object_complete(uk, obj); - } - - return PRIMITIVE_UNEXPECTED_EXT_TYPE; -} - -/* stack funcs */ -static inline msgpack_unpacker_stack_entry_t* _msgpack_unpacker_stack_entry_top(msgpack_unpacker_t* uk) -{ - return &uk->stack.data[uk->stack.depth-1]; -} - -static inline int _msgpack_unpacker_stack_push(msgpack_unpacker_t* uk, enum stack_type_t type, size_t count, VALUE object) -{ - reset_head_byte(uk); - - if(uk->stack.capacity - uk->stack.depth <= 0) { - return PRIMITIVE_STACK_TOO_DEEP; - } - - msgpack_unpacker_stack_entry_t* next = &uk->stack.data[uk->stack.depth]; - next->count = count; - next->type = type; - next->object = object; - next->key = Qnil; - - uk->stack.depth++; - return PRIMITIVE_CONTAINER_START; -} - -static inline size_t msgpack_unpacker_stack_pop(msgpack_unpacker_t* uk) -{ - return --uk->stack.depth; -} - -static inline bool msgpack_unpacker_stack_is_empty(msgpack_unpacker_t* uk) -{ - return uk->stack.depth == 0; -} - -#ifdef USE_CASE_RANGE - -#define SWITCH_RANGE_BEGIN(BYTE) { switch(BYTE) { -#define SWITCH_RANGE(BYTE, FROM, TO) } case FROM ... TO: { -#define SWITCH_RANGE_DEFAULT } default: { -#define SWITCH_RANGE_END } } - -#else - -#define SWITCH_RANGE_BEGIN(BYTE) { if(0) { -#define SWITCH_RANGE(BYTE, FROM, TO) } else if(FROM <= (BYTE) && (BYTE) <= TO) { -#define SWITCH_RANGE_DEFAULT } else { -#define SWITCH_RANGE_END } } - -#endif - -union msgpack_buffer_cast_block_t { - char buffer[8]; - uint8_t u8; - uint16_t u16; - uint32_t u32; - uint64_t u64; - int8_t i8; - int16_t i16; - int32_t i32; - int64_t i64; - float f; - double d; -}; - -#define READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, n) \ - union msgpack_buffer_cast_block_t cb; \ - if (!msgpack_buffer_read_all(UNPACKER_BUFFER_(uk), (char *)&cb.buffer, n)) { \ - return PRIMITIVE_EOF; \ - } - -static inline bool is_reading_map_key(msgpack_unpacker_t* uk) -{ - if(uk->stack.depth > 0) { - msgpack_unpacker_stack_entry_t* top = _msgpack_unpacker_stack_entry_top(uk); - if(top->type == STACK_TYPE_MAP_KEY) { - return true; - } - } - return false; -} - -static int read_raw_body_cont(msgpack_unpacker_t* uk) -{ - size_t length = uk->reading_raw_remaining; - - if(uk->reading_raw == Qnil) { - uk->reading_raw = rb_str_buf_new(length); - } - - do { - size_t n = msgpack_buffer_read_to_string(UNPACKER_BUFFER_(uk), uk->reading_raw, length); - if(n == 0) { - return PRIMITIVE_EOF; - } - /* update reading_raw_remaining everytime because - * msgpack_buffer_read_to_string raises IOError */ - uk->reading_raw_remaining = length = length - n; - } while(length > 0); - - int ret; - if(uk->reading_raw_type == RAW_TYPE_STRING) { - ENCODING_SET(uk->reading_raw, msgpack_rb_encindex_utf8); - ret = object_complete(uk, uk->reading_raw); - } else if (uk->reading_raw_type == RAW_TYPE_BINARY) { - ret = object_complete(uk, uk->reading_raw); - } else { - ret = object_complete_ext(uk, uk->reading_raw_type, uk->reading_raw); - } - uk->reading_raw = Qnil; - return ret; -} - -static inline int read_raw_body_begin(msgpack_unpacker_t* uk, int raw_type) -{ - /* assuming uk->reading_raw == Qnil */ - - int ext_flags; - VALUE proc; - - if(!(raw_type == RAW_TYPE_STRING || raw_type == RAW_TYPE_BINARY)) { - proc = msgpack_unpacker_ext_registry_lookup(uk->ext_registry, raw_type, &ext_flags); - if(proc != Qnil && ext_flags & MSGPACK_EXT_RECURSIVE) { - VALUE obj; - uk->last_object = Qnil; - reset_head_byte(uk); - uk->reading_raw_remaining = 0; - - _msgpack_unpacker_stack_push(uk, STACK_TYPE_RECURSIVE, 1, Qnil); - int raised; - obj = protected_proc_call(proc, 1, &uk->self, &raised); - msgpack_unpacker_stack_pop(uk); - - if (raised) { - uk->last_object = rb_errinfo(); - return PRIMITIVE_RECURSIVE_RAISED; - } - - return object_complete(uk, obj); - } - } - - /* try optimized read */ - size_t length = uk->reading_raw_remaining; - if(length <= msgpack_buffer_top_readable_size(UNPACKER_BUFFER_(uk))) { - int ret; - if ((uk->optimized_symbol_ext_type && uk->symbol_ext_type == raw_type)) { - VALUE symbol = msgpack_buffer_read_top_as_symbol(UNPACKER_BUFFER_(uk), length, raw_type != RAW_TYPE_BINARY); - ret = object_complete_symbol(uk, symbol); - } else if (is_reading_map_key(uk) && raw_type == RAW_TYPE_STRING) { - /* don't use zerocopy for hash keys but get a frozen string directly - * because rb_hash_aset freezes keys and it causes copying */ - VALUE key; - if (uk->symbolize_keys) { - if (uk->use_key_cache) { - key = msgpack_buffer_read_top_as_interned_symbol(UNPACKER_BUFFER_(uk), &uk->key_cache, length); - } else { - key = msgpack_buffer_read_top_as_symbol(UNPACKER_BUFFER_(uk), length, true); - } - ret = object_complete_symbol(uk, key); - } else { - if (uk->use_key_cache) { - key = msgpack_buffer_read_top_as_interned_string(UNPACKER_BUFFER_(uk), &uk->key_cache, length); - } else { - key = msgpack_buffer_read_top_as_string(UNPACKER_BUFFER_(uk), length, true, true); - } - - ret = object_complete(uk, key); - } - } else { - bool will_freeze = uk->freeze; - if(raw_type == RAW_TYPE_STRING || raw_type == RAW_TYPE_BINARY) { - VALUE string = msgpack_buffer_read_top_as_string(UNPACKER_BUFFER_(uk), length, will_freeze, raw_type == RAW_TYPE_STRING); - ret = object_complete(uk, string); - } else { - VALUE string = msgpack_buffer_read_top_as_string(UNPACKER_BUFFER_(uk), length, false, false); - ret = object_complete_ext(uk, raw_type, string); - } - } - uk->reading_raw_remaining = 0; - return ret; - } - - uk->reading_raw_type = raw_type; - return read_raw_body_cont(uk); -} - -static int read_primitive(msgpack_unpacker_t* uk) -{ - if(uk->reading_raw_remaining > 0) { - return read_raw_body_cont(uk); - } - - int b = get_head_byte(uk); - if(b < 0) { - return b; - } - - SWITCH_RANGE_BEGIN(b) - SWITCH_RANGE(b, 0x00, 0x7f) // Positive Fixnum - return object_complete(uk, INT2NUM(b)); - - SWITCH_RANGE(b, 0xe0, 0xff) // Negative Fixnum - return object_complete(uk, INT2NUM((int8_t)b)); - - SWITCH_RANGE(b, 0xa0, 0xbf) // FixRaw / fixstr - int count = b & 0x1f; - /* read_raw_body_begin sets uk->reading_raw */ - uk->reading_raw_remaining = count; - return read_raw_body_begin(uk, RAW_TYPE_STRING); - - SWITCH_RANGE(b, 0x90, 0x9f) // FixArray - int count = b & 0x0f; - if(count == 0) { - return object_complete(uk, rb_ary_new()); - } - return _msgpack_unpacker_stack_push(uk, STACK_TYPE_ARRAY, count, rb_ary_new2(initial_buffer_size(count))); - - SWITCH_RANGE(b, 0x80, 0x8f) // FixMap - int count = b & 0x0f; - if(count == 0) { - return object_complete(uk, rb_hash_new()); - } - return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(initial_buffer_size(count))); - - SWITCH_RANGE(b, 0xc0, 0xdf) // Variable - switch(b) { - case 0xc0: // nil - return object_complete(uk, Qnil); - - //case 0xc1: // string - - case 0xc2: // false - return object_complete(uk, Qfalse); - - case 0xc3: // true - return object_complete(uk, Qtrue); - - case 0xc7: // ext 8 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - uint8_t length = cb.u8; - int ext_type = (signed char) cb.buffer[1]; - if(length == 0) { - return object_complete_ext(uk, ext_type, Qnil); - } - uk->reading_raw_remaining = length; - return read_raw_body_begin(uk, ext_type); - } - - case 0xc8: // ext 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 3); - uint16_t length = _msgpack_be16(cb.u16); - int ext_type = (signed char) cb.buffer[2]; - if(length == 0) { - return object_complete_ext(uk, ext_type, Qnil); - } - uk->reading_raw_remaining = length; - return read_raw_body_begin(uk, ext_type); - } - - case 0xc9: // ext 32 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 5); - uint32_t length = _msgpack_be32(cb.u32); - int ext_type = (signed char) cb.buffer[4]; - if(length == 0) { - return object_complete_ext(uk, ext_type, Qnil); - } - uk->reading_raw_remaining = length; - return read_raw_body_begin(uk, ext_type); - } - - case 0xca: // float - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - cb.u32 = _msgpack_be_float(cb.u32); - return object_complete(uk, rb_float_new(cb.f)); - } - - case 0xcb: // double - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 8); - cb.u64 = _msgpack_be_double(cb.u64); - return object_complete(uk, rb_float_new(cb.d)); - } - - case 0xcc: // unsigned int 8 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - uint8_t u8 = cb.u8; - return object_complete(uk, INT2NUM((int)u8)); - } - - case 0xcd: // unsigned int 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - uint16_t u16 = _msgpack_be16(cb.u16); - return object_complete(uk, INT2NUM((int)u16)); - } - - case 0xce: // unsigned int 32 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - uint32_t u32 = _msgpack_be32(cb.u32); - return object_complete(uk, ULONG2NUM(u32)); // long at least 32 bits - } - - case 0xcf: // unsigned int 64 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 8); - uint64_t u64 = _msgpack_be64(cb.u64); - return object_complete(uk, rb_ull2inum(u64)); - } - - case 0xd0: // signed int 8 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - int8_t i8 = cb.i8; - return object_complete(uk, INT2NUM((int)i8)); - } - - case 0xd1: // signed int 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - int16_t i16 = _msgpack_be16(cb.i16); - return object_complete(uk, INT2NUM((int)i16)); - } - - case 0xd2: // signed int 32 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - int32_t i32 = _msgpack_be32(cb.i32); - return object_complete(uk, LONG2NUM(i32)); // long at least 32 bits - } - - case 0xd3: // signed int 64 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 8); - int64_t i64 = _msgpack_be64(cb.i64); - return object_complete(uk, rb_ll2inum(i64)); - } - - case 0xd4: // fixext 1 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - int ext_type = cb.i8; - uk->reading_raw_remaining = 1; - return read_raw_body_begin(uk, ext_type); - } - - case 0xd5: // fixext 2 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - int ext_type = cb.i8; - uk->reading_raw_remaining = 2; - return read_raw_body_begin(uk, ext_type); - } - - case 0xd6: // fixext 4 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - int ext_type = cb.i8; - uk->reading_raw_remaining = 4; - return read_raw_body_begin(uk, ext_type); - } - - case 0xd7: // fixext 8 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - int ext_type = cb.i8; - uk->reading_raw_remaining = 8; - return read_raw_body_begin(uk, ext_type); - } - - case 0xd8: // fixext 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - int ext_type = cb.i8; - uk->reading_raw_remaining = 16; - return read_raw_body_begin(uk, ext_type); - } - - - case 0xd9: // raw 8 / str 8 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - uint8_t count = cb.u8; - /* read_raw_body_begin sets uk->reading_raw */ - uk->reading_raw_remaining = count; - return read_raw_body_begin(uk, RAW_TYPE_STRING); - } - - case 0xda: // raw 16 / str 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - uint16_t count = _msgpack_be16(cb.u16); - /* read_raw_body_begin sets uk->reading_raw */ - uk->reading_raw_remaining = count; - return read_raw_body_begin(uk, RAW_TYPE_STRING); - } - - case 0xdb: // raw 32 / str 32 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - uint32_t count = _msgpack_be32(cb.u32); - /* read_raw_body_begin sets uk->reading_raw */ - uk->reading_raw_remaining = count; - return read_raw_body_begin(uk, RAW_TYPE_STRING); - } - - case 0xc4: // bin 8 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 1); - uint8_t count = cb.u8; - /* read_raw_body_begin sets uk->reading_raw */ - uk->reading_raw_remaining = count; - return read_raw_body_begin(uk, RAW_TYPE_BINARY); - } - - case 0xc5: // bin 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - uint16_t count = _msgpack_be16(cb.u16); - /* read_raw_body_begin sets uk->reading_raw */ - uk->reading_raw_remaining = count; - return read_raw_body_begin(uk, RAW_TYPE_BINARY); - } - - case 0xc6: // bin 32 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - uint32_t count = _msgpack_be32(cb.u32); - /* read_raw_body_begin sets uk->reading_raw */ - uk->reading_raw_remaining = count; - return read_raw_body_begin(uk, RAW_TYPE_BINARY); - } - - case 0xdc: // array 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - uint16_t count = _msgpack_be16(cb.u16); - if(count == 0) { - return object_complete(uk, rb_ary_new()); - } - return _msgpack_unpacker_stack_push(uk, STACK_TYPE_ARRAY, count, rb_ary_new2(initial_buffer_size(count))); - } - - case 0xdd: // array 32 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - uint32_t count = _msgpack_be32(cb.u32); - if(count == 0) { - return object_complete(uk, rb_ary_new()); - } - return _msgpack_unpacker_stack_push(uk, STACK_TYPE_ARRAY, count, rb_ary_new2(initial_buffer_size(count))); - } - - case 0xde: // map 16 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - uint16_t count = _msgpack_be16(cb.u16); - if(count == 0) { - return object_complete(uk, rb_hash_new()); - } - return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(initial_buffer_size(count))); - } - - case 0xdf: // map 32 - { - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - uint32_t count = _msgpack_be32(cb.u32); - if(count == 0) { - return object_complete(uk, rb_hash_new()); - } - return _msgpack_unpacker_stack_push(uk, STACK_TYPE_MAP_KEY, count*2, rb_hash_new_capa(initial_buffer_size(count))); - } - - default: - return PRIMITIVE_INVALID_BYTE; - } - - SWITCH_RANGE_DEFAULT - return PRIMITIVE_INVALID_BYTE; - - SWITCH_RANGE_END -} - -int msgpack_unpacker_read_array_header(msgpack_unpacker_t* uk, uint32_t* result_size) -{ - int b = get_head_byte(uk); - if(b < 0) { - return b; - } - - if(0x90 <= b && b <= 0x9f) { - *result_size = b & 0x0f; - - } else if(b == 0xdc) { - /* array 16 */ - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - *result_size = _msgpack_be16(cb.u16); - - } else if(b == 0xdd) { - /* array 32 */ - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - *result_size = _msgpack_be32(cb.u32); - - } else { - return PRIMITIVE_UNEXPECTED_TYPE; - } - - reset_head_byte(uk); - return 0; -} - -int msgpack_unpacker_read_map_header(msgpack_unpacker_t* uk, uint32_t* result_size) -{ - int b = get_head_byte(uk); - if(b < 0) { - return b; - } - - if(0x80 <= b && b <= 0x8f) { - *result_size = b & 0x0f; - - } else if(b == 0xde) { - /* map 16 */ - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 2); - *result_size = _msgpack_be16(cb.u16); - - } else if(b == 0xdf) { - /* map 32 */ - READ_CAST_BLOCK_OR_RETURN_EOF(cb, uk, 4); - *result_size = _msgpack_be32(cb.u32); - - } else { - return PRIMITIVE_UNEXPECTED_TYPE; - } - - reset_head_byte(uk); - return 0; -} - -int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth) -{ - STACK_INIT(uk); - - while(true) { - int r = read_primitive(uk); - if(r < 0) { - if (r != PRIMITIVE_EOF) { - // We keep the stack on EOF as the parsing may be resumed. - STACK_FREE(uk); - } - return r; - } - if(r == PRIMITIVE_CONTAINER_START) { - continue; - } - /* PRIMITIVE_OBJECT_COMPLETE */ - - if(msgpack_unpacker_stack_is_empty(uk)) { - STACK_FREE(uk); - return PRIMITIVE_OBJECT_COMPLETE; - } - - container_completed: - { - msgpack_unpacker_stack_entry_t* top = _msgpack_unpacker_stack_entry_top(uk); - switch(top->type) { - case STACK_TYPE_ARRAY: - rb_ary_push(top->object, uk->last_object); - break; - case STACK_TYPE_MAP_KEY: - top->key = uk->last_object; - top->type = STACK_TYPE_MAP_VALUE; - break; - case STACK_TYPE_MAP_VALUE: - if(uk->symbolize_keys && rb_type(top->key) == T_STRING) { - /* here uses rb_str_intern instead of rb_intern so that Ruby VM can GC unused symbols */ - rb_hash_aset(top->object, rb_str_intern(top->key), uk->last_object); - } else { - rb_hash_aset(top->object, top->key, uk->last_object); - } - top->type = STACK_TYPE_MAP_KEY; - break; - case STACK_TYPE_RECURSIVE: - STACK_FREE(uk); - return PRIMITIVE_OBJECT_COMPLETE; - } - size_t count = --top->count; - - if(count == 0) { - object_complete(uk, top->object); - if(msgpack_unpacker_stack_pop(uk) <= target_stack_depth) { - STACK_FREE(uk); - return PRIMITIVE_OBJECT_COMPLETE; - } - goto container_completed; - } - } - } -} - -int msgpack_unpacker_skip(msgpack_unpacker_t* uk, size_t target_stack_depth) -{ - STACK_INIT(uk); - - while(true) { - int r = read_primitive(uk); - if(r < 0) { - STACK_FREE(uk); - return r; - } - if(r == PRIMITIVE_CONTAINER_START) { - continue; - } - /* PRIMITIVE_OBJECT_COMPLETE */ - - if(msgpack_unpacker_stack_is_empty(uk)) { - STACK_FREE(uk); - return PRIMITIVE_OBJECT_COMPLETE; - } - - container_completed: - { - msgpack_unpacker_stack_entry_t* top = _msgpack_unpacker_stack_entry_top(uk); - - /* this section optimized out */ - // TODO object_complete still creates objects which should be optimized out - - size_t count = --top->count; - - if(count == 0) { - object_complete(uk, Qnil); - if(msgpack_unpacker_stack_pop(uk) <= target_stack_depth) { - STACK_FREE(uk); - return PRIMITIVE_OBJECT_COMPLETE; - } - goto container_completed; - } - } - } -} - -int msgpack_unpacker_peek_next_object_type(msgpack_unpacker_t* uk) -{ - int b = get_head_byte(uk); - if(b < 0) { - return b; - } - - SWITCH_RANGE_BEGIN(b) - SWITCH_RANGE(b, 0x00, 0x7f) // Positive Fixnum - return TYPE_INTEGER; - - SWITCH_RANGE(b, 0xe0, 0xff) // Negative Fixnum - return TYPE_INTEGER; - - SWITCH_RANGE(b, 0xa0, 0xbf) // FixRaw - return TYPE_RAW; - - SWITCH_RANGE(b, 0x90, 0x9f) // FixArray - return TYPE_ARRAY; - - SWITCH_RANGE(b, 0x80, 0x8f) // FixMap - return TYPE_MAP; - - SWITCH_RANGE(b, 0xc0, 0xdf) // Variable - switch(b) { - case 0xc0: // nil - return TYPE_NIL; - - case 0xc2: // false - case 0xc3: // true - return TYPE_BOOLEAN; - - case 0xca: // float - case 0xcb: // double - return TYPE_FLOAT; - - case 0xcc: // unsigned int 8 - case 0xcd: // unsigned int 16 - case 0xce: // unsigned int 32 - case 0xcf: // unsigned int 64 - return TYPE_INTEGER; - - case 0xd0: // signed int 8 - case 0xd1: // signed int 16 - case 0xd2: // signed int 32 - case 0xd3: // signed int 64 - return TYPE_INTEGER; - - case 0xd9: // raw 8 / str 8 - case 0xda: // raw 16 / str 16 - case 0xdb: // raw 32 / str 32 - return TYPE_RAW; - - case 0xc4: // bin 8 - case 0xc5: // bin 16 - case 0xc6: // bin 32 - return TYPE_RAW; - - case 0xdc: // array 16 - case 0xdd: // array 32 - return TYPE_ARRAY; - - case 0xde: // map 16 - case 0xdf: // map 32 - return TYPE_MAP; - - default: - return PRIMITIVE_INVALID_BYTE; - } - - SWITCH_RANGE_DEFAULT - return PRIMITIVE_INVALID_BYTE; - - SWITCH_RANGE_END -} - -int msgpack_unpacker_skip_nil(msgpack_unpacker_t* uk) -{ - int b = get_head_byte(uk); - if(b < 0) { - return b; - } - if(b == 0xc0) { - return 1; - } - return 0; -} - diff --git a/ext/msgpack/unpacker.h b/ext/msgpack/unpacker.h deleted file mode 100644 index 10e13268..00000000 --- a/ext/msgpack/unpacker.h +++ /dev/null @@ -1,152 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_UNPACKER_H__ -#define MSGPACK_RUBY_UNPACKER_H__ - -#include "buffer.h" -#include "unpacker_ext_registry.h" - -#define MSGPACK_UNPACKER_STACK_CAPACITY 128 - -struct msgpack_unpacker_t; -typedef struct msgpack_unpacker_t msgpack_unpacker_t; -typedef struct msgpack_unpacker_stack_t msgpack_unpacker_stack_t; - -enum stack_type_t { - STACK_TYPE_ARRAY, - STACK_TYPE_MAP_KEY, - STACK_TYPE_MAP_VALUE, - STACK_TYPE_RECURSIVE, -}; - -typedef struct { - size_t count; - enum stack_type_t type; - VALUE object; - VALUE key; -} msgpack_unpacker_stack_entry_t; - -struct msgpack_unpacker_stack_t { - size_t depth; - size_t capacity; - msgpack_unpacker_stack_entry_t *data; -}; - -struct msgpack_unpacker_t { - msgpack_buffer_t buffer; - msgpack_unpacker_stack_t stack; - msgpack_key_cache_t key_cache; - - VALUE self; - VALUE last_object; - - VALUE reading_raw; - size_t reading_raw_remaining; - - VALUE buffer_ref; - - msgpack_unpacker_ext_registry_t *ext_registry; - - int reading_raw_type; - unsigned int head_byte; - - /* options */ - int symbol_ext_type; - - bool use_key_cache: 1; - bool symbolize_keys: 1; - bool freeze: 1; - bool allow_unknown_ext: 1; - bool optimized_symbol_ext_type: 1; -}; - -#define UNPACKER_BUFFER_(uk) (&(uk)->buffer) - -enum msgpack_unpacker_object_type { - TYPE_NIL = 0, - TYPE_BOOLEAN, - TYPE_INTEGER, - TYPE_FLOAT, - TYPE_RAW, - TYPE_ARRAY, - TYPE_MAP, -}; - -void msgpack_unpacker_static_init(void); - -void msgpack_unpacker_static_destroy(void); - -void _msgpack_unpacker_init(msgpack_unpacker_t*); - -void _msgpack_unpacker_destroy(msgpack_unpacker_t* uk); - -void msgpack_unpacker_mark(msgpack_unpacker_t* uk); - -void _msgpack_unpacker_reset(msgpack_unpacker_t* uk); - -static inline void msgpack_unpacker_set_symbolized_keys(msgpack_unpacker_t* uk, bool enable) -{ - uk->symbolize_keys = enable; -} - -static inline void msgpack_unpacker_set_key_cache(msgpack_unpacker_t* uk, bool enable) -{ - uk->use_key_cache = enable; -} - -static inline void msgpack_unpacker_set_freeze(msgpack_unpacker_t* uk, bool enable) -{ - uk->freeze = enable; -} - -static inline void msgpack_unpacker_set_allow_unknown_ext(msgpack_unpacker_t* uk, bool enable) -{ - uk->allow_unknown_ext = enable; -} - - -/* error codes */ -#define PRIMITIVE_CONTAINER_START 1 -#define PRIMITIVE_OBJECT_COMPLETE 0 -#define PRIMITIVE_EOF -1 -#define PRIMITIVE_INVALID_BYTE -2 -#define PRIMITIVE_STACK_TOO_DEEP -3 -#define PRIMITIVE_UNEXPECTED_TYPE -4 -#define PRIMITIVE_UNEXPECTED_EXT_TYPE -5 -#define PRIMITIVE_RECURSIVE_RAISED -6 - -int msgpack_unpacker_read(msgpack_unpacker_t* uk, size_t target_stack_depth); - -int msgpack_unpacker_skip(msgpack_unpacker_t* uk, size_t target_stack_depth); - -static inline VALUE msgpack_unpacker_get_last_object(msgpack_unpacker_t* uk) -{ - return uk->last_object; -} - - -int msgpack_unpacker_peek_next_object_type(msgpack_unpacker_t* uk); - -int msgpack_unpacker_skip_nil(msgpack_unpacker_t* uk); - -int msgpack_unpacker_read_array_header(msgpack_unpacker_t* uk, uint32_t* result_size); - -int msgpack_unpacker_read_map_header(msgpack_unpacker_t* uk, uint32_t* result_size); - -#endif - diff --git a/ext/msgpack/unpacker_class.c b/ext/msgpack/unpacker_class.c deleted file mode 100644 index c4f84699..00000000 --- a/ext/msgpack/unpacker_class.c +++ /dev/null @@ -1,447 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "unpacker.h" -#include "unpacker_class.h" -#include "buffer_class.h" -#include "factory_class.h" - -VALUE cMessagePack_Unpacker; - -//static VALUE s_unpacker_value; -//static msgpack_unpacker_t* s_unpacker; - -static VALUE eUnpackError; -static VALUE eMalformedFormatError; -static VALUE eStackError; -static VALUE eUnexpectedTypeError; -static VALUE eUnknownExtTypeError; -static VALUE mTypeError; // obsoleted. only for backward compatibility. See #86. - -static VALUE sym_symbolize_keys; -static VALUE sym_key_cache; -static VALUE sym_freeze; -static VALUE sym_allow_unknown_ext; - -static void Unpacker_free(void *ptr) -{ - msgpack_unpacker_t* uk = ptr; - if(uk == NULL) { - return; - } - msgpack_unpacker_ext_registry_release(uk->ext_registry); - _msgpack_unpacker_destroy(uk); - xfree(uk); -} - -static void Unpacker_mark(void *ptr) -{ - msgpack_unpacker_t* uk = ptr; - msgpack_buffer_mark(uk); - msgpack_unpacker_mark(uk); - msgpack_unpacker_ext_registry_mark(uk->ext_registry); -} - -static size_t Unpacker_memsize(const void *ptr) -{ - const msgpack_unpacker_t* uk = ptr; - - size_t total_size = sizeof(msgpack_unpacker_t); - - if (uk->ext_registry) { - total_size += sizeof(msgpack_unpacker_ext_registry_t) / (uk->ext_registry->borrow_count + 1); - } - - if (uk->stack.data) { - total_size += (uk->stack.depth + 1) * sizeof(msgpack_unpacker_stack_t); - } - - return total_size + msgpack_buffer_memsize(&uk->buffer); -} - -const rb_data_type_t unpacker_data_type = { - .wrap_struct_name = "msgpack:unpacker", - .function = { - .dmark = Unpacker_mark, - .dfree = Unpacker_free, - .dsize = Unpacker_memsize, - }, - .flags = RUBY_TYPED_FREE_IMMEDIATELY -}; - -VALUE MessagePack_Unpacker_alloc(VALUE klass) -{ - msgpack_unpacker_t* uk; - VALUE self = TypedData_Make_Struct(klass, msgpack_unpacker_t, &unpacker_data_type, uk); - _msgpack_unpacker_init(uk); - uk->self = self; - return self; -} - -VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self) -{ - VALUE io = Qnil; - VALUE options = Qnil; - - if(argc == 0 || (argc == 1 && argv[0] == Qnil)) { - /* Qnil */ - - } else if(argc == 1) { - VALUE v = argv[0]; - if(rb_type(v) == T_HASH) { - options = v; - } else { - io = v; - } - - } else if(argc == 2) { - io = argv[0]; - options = argv[1]; - if(options != Qnil && rb_type(options) != T_HASH) { - rb_raise(rb_eArgError, "expected Hash but found %s.", rb_obj_classname(options)); - } - - } else { - rb_raise(rb_eArgError, "wrong number of arguments (%d for 0..2)", argc); - } - - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - uk->buffer_ref = Qnil; - - MessagePack_Buffer_set_options(UNPACKER_BUFFER_(uk), io, options); - - if(options != Qnil) { - VALUE v; - - v = rb_hash_aref(options, sym_key_cache); - msgpack_unpacker_set_key_cache(uk, RTEST(v)); - - v = rb_hash_aref(options, sym_symbolize_keys); - msgpack_unpacker_set_symbolized_keys(uk, RTEST(v)); - - v = rb_hash_aref(options, sym_freeze); - msgpack_unpacker_set_freeze(uk, RTEST(v)); - - v = rb_hash_aref(options, sym_allow_unknown_ext); - msgpack_unpacker_set_allow_unknown_ext(uk, RTEST(v)); - } - - return self; -} - -static VALUE Unpacker_symbolized_keys_p(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - return uk->symbolize_keys ? Qtrue : Qfalse; -} - -static VALUE Unpacker_freeze_p(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - return uk->freeze ? Qtrue : Qfalse; -} - -static VALUE Unpacker_allow_unknown_ext_p(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - return uk->allow_unknown_ext ? Qtrue : Qfalse; -} - -NORETURN(static void raise_unpacker_error(msgpack_unpacker_t *uk, int r)) -{ - uk->stack.depth = 0; - switch(r) { - case PRIMITIVE_EOF: - rb_raise(rb_eEOFError, "end of buffer reached"); - break; - case PRIMITIVE_INVALID_BYTE: - rb_raise(eMalformedFormatError, "invalid byte"); - break; - case PRIMITIVE_STACK_TOO_DEEP: - rb_raise(eStackError, "stack level too deep"); - break; - case PRIMITIVE_UNEXPECTED_TYPE: - rb_raise(eUnexpectedTypeError, "unexpected type"); - break; - case PRIMITIVE_UNEXPECTED_EXT_TYPE: - rb_raise(eUnknownExtTypeError, "unexpected extension type"); - break; - case PRIMITIVE_RECURSIVE_RAISED: - rb_exc_raise(msgpack_unpacker_get_last_object(uk)); - break; - default: - rb_raise(eUnpackError, "logically unknown error %d", r); - } -} - -static VALUE Unpacker_buffer(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - if (!RTEST(uk->buffer_ref)) { - uk->buffer_ref = MessagePack_Buffer_wrap(UNPACKER_BUFFER_(uk), self); - } - return uk->buffer_ref; -} - -static VALUE Unpacker_read(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - int r = msgpack_unpacker_read(uk, 0); - if(r < 0) { - raise_unpacker_error(uk, r); - } - - return msgpack_unpacker_get_last_object(uk); -} - -static VALUE Unpacker_skip(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - int r = msgpack_unpacker_skip(uk, 0); - if(r < 0) { - raise_unpacker_error(uk, r); - } - - return Qnil; -} - -static VALUE Unpacker_skip_nil(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - int r = msgpack_unpacker_skip_nil(uk); - if(r < 0) { - raise_unpacker_error(uk, r); - } - - if(r) { - return Qtrue; - } - return Qfalse; -} - -static VALUE Unpacker_read_array_header(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - uint32_t size; - int r = msgpack_unpacker_read_array_header(uk, &size); - if(r < 0) { - raise_unpacker_error(uk, r); - } - - return ULONG2NUM(size); // long at least 32 bits -} - -static VALUE Unpacker_read_map_header(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - uint32_t size; - int r = msgpack_unpacker_read_map_header(uk, &size); - if(r < 0) { - raise_unpacker_error(uk, r); - } - - return ULONG2NUM(size); // long at least 32 bits -} - -static VALUE Unpacker_feed_reference(VALUE self, VALUE data) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - StringValue(data); - - msgpack_buffer_append_string_reference(UNPACKER_BUFFER_(uk), data); - - return self; -} - -static VALUE Unpacker_each_impl(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - while(true) { - int r = msgpack_unpacker_read(uk, 0); - if(r < 0) { - if(r == PRIMITIVE_EOF) { - return Qnil; - } - raise_unpacker_error(uk, r); - } - VALUE v = msgpack_unpacker_get_last_object(uk); - rb_yield(v); - } -} - -static VALUE Unpacker_rescue_EOFError(VALUE args, VALUE error) -{ - UNUSED(args); - UNUSED(error); - return Qnil; -} - -static VALUE Unpacker_each(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - -#ifdef RETURN_ENUMERATOR - RETURN_ENUMERATOR(self, 0, 0); -#endif - - if(msgpack_buffer_has_io(UNPACKER_BUFFER_(uk))) { - /* rescue EOFError only if io is set */ - return rb_rescue2(Unpacker_each_impl, self, - Unpacker_rescue_EOFError, self, - rb_eEOFError, NULL); - } else { - return Unpacker_each_impl(self); - } -} - -static VALUE Unpacker_feed_each(VALUE self, VALUE data) -{ -#ifdef RETURN_ENUMERATOR - { - VALUE argv[] = { data }; - RETURN_ENUMERATOR(self, sizeof(argv) / sizeof(VALUE), argv); - } -#endif - - Unpacker_feed_reference(self, data); - return Unpacker_each(self); -} - -static VALUE Unpacker_reset(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - _msgpack_unpacker_reset(uk); - - return Qnil; -} - -static VALUE Unpacker_registered_types_internal(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - VALUE mapping = rb_hash_new(); - if (uk->ext_registry) { - for(int i=0; i < 256; i++) { - if(uk->ext_registry->array[i] != Qnil) { - rb_hash_aset(mapping, INT2FIX(i - 128), uk->ext_registry->array[i]); - } - } - } - - return mapping; -} - -static VALUE Unpacker_register_type_internal(VALUE self, VALUE rb_ext_type, VALUE ext_module, VALUE proc) -{ - if (OBJ_FROZEN(self)) { - rb_raise(rb_eFrozenError, "can't modify frozen MessagePack::Unpacker"); - } - - int ext_type = NUM2INT(rb_ext_type); - if(ext_type < -128 || ext_type > 127) { - rb_raise(rb_eRangeError, "integer %d too big to convert to `signed char'", ext_type); - } - - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - msgpack_unpacker_ext_registry_put(self, &uk->ext_registry, ext_module, ext_type, 0, proc); - - return Qnil; -} - -static VALUE Unpacker_full_unpack(VALUE self) -{ - msgpack_unpacker_t *uk = MessagePack_Unpacker_get(self); - - int r = msgpack_unpacker_read(uk, 0); - if(r < 0) { - raise_unpacker_error(uk, r); - } - - /* raise if extra bytes follow */ - size_t extra = msgpack_buffer_top_readable_size(UNPACKER_BUFFER_(uk)); - if(extra > 0) { - rb_raise(eMalformedFormatError, "%zd extra bytes after the deserialized object", extra); - } - - return msgpack_unpacker_get_last_object(uk); -} - -VALUE MessagePack_Unpacker_new(int argc, VALUE* argv) -{ - VALUE self = MessagePack_Unpacker_alloc(cMessagePack_Unpacker); - MessagePack_Unpacker_initialize(argc, argv, self); - return self; -} - -void MessagePack_Unpacker_module_init(VALUE mMessagePack) -{ - msgpack_unpacker_static_init(); - - mTypeError = rb_define_module_under(mMessagePack, "TypeError"); - - cMessagePack_Unpacker = rb_define_class_under(mMessagePack, "Unpacker", rb_cObject); - - eUnpackError = rb_define_class_under(mMessagePack, "UnpackError", rb_eStandardError); - - eMalformedFormatError = rb_define_class_under(mMessagePack, "MalformedFormatError", eUnpackError); - - eStackError = rb_define_class_under(mMessagePack, "StackError", eUnpackError); - - eUnexpectedTypeError = rb_define_class_under(mMessagePack, "UnexpectedTypeError", eUnpackError); - rb_include_module(eUnexpectedTypeError, mTypeError); - - eUnknownExtTypeError = rb_define_class_under(mMessagePack, "UnknownExtTypeError", eUnpackError); - - sym_symbolize_keys = ID2SYM(rb_intern("symbolize_keys")); - sym_key_cache = ID2SYM(rb_intern("key_cache")); - sym_freeze = ID2SYM(rb_intern("freeze")); - sym_allow_unknown_ext = ID2SYM(rb_intern("allow_unknown_ext")); - - rb_define_alloc_func(cMessagePack_Unpacker, MessagePack_Unpacker_alloc); - - rb_define_method(cMessagePack_Unpacker, "initialize", MessagePack_Unpacker_initialize, -1); - rb_define_method(cMessagePack_Unpacker, "symbolize_keys?", Unpacker_symbolized_keys_p, 0); - rb_define_method(cMessagePack_Unpacker, "freeze?", Unpacker_freeze_p, 0); - rb_define_method(cMessagePack_Unpacker, "allow_unknown_ext?", Unpacker_allow_unknown_ext_p, 0); - rb_define_method(cMessagePack_Unpacker, "buffer", Unpacker_buffer, 0); - rb_define_method(cMessagePack_Unpacker, "read", Unpacker_read, 0); - rb_define_alias(cMessagePack_Unpacker, "unpack", "read"); - rb_define_method(cMessagePack_Unpacker, "skip", Unpacker_skip, 0); - rb_define_method(cMessagePack_Unpacker, "skip_nil", Unpacker_skip_nil, 0); - rb_define_method(cMessagePack_Unpacker, "read_array_header", Unpacker_read_array_header, 0); - rb_define_method(cMessagePack_Unpacker, "read_map_header", Unpacker_read_map_header, 0); - rb_define_method(cMessagePack_Unpacker, "feed", Unpacker_feed_reference, 1); - rb_define_alias(cMessagePack_Unpacker, "feed_reference", "feed"); - rb_define_method(cMessagePack_Unpacker, "each", Unpacker_each, 0); - rb_define_method(cMessagePack_Unpacker, "feed_each", Unpacker_feed_each, 1); - rb_define_method(cMessagePack_Unpacker, "reset", Unpacker_reset, 0); - - rb_define_private_method(cMessagePack_Unpacker, "registered_types_internal", Unpacker_registered_types_internal, 0); - rb_define_private_method(cMessagePack_Unpacker, "register_type_internal", Unpacker_register_type_internal, 3); - - rb_define_method(cMessagePack_Unpacker, "full_unpack", Unpacker_full_unpack, 0); -} diff --git a/ext/msgpack/unpacker_class.h b/ext/msgpack/unpacker_class.h deleted file mode 100644 index 7651fa30..00000000 --- a/ext/msgpack/unpacker_class.h +++ /dev/null @@ -1,43 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2013 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_UNPACKER_CLASS_H__ -#define MSGPACK_RUBY_UNPACKER_CLASS_H__ - -#include "unpacker.h" - -extern const rb_data_type_t unpacker_data_type; - -static inline msgpack_unpacker_t *MessagePack_Unpacker_get(VALUE object) { - msgpack_unpacker_t *unpacker; - TypedData_Get_Struct(object, msgpack_unpacker_t, &unpacker_data_type, unpacker); - if (!unpacker) { - rb_raise(rb_eArgError, "Uninitialized Unpacker object"); - } - return unpacker; -} - -extern VALUE cMessagePack_Unpacker; - -void MessagePack_Unpacker_module_init(VALUE mMessagePack); - -VALUE MessagePack_Unpacker_alloc(VALUE klass); - -VALUE MessagePack_Unpacker_initialize(int argc, VALUE* argv, VALUE self); - -#endif - diff --git a/ext/msgpack/unpacker_ext_registry.c b/ext/msgpack/unpacker_ext_registry.c deleted file mode 100644 index 290fefab..00000000 --- a/ext/msgpack/unpacker_ext_registry.c +++ /dev/null @@ -1,74 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2015 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -#include "unpacker_ext_registry.h" - -void msgpack_unpacker_ext_registry_mark(msgpack_unpacker_ext_registry_t* ukrg) -{ - if (ukrg) { - for(int i=0; i < 256; i++) { - if (ukrg->array[i] != Qnil) { - rb_gc_mark(ukrg->array[i]); - } - } - } -} - -msgpack_unpacker_ext_registry_t* msgpack_unpacker_ext_registry_cow(msgpack_unpacker_ext_registry_t* src) -{ - msgpack_unpacker_ext_registry_t* dst; - if (src) { - if (src->borrow_count) { - dst = ALLOC(msgpack_unpacker_ext_registry_t); - dst->borrow_count = 0; - MEMCPY(dst->array, src->array, VALUE, 256); - msgpack_unpacker_ext_registry_release(src); - return dst; - } else { - return src; - } - } else { - dst = ALLOC(msgpack_unpacker_ext_registry_t); - dst->borrow_count = 0; - for(int i=0; i < 256; i++) { - dst->array[i] = Qnil; - } - return dst; - } -} - -void msgpack_unpacker_ext_registry_release(msgpack_unpacker_ext_registry_t* ukrg) -{ - if (ukrg) { - if (ukrg->borrow_count) { - ukrg->borrow_count--; - } else { - xfree(ukrg); - } - } -} - -void msgpack_unpacker_ext_registry_put(VALUE owner, msgpack_unpacker_ext_registry_t** ukrg, - VALUE ext_module, int ext_type, int flags, VALUE proc) -{ - msgpack_unpacker_ext_registry_t* ext_registry = msgpack_unpacker_ext_registry_cow(*ukrg); - - VALUE entry = rb_ary_new3(3, ext_module, proc, INT2FIX(flags)); - RB_OBJ_WRITE(owner, &ext_registry->array[ext_type + 128], entry); - *ukrg = ext_registry; -} diff --git a/ext/msgpack/unpacker_ext_registry.h b/ext/msgpack/unpacker_ext_registry.h deleted file mode 100644 index e957816d..00000000 --- a/ext/msgpack/unpacker_ext_registry.h +++ /dev/null @@ -1,62 +0,0 @@ -/* - * MessagePack for Ruby - * - * Copyright (C) 2008-2015 Sadayuki Furuhashi - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -#ifndef MSGPACK_RUBY_UNPACKER_EXT_REGISTRY_H__ -#define MSGPACK_RUBY_UNPACKER_EXT_REGISTRY_H__ - -#include "compat.h" -#include "ruby.h" - -#define MSGPACK_EXT_RECURSIVE 0b0001 - -struct msgpack_unpacker_ext_registry_t; -typedef struct msgpack_unpacker_ext_registry_t msgpack_unpacker_ext_registry_t; - -struct msgpack_unpacker_ext_registry_t { - unsigned int borrow_count; - VALUE array[256]; -}; - -void msgpack_unpacker_ext_registry_release(msgpack_unpacker_ext_registry_t* ukrg); - -static inline void msgpack_unpacker_ext_registry_borrow(msgpack_unpacker_ext_registry_t* src, msgpack_unpacker_ext_registry_t** dst) -{ - if (src) { - src->borrow_count++; - *dst = src; - } -} - -void msgpack_unpacker_ext_registry_mark(msgpack_unpacker_ext_registry_t* ukrg); - -void msgpack_unpacker_ext_registry_put(VALUE owner, msgpack_unpacker_ext_registry_t** ukrg, - VALUE ext_module, int ext_type, int flags, VALUE proc); - -static inline VALUE msgpack_unpacker_ext_registry_lookup(msgpack_unpacker_ext_registry_t* ukrg, - int ext_type, int* ext_flags_result) -{ - if (ukrg) { - VALUE entry = ukrg->array[ext_type + 128]; - if (entry != Qnil) { - *ext_flags_result = FIX2INT(rb_ary_entry(entry, 2)); - return rb_ary_entry(entry, 1); - } - } - return Qnil; -} - -#endif diff --git a/file.README.html b/file.README.html new file mode 100644 index 00000000..be4c95f9 --- /dev/null +++ b/file.README.html @@ -0,0 +1,367 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + File: README + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "README"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="file_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index</a> » + <span class="title">File: README</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><div id='filecontents'> +<h1 id="label-MessagePack">MessagePack</h1> + +<p><a href="http://msgpack.org">MessagePack</a> is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON but it’s faster and smaller. For example, small integers (like flags or error code) are encoded into a single byte, and typical short strings only require an extra byte in addition to the strings themselves.</p> + +<p>If you ever wished to use JSON for convenience (storing an image with metadata) but could not for technical reasons (binary data, size, speed…), MessagePack is a perfect replacement.</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +<span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span><span class='int'>2</span><span class='comma'>,</span><span class='int'>3</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'>#=> "\x93\x01\x02\x03" +</span><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span> <span class='comment'>#=> [1,2,3] +</span></code></pre> + +<p>Add msgpack to your Gemfile to install with Bundler:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># Gemfile +</span><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +</code></pre> + +<p>Or, use RubyGems to install:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_msgpack'>msgpack</span> +</code></pre> + +<p>Or, build msgpack-ruby and install from a checked-out msgpack-ruby repository:</p> + +<pre class="code ruby"><code class="ruby">bundle +rake +gem install --local pkg/msgpack +</code></pre> + +<h2 id="label-Use+cases">Use cases</h2> +<ul><li> +<p>Create REST API returing MessagePack using Rails + <a href="https://github.com/nesquena/rabl">RABL</a></p> +</li><li> +<p>Store objects efficiently serialized by msgpack on memcached or Redis</p> +</li><li> +<p>In fact Redis supports msgpack in <a href="https://redis.io/docs/latest/commands/eval/">EVAL-scripts</a></p> +</li><li> +<p>Upload data in efficient format from mobile devices such as smartphones</p> +</li><li> +<p>MessagePack works on iPhone/iPad and Android. See also <a href="https://github.com/msgpack/msgpack-objectivec">Objective-C</a> and <a href="https://github.com/msgpack/msgpack-java">Java</a> implementations</p> +</li><li> +<p>Design a portable protocol to communicate with embedded devices</p> +</li><li> +<p>Check also <a href="https://www.fluentd.org">Fluentd</a> 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)</p> +</li><li> +<p>Exchange objects between software components written in different languages</p> +</li><li> +<p>You’ll need a flexible but efficient format so that components exchange objects while keeping compatibility</p> +</li></ul> + +<h2 id="label-Portability">Portability</h2> + +<p>MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.</p> + +<p>And it works with MRI (CRuby) and Rubinius. Patches to improve portability are highly welcomed.</p> + +<h2 id="label-Serializing+objects">Serializing objects</h2> + +<p>Use <code>MessagePack.pack</code> or <code>to_msgpack</code>:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +<span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_pack'><span class='object_link'><a href="MessagePack.html#pack-class_method" title="MessagePack.pack (method)">pack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span> <span class='comment'># or +</span><span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> +<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_binwrite'>binwrite</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>mydata.msgpack</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span> +</code></pre> + +<h3 id="label-Streaming+serialization">Streaming serialization</h3> + +<p>Packer provides advanced API to serialize objects in streaming style:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># serialize a 2-element array [e1, e2] +</span><span class='id identifier rubyid_pk'>pk</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Packer.html" title="MessagePack::Packer (class)">Packer</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Packer.html#initialize-instance_method" title="MessagePack::Packer#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='id identifier rubyid_pk'>pk</span><span class='period'>.</span><span class='id identifier rubyid_write_array_header'>write_array_header</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_e1'>e1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_e2'>e2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_flush'>flush</span> +</code></pre> + +<p>See <a href="http://ruby.msgpack.org/MessagePack/Packer.html">API reference</a> for details.</p> + +<h2 id="label-Deserializing+objects">Deserializing objects</h2> + +<p>Use <code>MessagePack.unpack</code>:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +<span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_binread'>binread</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>mydata.msgpack</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> +<span class='id identifier rubyid_obj'>obj</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span> +</code></pre> + +<h3 id="label-Streaming+deserialization">Streaming deserialization</h3> + +<p>Unpacker provides advanced API to deserialize objects in streaming style:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># deserialize objects from an IO +</span><span class='id identifier rubyid_u'>u</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Unpacker.html#initialize-instance_method" title="MessagePack::Unpacker#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_obj'>obj</span><span class='op'>|</span> + <span class='comment'># ... +</span><span class='kw'>end</span> +</code></pre> + +<p>or event-driven style which works well with EventMachine:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># event-driven deserialization +</span><span class='kw'>def</span> <span class='id identifier rubyid_on_read'>on_read</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> + <span class='ivar'>@u</span> <span class='op'>||=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Unpacker.html#initialize-instance_method" title="MessagePack::Unpacker#initialize (method)">new</a></span></span> + <span class='ivar'>@u</span><span class='period'>.</span><span class='id identifier rubyid_feed_each'>feed_each</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_obj'>obj</span><span class='op'>|</span> + <span class='comment'># ... +</span> <span class='rbrace'>}</span> +<span class='kw'>end</span> +</code></pre> + +<p>See <a href="http://ruby.msgpack.org/MessagePack/Unpacker.html">API reference</a> for details.</p> + +<h2 id="label-Serializing+and+deserializing+symbols">Serializing and deserializing symbols</h2> + +<p>By default, symbols are serialized as strings:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_packed'>packed</span> <span class='op'>=</span> <span class='symbol'>:symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'># => "\xA6symbol" +</span><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_packed'>packed</span><span class='rparen'>)</span> <span class='comment'># => "symbol" +</span></code></pre> + +<p>This can be customized by registering an extension type for them:</p> + +<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x00</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span></span><span class='rparen'>)</span> + +<span class='comment'># symbols now survive round trips +</span><span class='id identifier rubyid_packed'>packed</span> <span class='op'>=</span> <span class='symbol'>:symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'># => "\xc7\x06\x00symbol" +</span><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_packed'>packed</span><span class='rparen'>)</span> <span class='comment'># => :symbol +</span></code></pre> + +<p>The extension type for symbols is configurable like any other extension type. For example, to customize how symbols are packed you can just redefine Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from being serialized altogether by throwing an exception:</p> + +<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'><span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span></span> + <span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack_ext'>to_msgpack_ext</span> + <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Serialization of symbols prohibited</span><span class='tstring_end'>"</span></span> + <span class='kw'>end</span> +<span class='kw'>end</span> + +<span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x00</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span></span><span class='rparen'>)</span> + +<span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='symbol'>:symbol</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>string</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'># => RuntimeError: Serialization of symbols prohibited +</span></code></pre> + +<h2 id="label-Serializing+and+deserializing+Time+instances">Serializing and deserializing Time instances</h2> + +<p>There are the timestamp extension type in MessagePack, but it is not registered by default.</p> + +<p>To map Ruby’s Time to MessagePack’s timestamp for the default factory:</p> + +<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span> + <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Timestamp.html" title="MessagePack::Timestamp (class)">Timestamp</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Timestamp.html#TYPE-constant" title="MessagePack::Timestamp::TYPE (constant)">TYPE</a></span></span><span class='comma'>,</span> <span class='comment'># or just -1 +</span> <span class='const'>Time</span><span class='comma'>,</span> + <span class='label'>packer:</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html" title="MessagePack::Time (class)">Time</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html#Packer-constant" title="MessagePack::Time::Packer (constant)">Packer</a></span></span><span class='comma'>,</span> + <span class='label'>unpacker:</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html" title="MessagePack::Time (class)">Time</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html#Unpacker-constant" title="MessagePack::Time::Unpacker (constant)">Unpacker</a></span></span> +<span class='rparen'>)</span> +</code></pre> + +<p>See <a href="http://ruby.msgpack.org/">API reference</a> for details.</p> + +<h2 id="label-Extension+Types">Extension Types</h2> + +<p>Packer and Unpacker support <a href="https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type">Extension types of MessagePack</a>.</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># register how to serialize custom class at first +</span><span class='id identifier rubyid_pk'>pk</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Packer.html" title="MessagePack::Packer (class)">Packer</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Packer.html#initialize-instance_method" title="MessagePack::Packer#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='id identifier rubyid_pk'>pk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='comma'>,</span> <span class='symbol'>:to_msgpack_ext</span><span class='rparen'>)</span> <span class='comment'># equal to pk.register_type(0x01, MyClass) +</span><span class='id identifier rubyid_pk'>pk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x02</span><span class='comma'>,</span> <span class='const'>MyClass2</span><span class='rparen'>)</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_obj'>obj</span><span class='op'>|</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_how_to_serialize'>how_to_serialize</span><span class='lparen'>(</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='comment'># blocks also available +</span> +<span class='comment'># almost same API for unpacker +</span><span class='id identifier rubyid_uk'>uk</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Unpacker.html#initialize-instance_method" title="MessagePack::Unpacker#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='rparen'>)</span> +<span class='id identifier rubyid_uk'>uk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='comma'>,</span> <span class='symbol'>:from_msgpack_ext</span><span class='rparen'>)</span> +<span class='id identifier rubyid_uk'>uk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x02</span><span class='rparen'>)</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_data'>data</span><span class='op'>|</span> <span class='const'>MyClass2</span><span class='period'>.</span><span class='id identifier rubyid_create_from_serialized_data'>create_from_serialized_data</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> <span class='rbrace'>}</span> +</code></pre> + +<p><code>MessagePack::Factory</code> is to create packer and unpacker which have same extension types.</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_factory'>factory</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">new</a></span></span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='rparen'>)</span> <span class='comment'># same with next line +</span><span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='comma'>,</span> <span class='label'>packer:</span> <span class='symbol'>:to_msgpack_ext</span><span class='comma'>,</span> <span class='label'>unpacker:</span> <span class='symbol'>:from_msgpack_ext</span><span class='rparen'>)</span> +<span class='id identifier rubyid_pk'>pk</span> <span class='op'>=</span> <span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_packer'>packer</span><span class='lparen'>(</span><span class='id identifier rubyid_options_for_packer'>options_for_packer</span><span class='rparen'>)</span> +<span class='id identifier rubyid_uk'>uk</span> <span class='op'>=</span> <span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_unpacker'>unpacker</span><span class='lparen'>(</span><span class='id identifier rubyid_options_for_unpacker'>options_for_unpacker</span><span class='rparen'>)</span> +</code></pre> + +<p>For <code>MessagePack.pack</code> and <code>MessagePack.unpack</code>, default packer/unpacker refer <code>MessagePack::DefaultFactory</code>. Call <code>MessagePack::DefaultFactory.register_type</code> to enable types process globally.</p> + +<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x03</span><span class='comma'>,</span> <span class='const'>MyClass3</span><span class='rparen'>)</span> +<span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data_with_ext_typeid_03'>data_with_ext_typeid_03</span><span class='rparen'>)</span> <span class='comment'>#=> MyClass3 instance +</span></code></pre> + +<p>Alternatively, extension types can call the packer or unpacker recursively to generate the extension data:</p> + +<pre class="code ruby"><code class="ruby"><span class='const'>Point</span> <span class='op'>=</span> <span class='const'>Struct</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:x</span><span class='comma'>,</span> <span class='symbol'>:y</span><span class='rparen'>)</span> +<span class='id identifier rubyid_factory'>factory</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">new</a></span></span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span> + <span class='int'>0x01</span><span class='comma'>,</span> + <span class='const'>Point</span><span class='comma'>,</span> + <span class='label'>packer:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='comma'>,</span> <span class='id identifier rubyid_packer'>packer</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_x'>x</span><span class='rparen'>)</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>unpacker:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_unpacker'>unpacker</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_x'>x</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='id identifier rubyid_y'>y</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>recursive:</span> <span class='kw'>true</span><span class='comma'>,</span> +<span class='rparen'>)</span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>12</span><span class='comma'>,</span> <span class='int'>34</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='comment'># => #<struct Point x=12, y=34> +</span></code></pre> + +<h2 id="label-Pooling">Pooling</h2> + +<p>Creating <code>Packer</code> and <code>Unpacker</code> objects is expensive. For best performance it is preferable to re-use these objects.</p> + +<p><code>MessagePack::Factory#pool</code> makes that easier:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_factory'>factory</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">new</a></span></span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span> + <span class='int'>0x01</span><span class='comma'>,</span> + <span class='const'>Point</span><span class='comma'>,</span> + <span class='label'>packer:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='comma'>,</span> <span class='id identifier rubyid_packer'>packer</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_x'>x</span><span class='rparen'>)</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>unpacker:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_unpacker'>unpacker</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_x'>x</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='id identifier rubyid_y'>y</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>recursive:</span> <span class='kw'>true</span><span class='comma'>,</span> +<span class='rparen'>)</span> +<span class='id identifier rubyid_pool'>pool</span> <span class='op'>=</span> <span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_pool'>pool</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span> <span class='comment'># The pool size should match the number of threads expected to use the factory concurrently. +</span> +<span class='id identifier rubyid_pool'>pool</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_pool'>pool</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>12</span><span class='comma'>,</span> <span class='int'>34</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='comment'># => #<struct Point x=12, y=34> +</span></code></pre> + +<h2 id="label-Buffer+API">Buffer API</h2> + +<p>MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.</p> + +<p>This <a href="http://ruby.msgpack.org/MessagePack/Buffer.html">MessagePack::Buffer</a> is backed with a fixed-length shared memory pool which is very fast for small data (<= 4KB), and has zero-copy capability which significantly affects performance to handle large binary data.</p> + +<h2 id="label-How+to+build+and+run+tests">How to build and run tests</h2> + +<p>Before building msgpack, you need to install bundler and dependencies.</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_bundler'>bundler</span> +<span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_install'>install</span> +</code></pre> + +<p>Then, you can run the tasks as follows:</p> + +<h3 id="label-Build">Build</h3> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_build'>build</span> +</code></pre> + +<h3 id="label-Run+tests">Run tests</h3> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_spec'>spec</span> +</code></pre> + +<h3 id="label-Generating+docs">Generating docs</h3> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_doc'>doc</span> +</code></pre> + +<h2 id="label-How+to+build+-java+rubygems">How to build -java rubygems</h2> + +<p>To build -java gems for JRuby, run:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_rake'>rake</span> <span class='label'>build:</span><span class='id identifier rubyid_java'>java</span> +</code></pre> + +<p>If this directory has Gemfile.lock (generated with MRI), remove it beforehand.</p> + +<h2 id="label-Updating+documents">Updating documents</h2> + +<p>Online documentation (<a href="https://ruby.msgpack.org">ruby.msgpack.org</a>) is generated from the gh-pages branch. To update documents in gh-pages branch:</p> + +<pre class="code ruby"><code class="ruby">bundle exec rake doc +git checkout gh-pages +cp doc/* ./ -a +</code></pre> + +<h2 id="label-Copyright">Copyright</h2> +<ul><li> +<p>Author</p> +</li><li> +<p>Sadayuki Furuhashi <a href="mailto:frsyuki@gmail.com">frsyuki@gmail.com</a></p> +</li><li> +<p>Copyright</p> +</li><li> +<p>Copyright © 2008-2015 Sadayuki Furuhashi</p> +</li><li> +<p>License</p> +</li><li> +<p>Apache License, Version 2.0</p> +</li></ul> +</div></div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/file_list.html b/file_list.html new file mode 100644 index 00000000..05465dfd --- /dev/null +++ b/file_list.html @@ -0,0 +1,59 @@ +<!DOCTYPE html> +<html > + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta charset="utf-8" /> + + <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" /> + + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script> + + + <title>File List</title> + <base id="base_target" target="_parent" /> + </head> + <body> + <div id="content"> + <div class="fixed_header"> + <h1 id="full_list_header">File List</h1> + <div id="full_list_nav"> + + <span><a target="_self" href="class_list.html"> + Classes + </a></span> + + <span><a target="_self" href="method_list.html"> + Methods + </a></span> + + <span><a target="_self" href="file_list.html"> + Files + </a></span> + + </div> + + <div id="search"> + <label for="search-class">Search:</label> + <input id="search-class" type="text" /> + </div> + </div> + + <ul id="full_list" class="file"> + + + <li id="object_README" class="odd"> + <div class="item"><span class="object_link"><a href="index.html" title="README">README</a></span></div> + </li> + + + + </ul> + </div> + </body> +</html> diff --git a/frames.html b/frames.html new file mode 100644 index 00000000..6586005f --- /dev/null +++ b/frames.html @@ -0,0 +1,22 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Documentation by YARD 0.9.37</title> +</head> +<script type="text/javascript"> +var mainUrl = 'index.html'; +try { + var match = decodeURIComponent(window.location.hash).match(/^#!(.+)/); + var name = match ? match[1] : mainUrl; + var url = new URL(name, location.href); + window.top.location.replace(url.origin === location.origin ? name : mainUrl); +} catch (e) { + window.top.location.replace(mainUrl); +} +</script> +<noscript> + <h1>Oops!</h1> + <h2>YARD requires JavaScript!</h2> +</noscript> +</html> diff --git a/index.html b/index.html new file mode 100644 index 00000000..3b4b032f --- /dev/null +++ b/index.html @@ -0,0 +1,367 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="UTF-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + File: README + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = "README"; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index</a> » + <span class="title">File: README</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><div id='filecontents'> +<h1 id="label-MessagePack">MessagePack</h1> + +<p><a href="http://msgpack.org">MessagePack</a> is an efficient binary serialization format. It lets you exchange data among multiple languages like JSON but it’s faster and smaller. For example, small integers (like flags or error code) are encoded into a single byte, and typical short strings only require an extra byte in addition to the strings themselves.</p> + +<p>If you ever wished to use JSON for convenience (storing an image with metadata) but could not for technical reasons (binary data, size, speed…), MessagePack is a perfect replacement.</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +<span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span><span class='int'>2</span><span class='comma'>,</span><span class='int'>3</span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'>#=> "\x93\x01\x02\x03" +</span><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span> <span class='comment'>#=> [1,2,3] +</span></code></pre> + +<p>Add msgpack to your Gemfile to install with Bundler:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># Gemfile +</span><span class='id identifier rubyid_gem'>gem</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +</code></pre> + +<p>Or, use RubyGems to install:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_msgpack'>msgpack</span> +</code></pre> + +<p>Or, build msgpack-ruby and install from a checked-out msgpack-ruby repository:</p> + +<pre class="code ruby"><code class="ruby">bundle +rake +gem install --local pkg/msgpack +</code></pre> + +<h2 id="label-Use+cases">Use cases</h2> +<ul><li> +<p>Create REST API returing MessagePack using Rails + <a href="https://github.com/nesquena/rabl">RABL</a></p> +</li><li> +<p>Store objects efficiently serialized by msgpack on memcached or Redis</p> +</li><li> +<p>In fact Redis supports msgpack in <a href="https://redis.io/docs/latest/commands/eval/">EVAL-scripts</a></p> +</li><li> +<p>Upload data in efficient format from mobile devices such as smartphones</p> +</li><li> +<p>MessagePack works on iPhone/iPad and Android. See also <a href="https://github.com/msgpack/msgpack-objectivec">Objective-C</a> and <a href="https://github.com/msgpack/msgpack-java">Java</a> implementations</p> +</li><li> +<p>Design a portable protocol to communicate with embedded devices</p> +</li><li> +<p>Check also <a href="https://www.fluentd.org">Fluentd</a> 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)</p> +</li><li> +<p>Exchange objects between software components written in different languages</p> +</li><li> +<p>You’ll need a flexible but efficient format so that components exchange objects while keeping compatibility</p> +</li></ul> + +<h2 id="label-Portability">Portability</h2> + +<p>MessagePack for Ruby should run on x86, ARM, PowerPC, SPARC and other CPU architectures.</p> + +<p>And it works with MRI (CRuby) and Rubinius. Patches to improve portability are highly welcomed.</p> + +<h2 id="label-Serializing+objects">Serializing objects</h2> + +<p>Use <code>MessagePack.pack</code> or <code>to_msgpack</code>:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +<span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_pack'><span class='object_link'><a href="MessagePack.html#pack-class_method" title="MessagePack.pack (method)">pack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_obj'>obj</span><span class='rparen'>)</span> <span class='comment'># or +</span><span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> +<span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_binwrite'>binwrite</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>mydata.msgpack</span><span class='tstring_end'>'</span></span><span class='comma'>,</span> <span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span> +</code></pre> + +<h3 id="label-Streaming+serialization">Streaming serialization</h3> + +<p>Packer provides advanced API to serialize objects in streaming style:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># serialize a 2-element array [e1, e2] +</span><span class='id identifier rubyid_pk'>pk</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Packer.html" title="MessagePack::Packer (class)">Packer</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Packer.html#initialize-instance_method" title="MessagePack::Packer#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='id identifier rubyid_pk'>pk</span><span class='period'>.</span><span class='id identifier rubyid_write_array_header'>write_array_header</span><span class='lparen'>(</span><span class='int'>2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_e1'>e1</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_e2'>e2</span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_flush'>flush</span> +</code></pre> + +<p>See <a href="http://ruby.msgpack.org/MessagePack/Packer.html">API reference</a> for details.</p> + +<h2 id="label-Deserializing+objects">Deserializing objects</h2> + +<p>Use <code>MessagePack.unpack</code>:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_require'>require</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>msgpack</span><span class='tstring_end'>'</span></span> +<span class='id identifier rubyid_msg'>msg</span> <span class='op'>=</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_binread'>binread</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>mydata.msgpack</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> +<span class='id identifier rubyid_obj'>obj</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_msg'>msg</span><span class='rparen'>)</span> +</code></pre> + +<h3 id="label-Streaming+deserialization">Streaming deserialization</h3> + +<p>Unpacker provides advanced API to deserialize objects in streaming style:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># deserialize objects from an IO +</span><span class='id identifier rubyid_u'>u</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Unpacker.html#initialize-instance_method" title="MessagePack::Unpacker#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='id identifier rubyid_u'>u</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_obj'>obj</span><span class='op'>|</span> + <span class='comment'># ... +</span><span class='kw'>end</span> +</code></pre> + +<p>or event-driven style which works well with EventMachine:</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># event-driven deserialization +</span><span class='kw'>def</span> <span class='id identifier rubyid_on_read'>on_read</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> + <span class='ivar'>@u</span> <span class='op'>||=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Unpacker.html#initialize-instance_method" title="MessagePack::Unpacker#initialize (method)">new</a></span></span> + <span class='ivar'>@u</span><span class='period'>.</span><span class='id identifier rubyid_feed_each'>feed_each</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> <span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_obj'>obj</span><span class='op'>|</span> + <span class='comment'># ... +</span> <span class='rbrace'>}</span> +<span class='kw'>end</span> +</code></pre> + +<p>See <a href="http://ruby.msgpack.org/MessagePack/Unpacker.html">API reference</a> for details.</p> + +<h2 id="label-Serializing+and+deserializing+symbols">Serializing and deserializing symbols</h2> + +<p>By default, symbols are serialized as strings:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_packed'>packed</span> <span class='op'>=</span> <span class='symbol'>:symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'># => "\xA6symbol" +</span><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_packed'>packed</span><span class='rparen'>)</span> <span class='comment'># => "symbol" +</span></code></pre> + +<p>This can be customized by registering an extension type for them:</p> + +<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x00</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span></span><span class='rparen'>)</span> + +<span class='comment'># symbols now survive round trips +</span><span class='id identifier rubyid_packed'>packed</span> <span class='op'>=</span> <span class='symbol'>:symbol</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'># => "\xc7\x06\x00symbol" +</span><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_packed'>packed</span><span class='rparen'>)</span> <span class='comment'># => :symbol +</span></code></pre> + +<p>The extension type for symbols is configurable like any other extension type. For example, to customize how symbols are packed you can just redefine Symbol#to_msgpack_ext. Doing this gives you an option to prevent symbols from being serialized altogether by throwing an exception:</p> + +<pre class="code ruby"><code class="ruby"><span class='kw'>class</span> <span class='const'><span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span></span> + <span class='kw'>def</span> <span class='id identifier rubyid_to_msgpack_ext'>to_msgpack_ext</span> + <span class='id identifier rubyid_raise'>raise</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>Serialization of symbols prohibited</span><span class='tstring_end'>"</span></span> + <span class='kw'>end</span> +<span class='kw'>end</span> + +<span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x00</span><span class='comma'>,</span> <span class='const'><span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span></span><span class='rparen'>)</span> + +<span class='lbracket'>[</span><span class='int'>1</span><span class='comma'>,</span> <span class='symbol'>:symbol</span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>string</span><span class='tstring_end'>'</span></span><span class='rbracket'>]</span><span class='period'>.</span><span class='id identifier rubyid_to_msgpack'>to_msgpack</span> <span class='comment'># => RuntimeError: Serialization of symbols prohibited +</span></code></pre> + +<h2 id="label-Serializing+and+deserializing+Time+instances">Serializing and deserializing Time instances</h2> + +<p>There are the timestamp extension type in MessagePack, but it is not registered by default.</p> + +<p>To map Ruby’s Time to MessagePack’s timestamp for the default factory:</p> + +<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span> + <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Timestamp.html" title="MessagePack::Timestamp (class)">Timestamp</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Timestamp.html#TYPE-constant" title="MessagePack::Timestamp::TYPE (constant)">TYPE</a></span></span><span class='comma'>,</span> <span class='comment'># or just -1 +</span> <span class='const'>Time</span><span class='comma'>,</span> + <span class='label'>packer:</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html" title="MessagePack::Time (class)">Time</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html#Packer-constant" title="MessagePack::Time::Packer (constant)">Packer</a></span></span><span class='comma'>,</span> + <span class='label'>unpacker:</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html" title="MessagePack::Time (class)">Time</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Time.html#Unpacker-constant" title="MessagePack::Time::Unpacker (constant)">Unpacker</a></span></span> +<span class='rparen'>)</span> +</code></pre> + +<p>See <a href="http://ruby.msgpack.org/">API reference</a> for details.</p> + +<h2 id="label-Extension+Types">Extension Types</h2> + +<p>Packer and Unpacker support <a href="https://github.com/msgpack/msgpack/blob/master/spec.md#types-extension-type">Extension types of MessagePack</a>.</p> + +<pre class="code ruby"><code class="ruby"><span class='comment'># register how to serialize custom class at first +</span><span class='id identifier rubyid_pk'>pk</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Packer.html" title="MessagePack::Packer (class)">Packer</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Packer.html#initialize-instance_method" title="MessagePack::Packer#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_io'>io</span><span class='rparen'>)</span> +<span class='id identifier rubyid_pk'>pk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='comma'>,</span> <span class='symbol'>:to_msgpack_ext</span><span class='rparen'>)</span> <span class='comment'># equal to pk.register_type(0x01, MyClass) +</span><span class='id identifier rubyid_pk'>pk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x02</span><span class='comma'>,</span> <span class='const'>MyClass2</span><span class='rparen'>)</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_obj'>obj</span><span class='op'>|</span> <span class='id identifier rubyid_obj'>obj</span><span class='period'>.</span><span class='id identifier rubyid_how_to_serialize'>how_to_serialize</span><span class='lparen'>(</span><span class='rparen'>)</span> <span class='rbrace'>}</span> <span class='comment'># blocks also available +</span> +<span class='comment'># almost same API for unpacker +</span><span class='id identifier rubyid_uk'>uk</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Unpacker.html" title="MessagePack::Unpacker (class)">Unpacker</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Unpacker.html#initialize-instance_method" title="MessagePack::Unpacker#initialize (method)">new</a></span></span><span class='lparen'>(</span><span class='rparen'>)</span> +<span class='id identifier rubyid_uk'>uk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='comma'>,</span> <span class='symbol'>:from_msgpack_ext</span><span class='rparen'>)</span> +<span class='id identifier rubyid_uk'>uk</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x02</span><span class='rparen'>)</span><span class='lbrace'>{</span><span class='op'>|</span><span class='id identifier rubyid_data'>data</span><span class='op'>|</span> <span class='const'>MyClass2</span><span class='period'>.</span><span class='id identifier rubyid_create_from_serialized_data'>create_from_serialized_data</span><span class='lparen'>(</span><span class='id identifier rubyid_data'>data</span><span class='rparen'>)</span> <span class='rbrace'>}</span> +</code></pre> + +<p><code>MessagePack::Factory</code> is to create packer and unpacker which have same extension types.</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_factory'>factory</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">new</a></span></span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='rparen'>)</span> <span class='comment'># same with next line +</span><span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x01</span><span class='comma'>,</span> <span class='const'>MyClass1</span><span class='comma'>,</span> <span class='label'>packer:</span> <span class='symbol'>:to_msgpack_ext</span><span class='comma'>,</span> <span class='label'>unpacker:</span> <span class='symbol'>:from_msgpack_ext</span><span class='rparen'>)</span> +<span class='id identifier rubyid_pk'>pk</span> <span class='op'>=</span> <span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_packer'>packer</span><span class='lparen'>(</span><span class='id identifier rubyid_options_for_packer'>options_for_packer</span><span class='rparen'>)</span> +<span class='id identifier rubyid_uk'>uk</span> <span class='op'>=</span> <span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_unpacker'>unpacker</span><span class='lparen'>(</span><span class='id identifier rubyid_options_for_unpacker'>options_for_unpacker</span><span class='rparen'>)</span> +</code></pre> + +<p>For <code>MessagePack.pack</code> and <code>MessagePack.unpack</code>, default packer/unpacker refer <code>MessagePack::DefaultFactory</code>. Call <code>MessagePack::DefaultFactory.register_type</code> to enable types process globally.</p> + +<pre class="code ruby"><code class="ruby"><span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack.html#DefaultFactory-constant" title="MessagePack::DefaultFactory (constant)">DefaultFactory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span><span class='int'>0x03</span><span class='comma'>,</span> <span class='const'>MyClass3</span><span class='rparen'>)</span> +<span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='period'>.</span><span class='id identifier rubyid_unpack'><span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span></span><span class='lparen'>(</span><span class='id identifier rubyid_data_with_ext_typeid_03'>data_with_ext_typeid_03</span><span class='rparen'>)</span> <span class='comment'>#=> MyClass3 instance +</span></code></pre> + +<p>Alternatively, extension types can call the packer or unpacker recursively to generate the extension data:</p> + +<pre class="code ruby"><code class="ruby"><span class='const'>Point</span> <span class='op'>=</span> <span class='const'>Struct</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='symbol'>:x</span><span class='comma'>,</span> <span class='symbol'>:y</span><span class='rparen'>)</span> +<span class='id identifier rubyid_factory'>factory</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">new</a></span></span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span> + <span class='int'>0x01</span><span class='comma'>,</span> + <span class='const'>Point</span><span class='comma'>,</span> + <span class='label'>packer:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='comma'>,</span> <span class='id identifier rubyid_packer'>packer</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_x'>x</span><span class='rparen'>)</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>unpacker:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_unpacker'>unpacker</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_x'>x</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='id identifier rubyid_y'>y</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>recursive:</span> <span class='kw'>true</span><span class='comma'>,</span> +<span class='rparen'>)</span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>12</span><span class='comma'>,</span> <span class='int'>34</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='comment'># => #<struct Point x=12, y=34> +</span></code></pre> + +<h2 id="label-Pooling">Pooling</h2> + +<p>Creating <code>Packer</code> and <code>Unpacker</code> objects is expensive. For best performance it is preferable to re-use these objects.</p> + +<p><code>MessagePack::Factory#pool</code> makes that easier:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_factory'>factory</span> <span class='op'>=</span> <span class='const'><span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="MessagePack/Factory.html" title="MessagePack::Factory (class)">Factory</a></span></span><span class='period'>.</span><span class='id identifier rubyid_new'><span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">new</a></span></span> +<span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_register_type'>register_type</span><span class='lparen'>(</span> + <span class='int'>0x01</span><span class='comma'>,</span> + <span class='const'>Point</span><span class='comma'>,</span> + <span class='label'>packer:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='comma'>,</span> <span class='id identifier rubyid_packer'>packer</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_x'>x</span><span class='rparen'>)</span> + <span class='id identifier rubyid_packer'>packer</span><span class='period'>.</span><span class='id identifier rubyid_write'>write</span><span class='lparen'>(</span><span class='id identifier rubyid_point'>point</span><span class='period'>.</span><span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>unpacker:</span> <span class='tlambda'>-></span><span class='lparen'>(</span><span class='id identifier rubyid_unpacker'>unpacker</span><span class='rparen'>)</span> <span class='tlambeg'>{</span> + <span class='id identifier rubyid_x'>x</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='id identifier rubyid_y'>y</span> <span class='op'>=</span> <span class='id identifier rubyid_unpacker'>unpacker</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> + <span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='id identifier rubyid_x'>x</span><span class='comma'>,</span> <span class='id identifier rubyid_y'>y</span><span class='rparen'>)</span> + <span class='rbrace'>}</span><span class='comma'>,</span> + <span class='label'>recursive:</span> <span class='kw'>true</span><span class='comma'>,</span> +<span class='rparen'>)</span> +<span class='id identifier rubyid_pool'>pool</span> <span class='op'>=</span> <span class='id identifier rubyid_factory'>factory</span><span class='period'>.</span><span class='id identifier rubyid_pool'>pool</span><span class='lparen'>(</span><span class='int'>5</span><span class='rparen'>)</span> <span class='comment'># The pool size should match the number of threads expected to use the factory concurrently. +</span> +<span class='id identifier rubyid_pool'>pool</span><span class='period'>.</span><span class='id identifier rubyid_load'>load</span><span class='lparen'>(</span><span class='id identifier rubyid_pool'>pool</span><span class='period'>.</span><span class='id identifier rubyid_dump'>dump</span><span class='lparen'>(</span><span class='const'>Point</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span><span class='lparen'>(</span><span class='int'>12</span><span class='comma'>,</span> <span class='int'>34</span><span class='rparen'>)</span><span class='rparen'>)</span><span class='rparen'>)</span> <span class='comment'># => #<struct Point x=12, y=34> +</span></code></pre> + +<h2 id="label-Buffer+API">Buffer API</h2> + +<p>MessagePack for Ruby provides a buffer API so that you can read or write data by hand, not via Packer or Unpacker API.</p> + +<p>This <a href="http://ruby.msgpack.org/MessagePack/Buffer.html">MessagePack::Buffer</a> is backed with a fixed-length shared memory pool which is very fast for small data (<= 4KB), and has zero-copy capability which significantly affects performance to handle large binary data.</p> + +<h2 id="label-How+to+build+and+run+tests">How to build and run tests</h2> + +<p>Before building msgpack, you need to install bundler and dependencies.</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_gem'>gem</span> <span class='id identifier rubyid_install'>install</span> <span class='id identifier rubyid_bundler'>bundler</span> +<span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_install'>install</span> +</code></pre> + +<p>Then, you can run the tasks as follows:</p> + +<h3 id="label-Build">Build</h3> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_build'>build</span> +</code></pre> + +<h3 id="label-Run+tests">Run tests</h3> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_spec'>spec</span> +</code></pre> + +<h3 id="label-Generating+docs">Generating docs</h3> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_bundle'>bundle</span> <span class='id identifier rubyid_exec'>exec</span> <span class='id identifier rubyid_rake'>rake</span> <span class='id identifier rubyid_doc'>doc</span> +</code></pre> + +<h2 id="label-How+to+build+-java+rubygems">How to build -java rubygems</h2> + +<p>To build -java gems for JRuby, run:</p> + +<pre class="code ruby"><code class="ruby"><span class='id identifier rubyid_rake'>rake</span> <span class='label'>build:</span><span class='id identifier rubyid_java'>java</span> +</code></pre> + +<p>If this directory has Gemfile.lock (generated with MRI), remove it beforehand.</p> + +<h2 id="label-Updating+documents">Updating documents</h2> + +<p>Online documentation (<a href="https://ruby.msgpack.org">ruby.msgpack.org</a>) is generated from the gh-pages branch. To update documents in gh-pages branch:</p> + +<pre class="code ruby"><code class="ruby">bundle exec rake doc +git checkout gh-pages +cp doc/* ./ -a +</code></pre> + +<h2 id="label-Copyright">Copyright</h2> +<ul><li> +<p>Author</p> +</li><li> +<p>Sadayuki Furuhashi <a href="mailto:frsyuki@gmail.com">frsyuki@gmail.com</a></p> +</li><li> +<p>Copyright</p> +</li><li> +<p>Copyright © 2008-2015 Sadayuki Furuhashi</p> +</li><li> +<p>License</p> +</li><li> +<p>Apache License, Version 2.0</p> +</li></ul> +</div></div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file diff --git a/js/app.js b/js/app.js new file mode 100644 index 00000000..b5610eff --- /dev/null +++ b/js/app.js @@ -0,0 +1,344 @@ +(function () { + var localStorage = {}, + sessionStorage = {}; + try { + localStorage = window.localStorage; + } catch (e) {} + try { + sessionStorage = window.sessionStorage; + } catch (e) {} + + function createSourceLinks() { + $(".method_details_list .source_code").before( + "<span class='showSource'>[<a href='#' class='toggleSource'>View source</a>]</span>" + ); + $(".toggleSource").toggle( + function () { + $(this).parent().nextAll(".source_code").slideDown(100); + $(this).text("Hide source"); + }, + function () { + $(this).parent().nextAll(".source_code").slideUp(100); + $(this).text("View source"); + } + ); + } + + function createDefineLinks() { + var tHeight = 0; + $(".defines").after(" <a href='#' class='toggleDefines'>more...</a>"); + $(".toggleDefines").toggle( + function () { + tHeight = $(this).parent().prev().height(); + $(this).prev().css("display", "inline"); + $(this).parent().prev().height($(this).parent().height()); + $(this).text("(less)"); + }, + function () { + $(this).prev().hide(); + $(this).parent().prev().height(tHeight); + $(this).text("more..."); + } + ); + } + + function createFullTreeLinks() { + var tHeight = 0; + $(".inheritanceTree").toggle( + function () { + tHeight = $(this).parent().prev().height(); + $(this).parent().toggleClass("showAll"); + $(this).text("(hide)"); + $(this).parent().prev().height($(this).parent().height()); + }, + function () { + $(this).parent().toggleClass("showAll"); + $(this).parent().prev().height(tHeight); + $(this).text("show all"); + } + ); + } + + function searchFrameButtons() { + $(".full_list_link").click(function () { + toggleSearchFrame(this, $(this).attr("href")); + return false; + }); + window.addEventListener("message", function (e) { + if (e.data === "navEscape") { + $("#nav").slideUp(100); + $("#search a").removeClass("active inactive"); + $(window).focus(); + } + }); + + $(window).resize(function () { + if ($("#search:visible").length === 0) { + $("#nav").removeAttr("style"); + $("#search a").removeClass("active inactive"); + $(window).focus(); + } + }); + } + + function toggleSearchFrame(id, link) { + var frame = $("#nav"); + $("#search a").removeClass("active").addClass("inactive"); + if (frame.attr("src") === link && frame.css("display") !== "none") { + frame.slideUp(100); + $("#search a").removeClass("active inactive"); + } else { + $(id).addClass("active").removeClass("inactive"); + if (frame.attr("src") !== link) frame.attr("src", link); + frame.slideDown(100); + } + } + + function linkSummaries() { + $(".summary_signature").click(function () { + document.location = $(this).find("a").attr("href"); + }); + } + + function summaryToggle() { + $(".summary_toggle").click(function (e) { + e.preventDefault(); + localStorage.summaryCollapsed = $(this).text(); + $(".summary_toggle").each(function () { + $(this).text($(this).text() == "collapse" ? "expand" : "collapse"); + var next = $(this).parent().parent().nextAll("ul.summary").first(); + if (next.hasClass("compact")) { + next.toggle(); + next.nextAll("ul.summary").first().toggle(); + } else if (next.hasClass("summary")) { + var list = $('<ul class="summary compact" />'); + list.html(next.html()); + list.find(".summary_desc, .note").remove(); + list.find("a").each(function () { + $(this).html($(this).find("strong").html()); + $(this).parent().html($(this)[0].outerHTML); + }); + next.before(list); + next.toggle(); + } + }); + return false; + }); + if (localStorage.summaryCollapsed == "collapse") { + $(".summary_toggle").first().click(); + } else { + localStorage.summaryCollapsed = "expand"; + } + } + + function constantSummaryToggle() { + $(".constants_summary_toggle").click(function (e) { + e.preventDefault(); + localStorage.summaryCollapsed = $(this).text(); + $(".constants_summary_toggle").each(function () { + $(this).text($(this).text() == "collapse" ? "expand" : "collapse"); + var next = $(this).parent().parent().nextAll("dl.constants").first(); + if (next.hasClass("compact")) { + next.toggle(); + next.nextAll("dl.constants").first().toggle(); + } else if (next.hasClass("constants")) { + var list = $('<dl class="constants compact" />'); + list.html(next.html()); + list.find("dt").each(function () { + $(this).addClass("summary_signature"); + $(this).text($(this).text().split("=")[0]); + if ($(this).has(".deprecated").length) { + $(this).addClass("deprecated"); + } + }); + // Add the value of the constant as "Tooltip" to the summary object + list.find("pre.code").each(function () { + console.log($(this).parent()); + var dt_element = $(this).parent().prev(); + var tooltip = $(this).text(); + if (dt_element.hasClass("deprecated")) { + tooltip = "Deprecated. " + tooltip; + } + dt_element.attr("title", tooltip); + }); + list.find(".docstring, .tags, dd").remove(); + next.before(list); + next.toggle(); + } + }); + return false; + }); + if (localStorage.summaryCollapsed == "collapse") { + $(".constants_summary_toggle").first().click(); + } else { + localStorage.summaryCollapsed = "expand"; + } + } + + function generateTOC() { + if ($("#filecontents").length === 0) return; + var _toc = $('<ol class="top"></ol>'); + var show = false; + var toc = _toc; + var counter = 0; + var tags = ["h2", "h3", "h4", "h5", "h6"]; + var i; + var curli; + if ($("#filecontents h1").length > 1) tags.unshift("h1"); + for (i = 0; i < tags.length; i++) { + tags[i] = "#filecontents " + tags[i]; + } + var lastTag = parseInt(tags[0][1], 10); + $(tags.join(", ")).each(function () { + if ($(this).parents(".method_details .docstring").length != 0) return; + if (this.id == "filecontents") return; + show = true; + var thisTag = parseInt(this.tagName[1], 10); + if (this.id.length === 0) { + var proposedId = $(this).attr("toc-id"); + if (typeof proposedId != "undefined") this.id = proposedId; + else { + var proposedId = $(this) + .text() + .replace(/[^a-z0-9-]/gi, "_"); + if ($("#" + proposedId).length > 0) { + proposedId += counter; + counter++; + } + this.id = proposedId; + } + } + if (thisTag > lastTag) { + for (i = 0; i < thisTag - lastTag; i++) { + if (typeof curli == "undefined") { + curli = $("<li/>"); + toc.append(curli); + } + toc = $("<ol/>"); + curli.append(toc); + curli = undefined; + } + } + if (thisTag < lastTag) { + for (i = 0; i < lastTag - thisTag; i++) { + toc = toc.parent(); + toc = toc.parent(); + } + } + var title = $(this).attr("toc-title"); + if (typeof title == "undefined") title = $(this).text(); + curli = $('<li><a href="#' + this.id + '">' + title + "</a></li>"); + toc.append(curli); + lastTag = thisTag; + }); + if (!show) return; + html = + '<div id="toc"><p class="title hide_toc"><a href="#"><strong>Table of Contents</strong></a></p></div>'; + $("#content").prepend(html); + $("#toc").append(_toc); + $("#toc .hide_toc").toggle( + function () { + $("#toc .top").slideUp("fast"); + $("#toc").toggleClass("hidden"); + $("#toc .title small").toggle(); + }, + function () { + $("#toc .top").slideDown("fast"); + $("#toc").toggleClass("hidden"); + $("#toc .title small").toggle(); + } + ); + } + + function navResizeFn(e) { + if (e.which !== 1) { + navResizeFnStop(); + return; + } + + sessionStorage.navWidth = e.pageX.toString(); + $(".nav_wrap").css("width", e.pageX); + $(".nav_wrap").css("-ms-flex", "inherit"); + } + + function navResizeFnStop() { + $(window).unbind("mousemove", navResizeFn); + window.removeEventListener("message", navMessageFn, false); + } + + function navMessageFn(e) { + if (e.data.action === "mousemove") navResizeFn(e.data.event); + if (e.data.action === "mouseup") navResizeFnStop(); + } + + function navResizer() { + $("#resizer").mousedown(function (e) { + e.preventDefault(); + $(window).mousemove(navResizeFn); + window.addEventListener("message", navMessageFn, false); + }); + $(window).mouseup(navResizeFnStop); + + if (sessionStorage.navWidth) { + navResizeFn({ which: 1, pageX: parseInt(sessionStorage.navWidth, 10) }); + } + } + + function navExpander() { + if (typeof pathId === "undefined") return; + var done = false, + timer = setTimeout(postMessage, 500); + function postMessage() { + if (done) return; + clearTimeout(timer); + var opts = { action: "expand", path: pathId }; + document.getElementById("nav").contentWindow.postMessage(opts, "*"); + done = true; + } + + window.addEventListener( + "message", + function (event) { + if (event.data === "navReady") postMessage(); + return false; + }, + false + ); + } + + function mainFocus() { + var hash = window.location.hash; + if (hash !== "" && $(hash)[0]) { + $(hash)[0].scrollIntoView(); + } + + setTimeout(function () { + $("#main").focus(); + }, 10); + } + + function navigationChange() { + // This works around the broken anchor navigation with the YARD template. + window.onpopstate = function () { + var hash = window.location.hash; + if (hash !== "" && $(hash)[0]) { + $(hash)[0].scrollIntoView(); + } + }; + } + + $(document).ready(function () { + navResizer(); + navExpander(); + createSourceLinks(); + createDefineLinks(); + createFullTreeLinks(); + searchFrameButtons(); + linkSummaries(); + summaryToggle(); + constantSummaryToggle(); + generateTOC(); + mainFocus(); + navigationChange(); + }); +})(); diff --git a/js/full_list.js b/js/full_list.js new file mode 100644 index 00000000..12bba48d --- /dev/null +++ b/js/full_list.js @@ -0,0 +1,242 @@ +(function() { + +var $clicked = $(null); +var searchTimeout = null; +var searchCache = []; +var caseSensitiveMatch = false; +var ignoreKeyCodeMin = 8; +var ignoreKeyCodeMax = 46; +var commandKey = 91; + +RegExp.escape = function(text) { + return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&"); +} + +function escapeShortcut() { + $(document).keydown(function(evt) { + if (evt.which == 27) { + window.parent.postMessage('navEscape', '*'); + } + }); +} + +function navResizer() { + $(window).mousemove(function(e) { + window.parent.postMessage({ + action: 'mousemove', event: {pageX: e.pageX, which: e.which} + }, '*'); + }).mouseup(function(e) { + window.parent.postMessage({action: 'mouseup'}, '*'); + }); + window.parent.postMessage("navReady", "*"); +} + +function clearSearchTimeout() { + clearTimeout(searchTimeout); + searchTimeout = null; +} + +function enableLinks() { + // load the target page in the parent window + $('#full_list li').on('click', function(evt) { + $('#full_list li').removeClass('clicked'); + $clicked = $(this); + $clicked.addClass('clicked'); + evt.stopPropagation(); + + if (evt.target.tagName === 'A') return true; + + var elem = $clicked.find('> .item .object_link a')[0]; + var e = evt.originalEvent; + var newEvent = new MouseEvent(evt.originalEvent.type); + newEvent.initMouseEvent(e.type, e.canBubble, e.cancelable, e.view, e.detail, e.screenX, e.screenY, e.clientX, e.clientY, e.ctrlKey, e.altKey, e.shiftKey, e.metaKey, e.button, e.relatedTarget); + elem.dispatchEvent(newEvent); + evt.preventDefault(); + return false; + }); +} + +function enableToggles() { + // show/hide nested classes on toggle click + $('#full_list a.toggle').on('click', function(evt) { + evt.stopPropagation(); + evt.preventDefault(); + $(this).parent().parent().toggleClass('collapsed'); + $(this).attr('aria-expanded', function (i, attr) { + return attr == 'true' ? 'false' : 'true' + }); + highlight(); + }); + + // navigation of nested classes using keyboard + $('#full_list a.toggle').on('keypress',function(evt) { + // enter key is pressed + if (evt.which == 13) { + evt.stopPropagation(); + evt.preventDefault(); + $(this).parent().parent().toggleClass('collapsed'); + $(this).attr('aria-expanded', function (i, attr) { + return attr == 'true' ? 'false' : 'true' + }); + highlight(); + } + }); +} + +function populateSearchCache() { + $('#full_list li .item').each(function() { + var $node = $(this); + var $link = $node.find('.object_link a'); + if ($link.length > 0) { + searchCache.push({ + node: $node, + link: $link, + name: $link.text(), + fullName: $link.attr('title').split(' ')[0] + }); + } + }); +} + +function enableSearch() { + $('#search input').keyup(function(event) { + if (ignoredKeyPress(event)) return; + if (this.value === "") { + clearSearch(); + } else { + performSearch(this.value); + } + }); + + $('#full_list').after("<div id='noresults' role='status' style='display: none'></div>"); +} + +function ignoredKeyPress(event) { + if ( + (event.keyCode > ignoreKeyCodeMin && event.keyCode < ignoreKeyCodeMax) || + (event.keyCode == commandKey) + ) { + return true; + } else { + return false; + } +} + +function clearSearch() { + clearSearchTimeout(); + $('#full_list .found').removeClass('found').each(function() { + var $link = $(this).find('.object_link a'); + $link.text($link.text()); + }); + $('#full_list, #content').removeClass('insearch'); + $clicked.parents().removeClass('collapsed'); + highlight(); +} + +function performSearch(searchString) { + clearSearchTimeout(); + $('#full_list, #content').addClass('insearch'); + $('#noresults').text('').hide(); + partialSearch(searchString, 0); +} + +function partialSearch(searchString, offset) { + var lastRowClass = ''; + var i = null; + for (i = offset; i < Math.min(offset + 50, searchCache.length); i++) { + var item = searchCache[i]; + var searchName = (searchString.indexOf('::') != -1 ? item.fullName : item.name); + var matchString = buildMatchString(searchString); + var matchRegexp = new RegExp(matchString, caseSensitiveMatch ? "" : "i"); + if (searchName.match(matchRegexp) == null) { + item.node.removeClass('found'); + item.link.text(item.link.text()); + } + else { + item.node.addClass('found'); + item.node.removeClass(lastRowClass).addClass(lastRowClass == 'r1' ? 'r2' : 'r1'); + lastRowClass = item.node.hasClass('r1') ? 'r1' : 'r2'; + item.link.html(item.name.replace(matchRegexp, "<strong>$&</strong>")); + } + } + if(i == searchCache.length) { + searchDone(); + } else { + searchTimeout = setTimeout(function() { + partialSearch(searchString, i); + }, 0); + } +} + +function searchDone() { + searchTimeout = null; + highlight(); + var found = $('#full_list li:visible').size(); + if (found === 0) { + $('#noresults').text('No results were found.'); + } else { + // This is read out to screen readers + $('#noresults').text('There are ' + found + ' results.'); + } + $('#noresults').show(); + $('#content').removeClass('insearch'); +} + +function buildMatchString(searchString, event) { + caseSensitiveMatch = searchString.match(/[A-Z]/) != null; + var regexSearchString = RegExp.escape(searchString); + if (caseSensitiveMatch) { + regexSearchString += "|" + + $.map(searchString.split(''), function(e) { return RegExp.escape(e); }). + join('.+?'); + } + return regexSearchString; +} + +function highlight() { + $('#full_list li:visible').each(function(n) { + $(this).removeClass('even odd').addClass(n % 2 == 0 ? 'odd' : 'even'); + }); +} + +/** + * Expands the tree to the target element and its immediate + * children. + */ +function expandTo(path) { + var $target = $(document.getElementById('object_' + path)); + $target.addClass('clicked'); + $target.removeClass('collapsed'); + $target.parentsUntil('#full_list', 'li').removeClass('collapsed'); + + $target.find('a.toggle').attr('aria-expanded', 'true') + $target.parentsUntil('#full_list', 'li').each(function(i, el) { + $(el).find('> div > a.toggle').attr('aria-expanded', 'true'); + }); + + if($target[0]) { + window.scrollTo(window.scrollX, $target.offset().top - 250); + highlight(); + } +} + +function windowEvents(event) { + var msg = event.data; + if (msg.action === "expand") { + expandTo(msg.path); + } + return false; +} + +window.addEventListener("message", windowEvents, false); + +$(document).ready(function() { + escapeShortcut(); + navResizer(); + enableLinks(); + enableToggles(); + populateSearchCache(); + enableSearch(); +}); + +})(); diff --git a/js/jquery.js b/js/jquery.js new file mode 100644 index 00000000..198b3ff0 --- /dev/null +++ b/js/jquery.js @@ -0,0 +1,4 @@ +/*! jQuery v1.7.1 jquery.com | jquery.org/license */ +(function(a,b){function cy(a){return f.isWindow(a)?a:a.nodeType===9?a.defaultView||a.parentWindow:!1}function cv(a){if(!ck[a]){var b=c.body,d=f("<"+a+">").appendTo(b),e=d.css("display");d.remove();if(e==="none"||e===""){cl||(cl=c.createElement("iframe"),cl.frameBorder=cl.width=cl.height=0),b.appendChild(cl);if(!cm||!cl.createElement)cm=(cl.contentWindow||cl.contentDocument).document,cm.write((c.compatMode==="CSS1Compat"?"<!doctype html>":"")+"<html><body>"),cm.close();d=cm.createElement(a),cm.body.appendChild(d),e=f.css(d,"display"),b.removeChild(cl)}ck[a]=e}return ck[a]}function cu(a,b){var c={};f.each(cq.concat.apply([],cq.slice(0,b)),function(){c[this]=a});return c}function ct(){cr=b}function cs(){setTimeout(ct,0);return cr=f.now()}function cj(){try{return new a.ActiveXObject("Microsoft.XMLHTTP")}catch(b){}}function ci(){try{return new a.XMLHttpRequest}catch(b){}}function cc(a,c){a.dataFilter&&(c=a.dataFilter(c,a.dataType));var d=a.dataTypes,e={},g,h,i=d.length,j,k=d[0],l,m,n,o,p;for(g=1;g<i;g++){if(g===1)for(h in a.converters)typeof h=="string"&&(e[h.toLowerCase()]=a.converters[h]);l=k,k=d[g];if(k==="*")k=l;else if(l!=="*"&&l!==k){m=l+" "+k,n=e[m]||e["* "+k];if(!n){p=b;for(o in e){j=o.split(" ");if(j[0]===l||j[0]==="*"){p=e[j[1]+" "+k];if(p){o=e[o],o===!0?n=p:p===!0&&(n=o);break}}}}!n&&!p&&f.error("No conversion from "+m.replace(" "," to ")),n!==!0&&(c=n?n(c):p(o(c)))}}return c}function cb(a,c,d){var e=a.contents,f=a.dataTypes,g=a.responseFields,h,i,j,k;for(i in g)i in d&&(c[g[i]]=d[i]);while(f[0]==="*")f.shift(),h===b&&(h=a.mimeType||c.getResponseHeader("content-type"));if(h)for(i in e)if(e[i]&&e[i].test(h)){f.unshift(i);break}if(f[0]in d)j=f[0];else{for(i in d){if(!f[0]||a.converters[i+" "+f[0]]){j=i;break}k||(k=i)}j=j||k}if(j){j!==f[0]&&f.unshift(j);return d[j]}}function ca(a,b,c,d){if(f.isArray(b))f.each(b,function(b,e){c||bE.test(a)?d(a,e):ca(a+"["+(typeof e=="object"||f.isArray(e)?b:"")+"]",e,c,d)});else if(!c&&b!=null&&typeof b=="object")for(var e in b)ca(a+"["+e+"]",b[e],c,d);else d(a,b)}function b_(a,c){var d,e,g=f.ajaxSettings.flatOptions||{};for(d in c)c[d]!==b&&((g[d]?a:e||(e={}))[d]=c[d]);e&&f.extend(!0,a,e)}function b$(a,c,d,e,f,g){f=f||c.dataTypes[0],g=g||{},g[f]=!0;var h=a[f],i=0,j=h?h.length:0,k=a===bT,l;for(;i<j&&(k||!l);i++)l=h[i](c,d,e),typeof l=="string"&&(!k||g[l]?l=b:(c.dataTypes.unshift(l),l=b$(a,c,d,e,l,g)));(k||!l)&&!g["*"]&&(l=b$(a,c,d,e,"*",g));return l}function bZ(a){return function(b,c){typeof b!="string"&&(c=b,b="*");if(f.isFunction(c)){var d=b.toLowerCase().split(bP),e=0,g=d.length,h,i,j;for(;e<g;e++)h=d[e],j=/^\+/.test(h),j&&(h=h.substr(1)||"*"),i=a[h]=a[h]||[],i[j?"unshift":"push"](c)}}}function bC(a,b,c){var d=b==="width"?a.offsetWidth:a.offsetHeight,e=b==="width"?bx:by,g=0,h=e.length;if(d>0){if(c!=="border")for(;g<h;g++)c||(d-=parseFloat(f.css(a,"padding"+e[g]))||0),c==="margin"?d+=parseFloat(f.css(a,c+e[g]))||0:d-=parseFloat(f.css(a,"border"+e[g]+"Width"))||0;return d+"px"}d=bz(a,b,b);if(d<0||d==null)d=a.style[b]||0;d=parseFloat(d)||0;if(c)for(;g<h;g++)d+=parseFloat(f.css(a,"padding"+e[g]))||0,c!=="padding"&&(d+=parseFloat(f.css(a,"border"+e[g]+"Width"))||0),c==="margin"&&(d+=parseFloat(f.css(a,c+e[g]))||0);return d+"px"}function bp(a,b){b.src?f.ajax({url:b.src,async:!1,dataType:"script"}):f.globalEval((b.text||b.textContent||b.innerHTML||"").replace(bf,"/*$0*/")),b.parentNode&&b.parentNode.removeChild(b)}function bo(a){var b=c.createElement("div");bh.appendChild(b),b.innerHTML=a.outerHTML;return b.firstChild}function bn(a){var b=(a.nodeName||"").toLowerCase();b==="input"?bm(a):b!=="script"&&typeof a.getElementsByTagName!="undefined"&&f.grep(a.getElementsByTagName("input"),bm)}function bm(a){if(a.type==="checkbox"||a.type==="radio")a.defaultChecked=a.checked}function bl(a){return typeof a.getElementsByTagName!="undefined"?a.getElementsByTagName("*"):typeof a.querySelectorAll!="undefined"?a.querySelectorAll("*"):[]}function bk(a,b){var c;if(b.nodeType===1){b.clearAttributes&&b.clearAttributes(),b.mergeAttributes&&b.mergeAttributes(a),c=b.nodeName.toLowerCase();if(c==="object")b.outerHTML=a.outerHTML;else if(c!=="input"||a.type!=="checkbox"&&a.type!=="radio"){if(c==="option")b.selected=a.defaultSelected;else if(c==="input"||c==="textarea")b.defaultValue=a.defaultValue}else a.checked&&(b.defaultChecked=b.checked=a.checked),b.value!==a.value&&(b.value=a.value);b.removeAttribute(f.expando)}}function bj(a,b){if(b.nodeType===1&&!!f.hasData(a)){var c,d,e,g=f._data(a),h=f._data(b,g),i=g.events;if(i){delete h.handle,h.events={};for(c in i)for(d=0,e=i[c].length;d<e;d++)f.event.add(b,c+(i[c][d].namespace?".":"")+i[c][d].namespace,i[c][d],i[c][d].data)}h.data&&(h.data=f.extend({},h.data))}}function bi(a,b){return f.nodeName(a,"table")?a.getElementsByTagName("tbody")[0]||a.appendChild(a.ownerDocument.createElement("tbody")):a}function U(a){var b=V.split("|"),c=a.createDocumentFragment();if(c.createElement)while(b.length)c.createElement(b.pop());return c}function T(a,b,c){b=b||0;if(f.isFunction(b))return f.grep(a,function(a,d){var e=!!b.call(a,d,a);return e===c});if(b.nodeType)return f.grep(a,function(a,d){return a===b===c});if(typeof b=="string"){var d=f.grep(a,function(a){return a.nodeType===1});if(O.test(b))return f.filter(b,d,!c);b=f.filter(b,d)}return f.grep(a,function(a,d){return f.inArray(a,b)>=0===c})}function S(a){return!a||!a.parentNode||a.parentNode.nodeType===11}function K(){return!0}function J(){return!1}function n(a,b,c){var d=b+"defer",e=b+"queue",g=b+"mark",h=f._data(a,d);h&&(c==="queue"||!f._data(a,e))&&(c==="mark"||!f._data(a,g))&&setTimeout(function(){!f._data(a,e)&&!f._data(a,g)&&(f.removeData(a,d,!0),h.fire())},0)}function m(a){for(var b in a){if(b==="data"&&f.isEmptyObject(a[b]))continue;if(b!=="toJSON")return!1}return!0}function l(a,c,d){if(d===b&&a.nodeType===1){var e="data-"+c.replace(k,"-$1").toLowerCase();d=a.getAttribute(e);if(typeof d=="string"){try{d=d==="true"?!0:d==="false"?!1:d==="null"?null:f.isNumeric(d)?parseFloat(d):j.test(d)?f.parseJSON(d):d}catch(g){}f.data(a,c,d)}else d=b}return d}function h(a){var b=g[a]={},c,d;a=a.split(/\s+/);for(c=0,d=a.length;c<d;c++)b[a[c]]=!0;return b}var c=a.document,d=a.navigator,e=a.location,f=function(){function J(){if(!e.isReady){try{c.documentElement.doScroll("left")}catch(a){setTimeout(J,1);return}e.ready()}}var e=function(a,b){return new e.fn.init(a,b,h)},f=a.jQuery,g=a.$,h,i=/^(?:[^#<]*(<[\w\W]+>)[^>]*$|#([\w\-]*)$)/,j=/\S/,k=/^\s+/,l=/\s+$/,m=/^<(\w+)\s*\/?>(?:<\/\1>)?$/,n=/^[\],:{}\s]*$/,o=/\\(?:["\\\/bfnrt]|u[0-9a-fA-F]{4})/g,p=/"[^"\\\n\r]*"|true|false|null|-?\d+(?:\.\d*)?(?:[eE][+\-]?\d+)?/g,q=/(?:^|:|,)(?:\s*\[)+/g,r=/(webkit)[ \/]([\w.]+)/,s=/(opera)(?:.*version)?[ \/]([\w.]+)/,t=/(msie) ([\w.]+)/,u=/(mozilla)(?:.*? rv:([\w.]+))?/,v=/-([a-z]|[0-9])/ig,w=/^-ms-/,x=function(a,b){return(b+"").toUpperCase()},y=d.userAgent,z,A,B,C=Object.prototype.toString,D=Object.prototype.hasOwnProperty,E=Array.prototype.push,F=Array.prototype.slice,G=String.prototype.trim,H=Array.prototype.indexOf,I={};e.fn=e.prototype={constructor:e,init:function(a,d,f){var g,h,j,k;if(!a)return this;if(a.nodeType){this.context=this[0]=a,this.length=1;return this}if(a==="body"&&!d&&c.body){this.context=c,this[0]=c.body,this.selector=a,this.length=1;return this}if(typeof a=="string"){a.charAt(0)!=="<"||a.charAt(a.length-1)!==">"||a.length<3?g=i.exec(a):g=[null,a,null];if(g&&(g[1]||!d)){if(g[1]){d=d instanceof e?d[0]:d,k=d?d.ownerDocument||d:c,j=m.exec(a),j?e.isPlainObject(d)?(a=[c.createElement(j[1])],e.fn.attr.call(a,d,!0)):a=[k.createElement(j[1])]:(j=e.buildFragment([g[1]],[k]),a=(j.cacheable?e.clone(j.fragment):j.fragment).childNodes);return e.merge(this,a)}h=c.getElementById(g[2]);if(h&&h.parentNode){if(h.id!==g[2])return f.find(a);this.length=1,this[0]=h}this.context=c,this.selector=a;return this}return!d||d.jquery?(d||f).find(a):this.constructor(d).find(a)}if(e.isFunction(a))return f.ready(a);a.selector!==b&&(this.selector=a.selector,this.context=a.context);return e.makeArray(a,this)},selector:"",jquery:"1.7.1",length:0,size:function(){return this.length},toArray:function(){return F.call(this,0)},get:function(a){return a==null?this.toArray():a<0?this[this.length+a]:this[a]},pushStack:function(a,b,c){var d=this.constructor();e.isArray(a)?E.apply(d,a):e.merge(d,a),d.prevObject=this,d.context=this.context,b==="find"?d.selector=this.selector+(this.selector?" ":"")+c:b&&(d.selector=this.selector+"."+b+"("+c+")");return d},each:function(a,b){return e.each(this,a,b)},ready:function(a){e.bindReady(),A.add(a);return this},eq:function(a){a=+a;return a===-1?this.slice(a):this.slice(a,a+1)},first:function(){return this.eq(0)},last:function(){return this.eq(-1)},slice:function(){return this.pushStack(F.apply(this,arguments),"slice",F.call(arguments).join(","))},map:function(a){return this.pushStack(e.map(this,function(b,c){return a.call(b,c,b)}))},end:function(){return this.prevObject||this.constructor(null)},push:E,sort:[].sort,splice:[].splice},e.fn.init.prototype=e.fn,e.extend=e.fn.extend=function(){var a,c,d,f,g,h,i=arguments[0]||{},j=1,k=arguments.length,l=!1;typeof i=="boolean"&&(l=i,i=arguments[1]||{},j=2),typeof i!="object"&&!e.isFunction(i)&&(i={}),k===j&&(i=this,--j);for(;j<k;j++)if((a=arguments[j])!=null)for(c in a){d=i[c],f=a[c];if(i===f)continue;l&&f&&(e.isPlainObject(f)||(g=e.isArray(f)))?(g?(g=!1,h=d&&e.isArray(d)?d:[]):h=d&&e.isPlainObject(d)?d:{},i[c]=e.extend(l,h,f)):f!==b&&(i[c]=f)}return i},e.extend({noConflict:function(b){a.$===e&&(a.$=g),b&&a.jQuery===e&&(a.jQuery=f);return e},isReady:!1,readyWait:1,holdReady:function(a){a?e.readyWait++:e.ready(!0)},ready:function(a){if(a===!0&&!--e.readyWait||a!==!0&&!e.isReady){if(!c.body)return setTimeout(e.ready,1);e.isReady=!0;if(a!==!0&&--e.readyWait>0)return;A.fireWith(c,[e]),e.fn.trigger&&e(c).trigger("ready").off("ready")}},bindReady:function(){if(!A){A=e.Callbacks("once memory");if(c.readyState==="complete")return setTimeout(e.ready,1);if(c.addEventListener)c.addEventListener("DOMContentLoaded",B,!1),a.addEventListener("load",e.ready,!1);else if(c.attachEvent){c.attachEvent("onreadystatechange",B),a.attachEvent("onload",e.ready);var b=!1;try{b=a.frameElement==null}catch(d){}c.documentElement.doScroll&&b&&J()}}},isFunction:function(a){return e.type(a)==="function"},isArray:Array.isArray||function(a){return e.type(a)==="array"},isWindow:function(a){return a&&typeof a=="object"&&"setInterval"in a},isNumeric:function(a){return!isNaN(parseFloat(a))&&isFinite(a)},type:function(a){return a==null?String(a):I[C.call(a)]||"object"},isPlainObject:function(a){if(!a||e.type(a)!=="object"||a.nodeType||e.isWindow(a))return!1;try{if(a.constructor&&!D.call(a,"constructor")&&!D.call(a.constructor.prototype,"isPrototypeOf"))return!1}catch(c){return!1}var d;for(d in a);return d===b||D.call(a,d)},isEmptyObject:function(a){for(var b in a)return!1;return!0},error:function(a){throw new Error(a)},parseJSON:function(b){if(typeof b!="string"||!b)return null;b=e.trim(b);if(a.JSON&&a.JSON.parse)return a.JSON.parse(b);if(n.test(b.replace(o,"@").replace(p,"]").replace(q,"")))return(new Function("return "+b))();e.error("Invalid JSON: "+b)},parseXML:function(c){var d,f;try{a.DOMParser?(f=new DOMParser,d=f.parseFromString(c,"text/xml")):(d=new ActiveXObject("Microsoft.XMLDOM"),d.async="false",d.loadXML(c))}catch(g){d=b}(!d||!d.documentElement||d.getElementsByTagName("parsererror").length)&&e.error("Invalid XML: "+c);return d},noop:function(){},globalEval:function(b){b&&j.test(b)&&(a.execScript||function(b){a.eval.call(a,b)})(b)},camelCase:function(a){return a.replace(w,"ms-").replace(v,x)},nodeName:function(a,b){return a.nodeName&&a.nodeName.toUpperCase()===b.toUpperCase()},each:function(a,c,d){var f,g=0,h=a.length,i=h===b||e.isFunction(a);if(d){if(i){for(f in a)if(c.apply(a[f],d)===!1)break}else for(;g<h;)if(c.apply(a[g++],d)===!1)break}else if(i){for(f in a)if(c.call(a[f],f,a[f])===!1)break}else for(;g<h;)if(c.call(a[g],g,a[g++])===!1)break;return a},trim:G?function(a){return a==null?"":G.call(a)}:function(a){return a==null?"":(a+"").replace(k,"").replace(l,"")},makeArray:function(a,b){var c=b||[];if(a!=null){var d=e.type(a);a.length==null||d==="string"||d==="function"||d==="regexp"||e.isWindow(a)?E.call(c,a):e.merge(c,a)}return c},inArray:function(a,b,c){var d;if(b){if(H)return H.call(b,a,c);d=b.length,c=c?c<0?Math.max(0,d+c):c:0;for(;c<d;c++)if(c in b&&b[c]===a)return c}return-1},merge:function(a,c){var d=a.length,e=0;if(typeof c.length=="number")for(var f=c.length;e<f;e++)a[d++]=c[e];else while(c[e]!==b)a[d++]=c[e++];a.length=d;return a},grep:function(a,b,c){var d=[],e;c=!!c;for(var f=0,g=a.length;f<g;f++)e=!!b(a[f],f),c!==e&&d.push(a[f]);return d},map:function(a,c,d){var f,g,h=[],i=0,j=a.length,k=a instanceof e||j!==b&&typeof j=="number"&&(j>0&&a[0]&&a[j-1]||j===0||e.isArray(a));if(k)for(;i<j;i++)f=c(a[i],i,d),f!=null&&(h[h.length]=f);else for(g in a)f=c(a[g],g,d),f!=null&&(h[h.length]=f);return h.concat.apply([],h)},guid:1,proxy:function(a,c){if(typeof c=="string"){var d=a[c];c=a,a=d}if(!e.isFunction(a))return b;var f=F.call(arguments,2),g=function(){return a.apply(c,f.concat(F.call(arguments)))};g.guid=a.guid=a.guid||g.guid||e.guid++;return g},access:function(a,c,d,f,g,h){var i=a.length;if(typeof c=="object"){for(var j in c)e.access(a,j,c[j],f,g,d);return a}if(d!==b){f=!h&&f&&e.isFunction(d);for(var k=0;k<i;k++)g(a[k],c,f?d.call(a[k],k,g(a[k],c)):d,h);return a}return i?g(a[0],c):b},now:function(){return(new Date).getTime()},uaMatch:function(a){a=a.toLowerCase();var b=r.exec(a)||s.exec(a)||t.exec(a)||a.indexOf("compatible")<0&&u.exec(a)||[];return{browser:b[1]||"",version:b[2]||"0"}},sub:function(){function a(b,c){return new a.fn.init(b,c)}e.extend(!0,a,this),a.superclass=this,a.fn=a.prototype=this(),a.fn.constructor=a,a.sub=this.sub,a.fn.init=function(d,f){f&&f instanceof e&&!(f instanceof a)&&(f=a(f));return e.fn.init.call(this,d,f,b)},a.fn.init.prototype=a.fn;var b=a(c);return a},browser:{}}),e.each("Boolean Number String Function Array Date RegExp Object".split(" "),function(a,b){I["[object "+b+"]"]=b.toLowerCase()}),z=e.uaMatch(y),z.browser&&(e.browser[z.browser]=!0,e.browser.version=z.version),e.browser.webkit&&(e.browser.safari=!0),j.test(" ")&&(k=/^[\s\xA0]+/,l=/[\s\xA0]+$/),h=e(c),c.addEventListener?B=function(){c.removeEventListener("DOMContentLoaded",B,!1),e.ready()}:c.attachEvent&&(B=function(){c.readyState==="complete"&&(c.detachEvent("onreadystatechange",B),e.ready())});return e}(),g={};f.Callbacks=function(a){a=a?g[a]||h(a):{};var c=[],d=[],e,i,j,k,l,m=function(b){var d,e,g,h,i;for(d=0,e=b.length;d<e;d++)g=b[d],h=f.type(g),h==="array"?m(g):h==="function"&&(!a.unique||!o.has(g))&&c.push(g)},n=function(b,f){f=f||[],e=!a.memory||[b,f],i=!0,l=j||0,j=0,k=c.length;for(;c&&l<k;l++)if(c[l].apply(b,f)===!1&&a.stopOnFalse){e=!0;break}i=!1,c&&(a.once?e===!0?o.disable():c=[]:d&&d.length&&(e=d.shift(),o.fireWith(e[0],e[1])))},o={add:function(){if(c){var a=c.length;m(arguments),i?k=c.length:e&&e!==!0&&(j=a,n(e[0],e[1]))}return this},remove:function(){if(c){var b=arguments,d=0,e=b.length;for(;d<e;d++)for(var f=0;f<c.length;f++)if(b[d]===c[f]){i&&f<=k&&(k--,f<=l&&l--),c.splice(f--,1);if(a.unique)break}}return this},has:function(a){if(c){var b=0,d=c.length;for(;b<d;b++)if(a===c[b])return!0}return!1},empty:function(){c=[];return this},disable:function(){c=d=e=b;return this},disabled:function(){return!c},lock:function(){d=b,(!e||e===!0)&&o.disable();return this},locked:function(){return!d},fireWith:function(b,c){d&&(i?a.once||d.push([b,c]):(!a.once||!e)&&n(b,c));return this},fire:function(){o.fireWith(this,arguments);return this},fired:function(){return!!e}};return o};var i=[].slice;f.extend({Deferred:function(a){var b=f.Callbacks("once memory"),c=f.Callbacks("once memory"),d=f.Callbacks("memory"),e="pending",g={resolve:b,reject:c,notify:d},h={done:b.add,fail:c.add,progress:d.add,state:function(){return e},isResolved:b.fired,isRejected:c.fired,then:function(a,b,c){i.done(a).fail(b).progress(c);return this},always:function(){i.done.apply(i,arguments).fail.apply(i,arguments);return this},pipe:function(a,b,c){return f.Deferred(function(d){f.each({done:[a,"resolve"],fail:[b,"reject"],progress:[c,"notify"]},function(a,b){var c=b[0],e=b[1],g;f.isFunction(c)?i[a](function(){g=c.apply(this,arguments),g&&f.isFunction(g.promise)?g.promise().then(d.resolve,d.reject,d.notify):d[e+"With"](this===i?d:this,[g])}):i[a](d[e])})}).promise()},promise:function(a){if(a==null)a=h;else for(var b in h)a[b]=h[b];return a}},i=h.promise({}),j;for(j in g)i[j]=g[j].fire,i[j+"With"]=g[j].fireWith;i.done(function(){e="resolved"},c.disable,d.lock).fail(function(){e="rejected"},b.disable,d.lock),a&&a.call(i,i);return i},when:function(a){function m(a){return function(b){e[a]=arguments.length>1?i.call(arguments,0):b,j.notifyWith(k,e)}}function l(a){return function(c){b[a]=arguments.length>1?i.call(arguments,0):c,--g||j.resolveWith(j,b)}}var b=i.call(arguments,0),c=0,d=b.length,e=Array(d),g=d,h=d,j=d<=1&&a&&f.isFunction(a.promise)?a:f.Deferred(),k=j.promise();if(d>1){for(;c<d;c++)b[c]&&b[c].promise&&f.isFunction(b[c].promise)?b[c].promise().then(l(c),j.reject,m(c)):--g;g||j.resolveWith(j,b)}else j!==a&&j.resolveWith(j,d?[a]:[]);return k}}),f.support=function(){var b,d,e,g,h,i,j,k,l,m,n,o,p,q=c.createElement("div"),r=c.documentElement;q.setAttribute("className","t"),q.innerHTML=" <link/><table></table><a href='/a' style='top:1px;float:left;opacity:.55;'>a</a><input type='checkbox'/>",d=q.getElementsByTagName("*"),e=q.getElementsByTagName("a")[0];if(!d||!d.length||!e)return{};g=c.createElement("select"),h=g.appendChild(c.createElement("option")),i=q.getElementsByTagName("input")[0],b={leadingWhitespace:q.firstChild.nodeType===3,tbody:!q.getElementsByTagName("tbody").length,htmlSerialize:!!q.getElementsByTagName("link").length,style:/top/.test(e.getAttribute("style")),hrefNormalized:e.getAttribute("href")==="/a",opacity:/^0.55/.test(e.style.opacity),cssFloat:!!e.style.cssFloat,checkOn:i.value==="on",optSelected:h.selected,getSetAttribute:q.className!=="t",enctype:!!c.createElement("form").enctype,html5Clone:c.createElement("nav").cloneNode(!0).outerHTML!=="<:nav></:nav>",submitBubbles:!0,changeBubbles:!0,focusinBubbles:!1,deleteExpando:!0,noCloneEvent:!0,inlineBlockNeedsLayout:!1,shrinkWrapBlocks:!1,reliableMarginRight:!0},i.checked=!0,b.noCloneChecked=i.cloneNode(!0).checked,g.disabled=!0,b.optDisabled=!h.disabled;try{delete q.test}catch(s){b.deleteExpando=!1}!q.addEventListener&&q.attachEvent&&q.fireEvent&&(q.attachEvent("onclick",function(){b.noCloneEvent=!1}),q.cloneNode(!0).fireEvent("onclick")),i=c.createElement("input"),i.value="t",i.setAttribute("type","radio"),b.radioValue=i.value==="t",i.setAttribute("checked","checked"),q.appendChild(i),k=c.createDocumentFragment(),k.appendChild(q.lastChild),b.checkClone=k.cloneNode(!0).cloneNode(!0).lastChild.checked,b.appendChecked=i.checked,k.removeChild(i),k.appendChild(q),q.innerHTML="",a.getComputedStyle&&(j=c.createElement("div"),j.style.width="0",j.style.marginRight="0",q.style.width="2px",q.appendChild(j),b.reliableMarginRight=(parseInt((a.getComputedStyle(j,null)||{marginRight:0}).marginRight,10)||0)===0);if(q.attachEvent)for(o in{submit:1,change:1,focusin:1})n="on"+o,p=n in q,p||(q.setAttribute(n,"return;"),p=typeof q[n]=="function"),b[o+"Bubbles"]=p;k.removeChild(q),k=g=h=j=q=i=null,f(function(){var a,d,e,g,h,i,j,k,m,n,o,r=c.getElementsByTagName("body")[0];!r||(j=1,k="position:absolute;top:0;left:0;width:1px;height:1px;margin:0;",m="visibility:hidden;border:0;",n="style='"+k+"border:5px solid #000;padding:0;'",o="<div "+n+"><div></div></div>"+"<table "+n+" cellpadding='0' cellspacing='0'>"+"<tr><td></td></tr></table>",a=c.createElement("div"),a.style.cssText=m+"width:0;height:0;position:static;top:0;margin-top:"+j+"px",r.insertBefore(a,r.firstChild),q=c.createElement("div"),a.appendChild(q),q.innerHTML="<table><tr><td style='padding:0;border:0;display:none'></td><td>t</td></tr></table>",l=q.getElementsByTagName("td"),p=l[0].offsetHeight===0,l[0].style.display="",l[1].style.display="none",b.reliableHiddenOffsets=p&&l[0].offsetHeight===0,q.innerHTML="",q.style.width=q.style.paddingLeft="1px",f.boxModel=b.boxModel=q.offsetWidth===2,typeof q.style.zoom!="undefined"&&(q.style.display="inline",q.style.zoom=1,b.inlineBlockNeedsLayout=q.offsetWidth===2,q.style.display="",q.innerHTML="<div style='width:4px;'></div>",b.shrinkWrapBlocks=q.offsetWidth!==2),q.style.cssText=k+m,q.innerHTML=o,d=q.firstChild,e=d.firstChild,h=d.nextSibling.firstChild.firstChild,i={doesNotAddBorder:e.offsetTop!==5,doesAddBorderForTableAndCells:h.offsetTop===5},e.style.position="fixed",e.style.top="20px",i.fixedPosition=e.offsetTop===20||e.offsetTop===15,e.style.position=e.style.top="",d.style.overflow="hidden",d.style.position="relative",i.subtractsBorderForOverflowNotVisible=e.offsetTop===-5,i.doesNotIncludeMarginInBodyOffset=r.offsetTop!==j,r.removeChild(a),q=a=null,f.extend(b,i))});return b}();var j=/^(?:\{.*\}|\[.*\])$/,k=/([A-Z])/g;f.extend({cache:{},uuid:0,expando:"jQuery"+(f.fn.jquery+Math.random()).replace(/\D/g,""),noData:{embed:!0,object:"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000",applet:!0},hasData:function(a){a=a.nodeType?f.cache[a[f.expando]]:a[f.expando];return!!a&&!m(a)},data:function(a,c,d,e){if(!!f.acceptData(a)){var g,h,i,j=f.expando,k=typeof c=="string",l=a.nodeType,m=l?f.cache:a,n=l?a[j]:a[j]&&j,o=c==="events";if((!n||!m[n]||!o&&!e&&!m[n].data)&&k&&d===b)return;n||(l?a[j]=n=++f.uuid:n=j),m[n]||(m[n]={},l||(m[n].toJSON=f.noop));if(typeof c=="object"||typeof c=="function")e?m[n]=f.extend(m[n],c):m[n].data=f.extend(m[n].data,c);g=h=m[n],e||(h.data||(h.data={}),h=h.data),d!==b&&(h[f.camelCase(c)]=d);if(o&&!h[c])return g.events;k?(i=h[c],i==null&&(i=h[f.camelCase(c)])):i=h;return i}},removeData:function(a,b,c){if(!!f.acceptData(a)){var d,e,g,h=f.expando,i=a.nodeType,j=i?f.cache:a,k=i?a[h]:h;if(!j[k])return;if(b){d=c?j[k]:j[k].data;if(d){f.isArray(b)||(b in d?b=[b]:(b=f.camelCase(b),b in d?b=[b]:b=b.split(" ")));for(e=0,g=b.length;e<g;e++)delete d[b[e]];if(!(c?m:f.isEmptyObject)(d))return}}if(!c){delete j[k].data;if(!m(j[k]))return}f.support.deleteExpando||!j.setInterval?delete j[k]:j[k]=null,i&&(f.support.deleteExpando?delete a[h]:a.removeAttribute?a.removeAttribute(h):a[h]=null)}},_data:function(a,b,c){return f.data(a,b,c,!0)},acceptData:function(a){if(a.nodeName){var b=f.noData[a.nodeName.toLowerCase()];if(b)return b!==!0&&a.getAttribute("classid")===b}return!0}}),f.fn.extend({data:function(a,c){var d,e,g,h=null;if(typeof a=="undefined"){if(this.length){h=f.data(this[0]);if(this[0].nodeType===1&&!f._data(this[0],"parsedAttrs")){e=this[0].attributes;for(var i=0,j=e.length;i<j;i++)g=e[i].name,g.indexOf("data-")===0&&(g=f.camelCase(g.substring(5)),l(this[0],g,h[g]));f._data(this[0],"parsedAttrs",!0)}}return h}if(typeof a=="object")return this.each(function(){f.data(this,a)});d=a.split("."),d[1]=d[1]?"."+d[1]:"";if(c===b){h=this.triggerHandler("getData"+d[1]+"!",[d[0]]),h===b&&this.length&&(h=f.data(this[0],a),h=l(this[0],a,h));return h===b&&d[1]?this.data(d[0]):h}return this.each(function(){var b=f(this),e=[d[0],c];b.triggerHandler("setData"+d[1]+"!",e),f.data(this,a,c),b.triggerHandler("changeData"+d[1]+"!",e)})},removeData:function(a){return this.each(function(){f.removeData(this,a)})}}),f.extend({_mark:function(a,b){a&&(b=(b||"fx")+"mark",f._data(a,b,(f._data(a,b)||0)+1))},_unmark:function(a,b,c){a!==!0&&(c=b,b=a,a=!1);if(b){c=c||"fx";var d=c+"mark",e=a?0:(f._data(b,d)||1)-1;e?f._data(b,d,e):(f.removeData(b,d,!0),n(b,c,"mark"))}},queue:function(a,b,c){var d;if(a){b=(b||"fx")+"queue",d=f._data(a,b),c&&(!d||f.isArray(c)?d=f._data(a,b,f.makeArray(c)):d.push(c));return d||[]}},dequeue:function(a,b){b=b||"fx";var c=f.queue(a,b),d=c.shift(),e={};d==="inprogress"&&(d=c.shift()),d&&(b==="fx"&&c.unshift("inprogress"),f._data(a,b+".run",e),d.call(a,function(){f.dequeue(a,b)},e)),c.length||(f.removeData(a,b+"queue "+b+".run",!0),n(a,b,"queue"))}}),f.fn.extend({queue:function(a,c){typeof a!="string"&&(c=a,a="fx");if(c===b)return f.queue(this[0],a);return this.each(function(){var b=f.queue(this,a,c);a==="fx"&&b[0]!=="inprogress"&&f.dequeue(this,a)})},dequeue:function(a){return this.each(function(){f.dequeue(this,a)})},delay:function(a,b){a=f.fx?f.fx.speeds[a]||a:a,b=b||"fx";return this.queue(b,function(b,c){var d=setTimeout(b,a);c.stop=function(){clearTimeout(d)}})},clearQueue:function(a){return this.queue(a||"fx",[])},promise:function(a,c){function m(){--h||d.resolveWith(e,[e])}typeof a!="string"&&(c=a,a=b),a=a||"fx";var d=f.Deferred(),e=this,g=e.length,h=1,i=a+"defer",j=a+"queue",k=a+"mark",l;while(g--)if(l=f.data(e[g],i,b,!0)||(f.data(e[g],j,b,!0)||f.data(e[g],k,b,!0))&&f.data(e[g],i,f.Callbacks("once memory"),!0))h++,l.add(m);m();return d.promise()}});var o=/[\n\t\r]/g,p=/\s+/,q=/\r/g,r=/^(?:button|input)$/i,s=/^(?:button|input|object|select|textarea)$/i,t=/^a(?:rea)?$/i,u=/^(?:autofocus|autoplay|async|checked|controls|defer|disabled|hidden|loop|multiple|open|readonly|required|scoped|selected)$/i,v=f.support.getSetAttribute,w,x,y;f.fn.extend({attr:function(a,b){return f.access(this,a,b,!0,f.attr)},removeAttr:function(a){return this.each(function(){f.removeAttr(this,a)})},prop:function(a,b){return f.access(this,a,b,!0,f.prop)},removeProp:function(a){a=f.propFix[a]||a;return this.each(function(){try{this[a]=b,delete this[a]}catch(c){}})},addClass:function(a){var b,c,d,e,g,h,i;if(f.isFunction(a))return this.each(function(b){f(this).addClass(a.call(this,b,this.className))});if(a&&typeof a=="string"){b=a.split(p);for(c=0,d=this.length;c<d;c++){e=this[c];if(e.nodeType===1)if(!e.className&&b.length===1)e.className=a;else{g=" "+e.className+" ";for(h=0,i=b.length;h<i;h++)~g.indexOf(" "+b[h]+" ")||(g+=b[h]+" ");e.className=f.trim(g)}}}return this},removeClass:function(a){var c,d,e,g,h,i,j;if(f.isFunction(a))return this.each(function(b){f(this).removeClass(a.call(this,b,this.className))});if(a&&typeof a=="string"||a===b){c=(a||"").split(p);for(d=0,e=this.length;d<e;d++){g=this[d];if(g.nodeType===1&&g.className)if(a){h=(" "+g.className+" ").replace(o," ");for(i=0,j=c.length;i<j;i++)h=h.replace(" "+c[i]+" "," ");g.className=f.trim(h)}else g.className=""}}return this},toggleClass:function(a,b){var c=typeof a,d=typeof b=="boolean";if(f.isFunction(a))return this.each(function(c){f(this).toggleClass(a.call(this,c,this.className,b),b)});return this.each(function(){if(c==="string"){var e,g=0,h=f(this),i=b,j=a.split(p);while(e=j[g++])i=d?i:!h.hasClass(e),h[i?"addClass":"removeClass"](e)}else if(c==="undefined"||c==="boolean")this.className&&f._data(this,"__className__",this.className),this.className=this.className||a===!1?"":f._data(this,"__className__")||""})},hasClass:function(a){var b=" "+a+" ",c=0,d=this.length;for(;c<d;c++)if(this[c].nodeType===1&&(" "+this[c].className+" ").replace(o," ").indexOf(b)>-1)return!0;return!1},val:function(a){var c,d,e,g=this[0];{if(!!arguments.length){e=f.isFunction(a);return this.each(function(d){var g=f(this),h;if(this.nodeType===1){e?h=a.call(this,d,g.val()):h=a,h==null?h="":typeof h=="number"?h+="":f.isArray(h)&&(h=f.map(h,function(a){return a==null?"":a+""})),c=f.valHooks[this.nodeName.toLowerCase()]||f.valHooks[this.type];if(!c||!("set"in c)||c.set(this,h,"value")===b)this.value=h}})}if(g){c=f.valHooks[g.nodeName.toLowerCase()]||f.valHooks[g.type];if(c&&"get"in c&&(d=c.get(g,"value"))!==b)return d;d=g.value;return typeof d=="string"?d.replace(q,""):d==null?"":d}}}}),f.extend({valHooks:{option:{get:function(a){var b=a.attributes.value;return!b||b.specified?a.value:a.text}},select:{get:function(a){var b,c,d,e,g=a.selectedIndex,h=[],i=a.options,j=a.type==="select-one";if(g<0)return null;c=j?g:0,d=j?g+1:i.length;for(;c<d;c++){e=i[c];if(e.selected&&(f.support.optDisabled?!e.disabled:e.getAttribute("disabled")===null)&&(!e.parentNode.disabled||!f.nodeName(e.parentNode,"optgroup"))){b=f(e).val();if(j)return b;h.push(b)}}if(j&&!h.length&&i.length)return f(i[g]).val();return h},set:function(a,b){var c=f.makeArray(b);f(a).find("option").each(function(){this.selected=f.inArray(f(this).val(),c)>=0}),c.length||(a.selectedIndex=-1);return c}}},attrFn:{val:!0,css:!0,html:!0,text:!0,data:!0,width:!0,height:!0,offset:!0},attr:function(a,c,d,e){var g,h,i,j=a.nodeType;if(!!a&&j!==3&&j!==8&&j!==2){if(e&&c in f.attrFn)return f(a)[c](d);if(typeof a.getAttribute=="undefined")return f.prop(a,c,d);i=j!==1||!f.isXMLDoc(a),i&&(c=c.toLowerCase(),h=f.attrHooks[c]||(u.test(c)?x:w));if(d!==b){if(d===null){f.removeAttr(a,c);return}if(h&&"set"in h&&i&&(g=h.set(a,d,c))!==b)return g;a.setAttribute(c,""+d);return d}if(h&&"get"in h&&i&&(g=h.get(a,c))!==null)return g;g=a.getAttribute(c);return g===null?b:g}},removeAttr:function(a,b){var c,d,e,g,h=0;if(b&&a.nodeType===1){d=b.toLowerCase().split(p),g=d.length;for(;h<g;h++)e=d[h],e&&(c=f.propFix[e]||e,f.attr(a,e,""),a.removeAttribute(v?e:c),u.test(e)&&c in a&&(a[c]=!1))}},attrHooks:{type:{set:function(a,b){if(r.test(a.nodeName)&&a.parentNode)f.error("type property can't be changed");else if(!f.support.radioValue&&b==="radio"&&f.nodeName(a,"input")){var c=a.value;a.setAttribute("type",b),c&&(a.value=c);return b}}},value:{get:function(a,b){if(w&&f.nodeName(a,"button"))return w.get(a,b);return b in a?a.value:null},set:function(a,b,c){if(w&&f.nodeName(a,"button"))return w.set(a,b,c);a.value=b}}},propFix:{tabindex:"tabIndex",readonly:"readOnly","for":"htmlFor","class":"className",maxlength:"maxLength",cellspacing:"cellSpacing",cellpadding:"cellPadding",rowspan:"rowSpan",colspan:"colSpan",usemap:"useMap",frameborder:"frameBorder",contenteditable:"contentEditable"},prop:function(a,c,d){var e,g,h,i=a.nodeType;if(!!a&&i!==3&&i!==8&&i!==2){h=i!==1||!f.isXMLDoc(a),h&&(c=f.propFix[c]||c,g=f.propHooks[c]);return d!==b?g&&"set"in g&&(e=g.set(a,d,c))!==b?e:a[c]=d:g&&"get"in g&&(e=g.get(a,c))!==null?e:a[c]}},propHooks:{tabIndex:{get:function(a){var c=a.getAttributeNode("tabindex");return c&&c.specified?parseInt(c.value,10):s.test(a.nodeName)||t.test(a.nodeName)&&a.href?0:b}}}}),f.attrHooks.tabindex=f.propHooks.tabIndex,x={get:function(a,c){var d,e=f.prop(a,c);return e===!0||typeof e!="boolean"&&(d=a.getAttributeNode(c))&&d.nodeValue!==!1?c.toLowerCase():b},set:function(a,b,c){var d;b===!1?f.removeAttr(a,c):(d=f.propFix[c]||c,d in a&&(a[d]=!0),a.setAttribute(c,c.toLowerCase()));return c}},v||(y={name:!0,id:!0},w=f.valHooks.button={get:function(a,c){var d;d=a.getAttributeNode(c);return d&&(y[c]?d.nodeValue!=="":d.specified)?d.nodeValue:b},set:function(a,b,d){var e=a.getAttributeNode(d);e||(e=c.createAttribute(d),a.setAttributeNode(e));return e.nodeValue=b+""}},f.attrHooks.tabindex.set=w.set,f.each(["width","height"],function(a,b){f.attrHooks[b]=f.extend(f.attrHooks[b],{set:function(a,c){if(c===""){a.setAttribute(b,"auto");return c}}})}),f.attrHooks.contenteditable={get:w.get,set:function(a,b,c){b===""&&(b="false"),w.set(a,b,c)}}),f.support.hrefNormalized||f.each(["href","src","width","height"],function(a,c){f.attrHooks[c]=f.extend(f.attrHooks[c],{get:function(a){var d=a.getAttribute(c,2);return d===null?b:d}})}),f.support.style||(f.attrHooks.style={get:function(a){return a.style.cssText.toLowerCase()||b},set:function(a,b){return a.style.cssText=""+b}}),f.support.optSelected||(f.propHooks.selected=f.extend(f.propHooks.selected,{get:function(a){var b=a.parentNode;b&&(b.selectedIndex,b.parentNode&&b.parentNode.selectedIndex);return null}})),f.support.enctype||(f.propFix.enctype="encoding"),f.support.checkOn||f.each(["radio","checkbox"],function(){f.valHooks[this]={get:function(a){return a.getAttribute("value")===null?"on":a.value}}}),f.each(["radio","checkbox"],function(){f.valHooks[this]=f.extend(f.valHooks[this],{set:function(a,b){if(f.isArray(b))return a.checked=f.inArray(f(a).val(),b)>=0}})});var z=/^(?:textarea|input|select)$/i,A=/^([^\.]*)?(?:\.(.+))?$/,B=/\bhover(\.\S+)?\b/,C=/^key/,D=/^(?:mouse|contextmenu)|click/,E=/^(?:focusinfocus|focusoutblur)$/,F=/^(\w*)(?:#([\w\-]+))?(?:\.([\w\-]+))?$/,G=function(a){var b=F.exec(a);b&&(b[1]=(b[1]||"").toLowerCase(),b[3]=b[3]&&new RegExp("(?:^|\\s)"+b[3]+"(?:\\s|$)"));return b},H=function(a,b){var c=a.attributes||{};return(!b[1]||a.nodeName.toLowerCase()===b[1])&&(!b[2]||(c.id||{}).value===b[2])&&(!b[3]||b[3].test((c["class"]||{}).value))},I=function(a){return f.event.special.hover?a:a.replace(B,"mouseenter$1 mouseleave$1")}; +f.event={add:function(a,c,d,e,g){var h,i,j,k,l,m,n,o,p,q,r,s;if(!(a.nodeType===3||a.nodeType===8||!c||!d||!(h=f._data(a)))){d.handler&&(p=d,d=p.handler),d.guid||(d.guid=f.guid++),j=h.events,j||(h.events=j={}),i=h.handle,i||(h.handle=i=function(a){return typeof f!="undefined"&&(!a||f.event.triggered!==a.type)?f.event.dispatch.apply(i.elem,arguments):b},i.elem=a),c=f.trim(I(c)).split(" ");for(k=0;k<c.length;k++){l=A.exec(c[k])||[],m=l[1],n=(l[2]||"").split(".").sort(),s=f.event.special[m]||{},m=(g?s.delegateType:s.bindType)||m,s=f.event.special[m]||{},o=f.extend({type:m,origType:l[1],data:e,handler:d,guid:d.guid,selector:g,quick:G(g),namespace:n.join(".")},p),r=j[m];if(!r){r=j[m]=[],r.delegateCount=0;if(!s.setup||s.setup.call(a,e,n,i)===!1)a.addEventListener?a.addEventListener(m,i,!1):a.attachEvent&&a.attachEvent("on"+m,i)}s.add&&(s.add.call(a,o),o.handler.guid||(o.handler.guid=d.guid)),g?r.splice(r.delegateCount++,0,o):r.push(o),f.event.global[m]=!0}a=null}},global:{},remove:function(a,b,c,d,e){var g=f.hasData(a)&&f._data(a),h,i,j,k,l,m,n,o,p,q,r,s;if(!!g&&!!(o=g.events)){b=f.trim(I(b||"")).split(" ");for(h=0;h<b.length;h++){i=A.exec(b[h])||[],j=k=i[1],l=i[2];if(!j){for(j in o)f.event.remove(a,j+b[h],c,d,!0);continue}p=f.event.special[j]||{},j=(d?p.delegateType:p.bindType)||j,r=o[j]||[],m=r.length,l=l?new RegExp("(^|\\.)"+l.split(".").sort().join("\\.(?:.*\\.)?")+"(\\.|$)"):null;for(n=0;n<r.length;n++)s=r[n],(e||k===s.origType)&&(!c||c.guid===s.guid)&&(!l||l.test(s.namespace))&&(!d||d===s.selector||d==="**"&&s.selector)&&(r.splice(n--,1),s.selector&&r.delegateCount--,p.remove&&p.remove.call(a,s));r.length===0&&m!==r.length&&((!p.teardown||p.teardown.call(a,l)===!1)&&f.removeEvent(a,j,g.handle),delete o[j])}f.isEmptyObject(o)&&(q=g.handle,q&&(q.elem=null),f.removeData(a,["events","handle"],!0))}},customEvent:{getData:!0,setData:!0,changeData:!0},trigger:function(c,d,e,g){if(!e||e.nodeType!==3&&e.nodeType!==8){var h=c.type||c,i=[],j,k,l,m,n,o,p,q,r,s;if(E.test(h+f.event.triggered))return;h.indexOf("!")>=0&&(h=h.slice(0,-1),k=!0),h.indexOf(".")>=0&&(i=h.split("."),h=i.shift(),i.sort());if((!e||f.event.customEvent[h])&&!f.event.global[h])return;c=typeof c=="object"?c[f.expando]?c:new f.Event(h,c):new f.Event(h),c.type=h,c.isTrigger=!0,c.exclusive=k,c.namespace=i.join("."),c.namespace_re=c.namespace?new RegExp("(^|\\.)"+i.join("\\.(?:.*\\.)?")+"(\\.|$)"):null,o=h.indexOf(":")<0?"on"+h:"";if(!e){j=f.cache;for(l in j)j[l].events&&j[l].events[h]&&f.event.trigger(c,d,j[l].handle.elem,!0);return}c.result=b,c.target||(c.target=e),d=d!=null?f.makeArray(d):[],d.unshift(c),p=f.event.special[h]||{};if(p.trigger&&p.trigger.apply(e,d)===!1)return;r=[[e,p.bindType||h]];if(!g&&!p.noBubble&&!f.isWindow(e)){s=p.delegateType||h,m=E.test(s+h)?e:e.parentNode,n=null;for(;m;m=m.parentNode)r.push([m,s]),n=m;n&&n===e.ownerDocument&&r.push([n.defaultView||n.parentWindow||a,s])}for(l=0;l<r.length&&!c.isPropagationStopped();l++)m=r[l][0],c.type=r[l][1],q=(f._data(m,"events")||{})[c.type]&&f._data(m,"handle"),q&&q.apply(m,d),q=o&&m[o],q&&f.acceptData(m)&&q.apply(m,d)===!1&&c.preventDefault();c.type=h,!g&&!c.isDefaultPrevented()&&(!p._default||p._default.apply(e.ownerDocument,d)===!1)&&(h!=="click"||!f.nodeName(e,"a"))&&f.acceptData(e)&&o&&e[h]&&(h!=="focus"&&h!=="blur"||c.target.offsetWidth!==0)&&!f.isWindow(e)&&(n=e[o],n&&(e[o]=null),f.event.triggered=h,e[h](),f.event.triggered=b,n&&(e[o]=n));return c.result}},dispatch:function(c){c=f.event.fix(c||a.event);var d=(f._data(this,"events")||{})[c.type]||[],e=d.delegateCount,g=[].slice.call(arguments,0),h=!c.exclusive&&!c.namespace,i=[],j,k,l,m,n,o,p,q,r,s,t;g[0]=c,c.delegateTarget=this;if(e&&!c.target.disabled&&(!c.button||c.type!=="click")){m=f(this),m.context=this.ownerDocument||this;for(l=c.target;l!=this;l=l.parentNode||this){o={},q=[],m[0]=l;for(j=0;j<e;j++)r=d[j],s=r.selector,o[s]===b&&(o[s]=r.quick?H(l,r.quick):m.is(s)),o[s]&&q.push(r);q.length&&i.push({elem:l,matches:q})}}d.length>e&&i.push({elem:this,matches:d.slice(e)});for(j=0;j<i.length&&!c.isPropagationStopped();j++){p=i[j],c.currentTarget=p.elem;for(k=0;k<p.matches.length&&!c.isImmediatePropagationStopped();k++){r=p.matches[k];if(h||!c.namespace&&!r.namespace||c.namespace_re&&c.namespace_re.test(r.namespace))c.data=r.data,c.handleObj=r,n=((f.event.special[r.origType]||{}).handle||r.handler).apply(p.elem,g),n!==b&&(c.result=n,n===!1&&(c.preventDefault(),c.stopPropagation()))}}return c.result},props:"attrChange attrName relatedNode srcElement altKey bubbles cancelable ctrlKey currentTarget eventPhase metaKey relatedTarget shiftKey target timeStamp view which".split(" "),fixHooks:{},keyHooks:{props:"char charCode key keyCode".split(" "),filter:function(a,b){a.which==null&&(a.which=b.charCode!=null?b.charCode:b.keyCode);return a}},mouseHooks:{props:"button buttons clientX clientY fromElement offsetX offsetY pageX pageY screenX screenY toElement".split(" "),filter:function(a,d){var e,f,g,h=d.button,i=d.fromElement;a.pageX==null&&d.clientX!=null&&(e=a.target.ownerDocument||c,f=e.documentElement,g=e.body,a.pageX=d.clientX+(f&&f.scrollLeft||g&&g.scrollLeft||0)-(f&&f.clientLeft||g&&g.clientLeft||0),a.pageY=d.clientY+(f&&f.scrollTop||g&&g.scrollTop||0)-(f&&f.clientTop||g&&g.clientTop||0)),!a.relatedTarget&&i&&(a.relatedTarget=i===a.target?d.toElement:i),!a.which&&h!==b&&(a.which=h&1?1:h&2?3:h&4?2:0);return a}},fix:function(a){if(a[f.expando])return a;var d,e,g=a,h=f.event.fixHooks[a.type]||{},i=h.props?this.props.concat(h.props):this.props;a=f.Event(g);for(d=i.length;d;)e=i[--d],a[e]=g[e];a.target||(a.target=g.srcElement||c),a.target.nodeType===3&&(a.target=a.target.parentNode),a.metaKey===b&&(a.metaKey=a.ctrlKey);return h.filter?h.filter(a,g):a},special:{ready:{setup:f.bindReady},load:{noBubble:!0},focus:{delegateType:"focusin"},blur:{delegateType:"focusout"},beforeunload:{setup:function(a,b,c){f.isWindow(this)&&(this.onbeforeunload=c)},teardown:function(a,b){this.onbeforeunload===b&&(this.onbeforeunload=null)}}},simulate:function(a,b,c,d){var e=f.extend(new f.Event,c,{type:a,isSimulated:!0,originalEvent:{}});d?f.event.trigger(e,null,b):f.event.dispatch.call(b,e),e.isDefaultPrevented()&&c.preventDefault()}},f.event.handle=f.event.dispatch,f.removeEvent=c.removeEventListener?function(a,b,c){a.removeEventListener&&a.removeEventListener(b,c,!1)}:function(a,b,c){a.detachEvent&&a.detachEvent("on"+b,c)},f.Event=function(a,b){if(!(this instanceof f.Event))return new f.Event(a,b);a&&a.type?(this.originalEvent=a,this.type=a.type,this.isDefaultPrevented=a.defaultPrevented||a.returnValue===!1||a.getPreventDefault&&a.getPreventDefault()?K:J):this.type=a,b&&f.extend(this,b),this.timeStamp=a&&a.timeStamp||f.now(),this[f.expando]=!0},f.Event.prototype={preventDefault:function(){this.isDefaultPrevented=K;var a=this.originalEvent;!a||(a.preventDefault?a.preventDefault():a.returnValue=!1)},stopPropagation:function(){this.isPropagationStopped=K;var a=this.originalEvent;!a||(a.stopPropagation&&a.stopPropagation(),a.cancelBubble=!0)},stopImmediatePropagation:function(){this.isImmediatePropagationStopped=K,this.stopPropagation()},isDefaultPrevented:J,isPropagationStopped:J,isImmediatePropagationStopped:J},f.each({mouseenter:"mouseover",mouseleave:"mouseout"},function(a,b){f.event.special[a]={delegateType:b,bindType:b,handle:function(a){var c=this,d=a.relatedTarget,e=a.handleObj,g=e.selector,h;if(!d||d!==c&&!f.contains(c,d))a.type=e.origType,h=e.handler.apply(this,arguments),a.type=b;return h}}}),f.support.submitBubbles||(f.event.special.submit={setup:function(){if(f.nodeName(this,"form"))return!1;f.event.add(this,"click._submit keypress._submit",function(a){var c=a.target,d=f.nodeName(c,"input")||f.nodeName(c,"button")?c.form:b;d&&!d._submit_attached&&(f.event.add(d,"submit._submit",function(a){this.parentNode&&!a.isTrigger&&f.event.simulate("submit",this.parentNode,a,!0)}),d._submit_attached=!0)})},teardown:function(){if(f.nodeName(this,"form"))return!1;f.event.remove(this,"._submit")}}),f.support.changeBubbles||(f.event.special.change={setup:function(){if(z.test(this.nodeName)){if(this.type==="checkbox"||this.type==="radio")f.event.add(this,"propertychange._change",function(a){a.originalEvent.propertyName==="checked"&&(this._just_changed=!0)}),f.event.add(this,"click._change",function(a){this._just_changed&&!a.isTrigger&&(this._just_changed=!1,f.event.simulate("change",this,a,!0))});return!1}f.event.add(this,"beforeactivate._change",function(a){var b=a.target;z.test(b.nodeName)&&!b._change_attached&&(f.event.add(b,"change._change",function(a){this.parentNode&&!a.isSimulated&&!a.isTrigger&&f.event.simulate("change",this.parentNode,a,!0)}),b._change_attached=!0)})},handle:function(a){var b=a.target;if(this!==b||a.isSimulated||a.isTrigger||b.type!=="radio"&&b.type!=="checkbox")return a.handleObj.handler.apply(this,arguments)},teardown:function(){f.event.remove(this,"._change");return z.test(this.nodeName)}}),f.support.focusinBubbles||f.each({focus:"focusin",blur:"focusout"},function(a,b){var d=0,e=function(a){f.event.simulate(b,a.target,f.event.fix(a),!0)};f.event.special[b]={setup:function(){d++===0&&c.addEventListener(a,e,!0)},teardown:function(){--d===0&&c.removeEventListener(a,e,!0)}}}),f.fn.extend({on:function(a,c,d,e,g){var h,i;if(typeof a=="object"){typeof c!="string"&&(d=c,c=b);for(i in a)this.on(i,c,d,a[i],g);return this}d==null&&e==null?(e=c,d=c=b):e==null&&(typeof c=="string"?(e=d,d=b):(e=d,d=c,c=b));if(e===!1)e=J;else if(!e)return this;g===1&&(h=e,e=function(a){f().off(a);return h.apply(this,arguments)},e.guid=h.guid||(h.guid=f.guid++));return this.each(function(){f.event.add(this,a,e,d,c)})},one:function(a,b,c,d){return this.on.call(this,a,b,c,d,1)},off:function(a,c,d){if(a&&a.preventDefault&&a.handleObj){var e=a.handleObj;f(a.delegateTarget).off(e.namespace?e.type+"."+e.namespace:e.type,e.selector,e.handler);return this}if(typeof a=="object"){for(var g in a)this.off(g,c,a[g]);return this}if(c===!1||typeof c=="function")d=c,c=b;d===!1&&(d=J);return this.each(function(){f.event.remove(this,a,d,c)})},bind:function(a,b,c){return this.on(a,null,b,c)},unbind:function(a,b){return this.off(a,null,b)},live:function(a,b,c){f(this.context).on(a,this.selector,b,c);return this},die:function(a,b){f(this.context).off(a,this.selector||"**",b);return this},delegate:function(a,b,c,d){return this.on(b,a,c,d)},undelegate:function(a,b,c){return arguments.length==1?this.off(a,"**"):this.off(b,a,c)},trigger:function(a,b){return this.each(function(){f.event.trigger(a,b,this)})},triggerHandler:function(a,b){if(this[0])return f.event.trigger(a,b,this[0],!0)},toggle:function(a){var b=arguments,c=a.guid||f.guid++,d=0,e=function(c){var e=(f._data(this,"lastToggle"+a.guid)||0)%d;f._data(this,"lastToggle"+a.guid,e+1),c.preventDefault();return b[e].apply(this,arguments)||!1};e.guid=c;while(d<b.length)b[d++].guid=c;return this.click(e)},hover:function(a,b){return this.mouseenter(a).mouseleave(b||a)}}),f.each("blur focus focusin focusout load resize scroll unload click dblclick mousedown mouseup mousemove mouseover mouseout mouseenter mouseleave change select submit keydown keypress keyup error contextmenu".split(" "),function(a,b){f.fn[b]=function(a,c){c==null&&(c=a,a=null);return arguments.length>0?this.on(b,null,a,c):this.trigger(b)},f.attrFn&&(f.attrFn[b]=!0),C.test(b)&&(f.event.fixHooks[b]=f.event.keyHooks),D.test(b)&&(f.event.fixHooks[b]=f.event.mouseHooks)}),function(){function x(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}if(j.nodeType===1){g||(j[d]=c,j.sizset=h);if(typeof b!="string"){if(j===b){k=!0;break}}else if(m.filter(b,[j]).length>0){k=j;break}}j=j[a]}e[h]=k}}}function w(a,b,c,e,f,g){for(var h=0,i=e.length;h<i;h++){var j=e[h];if(j){var k=!1;j=j[a];while(j){if(j[d]===c){k=e[j.sizset];break}j.nodeType===1&&!g&&(j[d]=c,j.sizset=h);if(j.nodeName.toLowerCase()===b){k=j;break}j=j[a]}e[h]=k}}}var a=/((?:\((?:\([^()]+\)|[^()]+)+\)|\[(?:\[[^\[\]]*\]|['"][^'"]*['"]|[^\[\]'"]+)+\]|\\.|[^ >+~,(\[\\]+)+|[>+~])(\s*,\s*)?((?:.|\r|\n)*)/g,d="sizcache"+(Math.random()+"").replace(".",""),e=0,g=Object.prototype.toString,h=!1,i=!0,j=/\\/g,k=/\r\n/g,l=/\W/;[0,0].sort(function(){i=!1;return 0});var m=function(b,d,e,f){e=e||[],d=d||c;var h=d;if(d.nodeType!==1&&d.nodeType!==9)return[];if(!b||typeof b!="string")return e;var i,j,k,l,n,q,r,t,u=!0,v=m.isXML(d),w=[],x=b;do{a.exec(""),i=a.exec(x);if(i){x=i[3],w.push(i[1]);if(i[2]){l=i[3];break}}}while(i);if(w.length>1&&p.exec(b))if(w.length===2&&o.relative[w[0]])j=y(w[0]+w[1],d,f);else{j=o.relative[w[0]]?[d]:m(w.shift(),d);while(w.length)b=w.shift(),o.relative[b]&&(b+=w.shift()),j=y(b,j,f)}else{!f&&w.length>1&&d.nodeType===9&&!v&&o.match.ID.test(w[0])&&!o.match.ID.test(w[w.length-1])&&(n=m.find(w.shift(),d,v),d=n.expr?m.filter(n.expr,n.set)[0]:n.set[0]);if(d){n=f?{expr:w.pop(),set:s(f)}:m.find(w.pop(),w.length===1&&(w[0]==="~"||w[0]==="+")&&d.parentNode?d.parentNode:d,v),j=n.expr?m.filter(n.expr,n.set):n.set,w.length>0?k=s(j):u=!1;while(w.length)q=w.pop(),r=q,o.relative[q]?r=w.pop():q="",r==null&&(r=d),o.relative[q](k,r,v)}else k=w=[]}k||(k=j),k||m.error(q||b);if(g.call(k)==="[object Array]")if(!u)e.push.apply(e,k);else if(d&&d.nodeType===1)for(t=0;k[t]!=null;t++)k[t]&&(k[t]===!0||k[t].nodeType===1&&m.contains(d,k[t]))&&e.push(j[t]);else for(t=0;k[t]!=null;t++)k[t]&&k[t].nodeType===1&&e.push(j[t]);else s(k,e);l&&(m(l,h,e,f),m.uniqueSort(e));return e};m.uniqueSort=function(a){if(u){h=i,a.sort(u);if(h)for(var b=1;b<a.length;b++)a[b]===a[b-1]&&a.splice(b--,1)}return a},m.matches=function(a,b){return m(a,null,null,b)},m.matchesSelector=function(a,b){return m(b,null,null,[a]).length>0},m.find=function(a,b,c){var d,e,f,g,h,i;if(!a)return[];for(e=0,f=o.order.length;e<f;e++){h=o.order[e];if(g=o.leftMatch[h].exec(a)){i=g[1],g.splice(1,1);if(i.substr(i.length-1)!=="\\"){g[1]=(g[1]||"").replace(j,""),d=o.find[h](g,b,c);if(d!=null){a=a.replace(o.match[h],"");break}}}}d||(d=typeof b.getElementsByTagName!="undefined"?b.getElementsByTagName("*"):[]);return{set:d,expr:a}},m.filter=function(a,c,d,e){var f,g,h,i,j,k,l,n,p,q=a,r=[],s=c,t=c&&c[0]&&m.isXML(c[0]);while(a&&c.length){for(h in o.filter)if((f=o.leftMatch[h].exec(a))!=null&&f[2]){k=o.filter[h],l=f[1],g=!1,f.splice(1,1);if(l.substr(l.length-1)==="\\")continue;s===r&&(r=[]);if(o.preFilter[h]){f=o.preFilter[h](f,s,d,r,e,t);if(!f)g=i=!0;else if(f===!0)continue}if(f)for(n=0;(j=s[n])!=null;n++)j&&(i=k(j,f,n,s),p=e^i,d&&i!=null?p?g=!0:s[n]=!1:p&&(r.push(j),g=!0));if(i!==b){d||(s=r),a=a.replace(o.match[h],"");if(!g)return[];break}}if(a===q)if(g==null)m.error(a);else break;q=a}return s},m.error=function(a){throw new Error("Syntax error, unrecognized expression: "+a)};var n=m.getText=function(a){var b,c,d=a.nodeType,e="";if(d){if(d===1||d===9){if(typeof a.textContent=="string")return a.textContent;if(typeof a.innerText=="string")return a.innerText.replace(k,"");for(a=a.firstChild;a;a=a.nextSibling)e+=n(a)}else if(d===3||d===4)return a.nodeValue}else for(b=0;c=a[b];b++)c.nodeType!==8&&(e+=n(c));return e},o=m.selectors={order:["ID","NAME","TAG"],match:{ID:/#((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,CLASS:/\.((?:[\w\u00c0-\uFFFF\-]|\\.)+)/,NAME:/\[name=['"]*((?:[\w\u00c0-\uFFFF\-]|\\.)+)['"]*\]/,ATTR:/\[\s*((?:[\w\u00c0-\uFFFF\-]|\\.)+)\s*(?:(\S?=)\s*(?:(['"])(.*?)\3|(#?(?:[\w\u00c0-\uFFFF\-]|\\.)*)|)|)\s*\]/,TAG:/^((?:[\w\u00c0-\uFFFF\*\-]|\\.)+)/,CHILD:/:(only|nth|last|first)-child(?:\(\s*(even|odd|(?:[+\-]?\d+|(?:[+\-]?\d*)?n\s*(?:[+\-]\s*\d+)?))\s*\))?/,POS:/:(nth|eq|gt|lt|first|last|even|odd)(?:\((\d*)\))?(?=[^\-]|$)/,PSEUDO:/:((?:[\w\u00c0-\uFFFF\-]|\\.)+)(?:\((['"]?)((?:\([^\)]+\)|[^\(\)]*)+)\2\))?/},leftMatch:{},attrMap:{"class":"className","for":"htmlFor"},attrHandle:{href:function(a){return a.getAttribute("href")},type:function(a){return a.getAttribute("type")}},relative:{"+":function(a,b){var c=typeof b=="string",d=c&&!l.test(b),e=c&&!d;d&&(b=b.toLowerCase());for(var f=0,g=a.length,h;f<g;f++)if(h=a[f]){while((h=h.previousSibling)&&h.nodeType!==1);a[f]=e||h&&h.nodeName.toLowerCase()===b?h||!1:h===b}e&&m.filter(b,a,!0)},">":function(a,b){var c,d=typeof b=="string",e=0,f=a.length;if(d&&!l.test(b)){b=b.toLowerCase();for(;e<f;e++){c=a[e];if(c){var g=c.parentNode;a[e]=g.nodeName.toLowerCase()===b?g:!1}}}else{for(;e<f;e++)c=a[e],c&&(a[e]=d?c.parentNode:c.parentNode===b);d&&m.filter(b,a,!0)}},"":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("parentNode",b,f,a,d,c)},"~":function(a,b,c){var d,f=e++,g=x;typeof b=="string"&&!l.test(b)&&(b=b.toLowerCase(),d=b,g=w),g("previousSibling",b,f,a,d,c)}},find:{ID:function(a,b,c){if(typeof b.getElementById!="undefined"&&!c){var d=b.getElementById(a[1]);return d&&d.parentNode?[d]:[]}},NAME:function(a,b){if(typeof b.getElementsByName!="undefined"){var c=[],d=b.getElementsByName(a[1]);for(var e=0,f=d.length;e<f;e++)d[e].getAttribute("name")===a[1]&&c.push(d[e]);return c.length===0?null:c}},TAG:function(a,b){if(typeof b.getElementsByTagName!="undefined")return b.getElementsByTagName(a[1])}},preFilter:{CLASS:function(a,b,c,d,e,f){a=" "+a[1].replace(j,"")+" ";if(f)return a;for(var g=0,h;(h=b[g])!=null;g++)h&&(e^(h.className&&(" "+h.className+" ").replace(/[\t\n\r]/g," ").indexOf(a)>=0)?c||d.push(h):c&&(b[g]=!1));return!1},ID:function(a){return a[1].replace(j,"")},TAG:function(a,b){return a[1].replace(j,"").toLowerCase()},CHILD:function(a){if(a[1]==="nth"){a[2]||m.error(a[0]),a[2]=a[2].replace(/^\+|\s*/g,"");var b=/(-?)(\d*)(?:n([+\-]?\d*))?/.exec(a[2]==="even"&&"2n"||a[2]==="odd"&&"2n+1"||!/\D/.test(a[2])&&"0n+"+a[2]||a[2]);a[2]=b[1]+(b[2]||1)-0,a[3]=b[3]-0}else a[2]&&m.error(a[0]);a[0]=e++;return a},ATTR:function(a,b,c,d,e,f){var g=a[1]=a[1].replace(j,"");!f&&o.attrMap[g]&&(a[1]=o.attrMap[g]),a[4]=(a[4]||a[5]||"").replace(j,""),a[2]==="~="&&(a[4]=" "+a[4]+" ");return a},PSEUDO:function(b,c,d,e,f){if(b[1]==="not")if((a.exec(b[3])||"").length>1||/^\w/.test(b[3]))b[3]=m(b[3],null,null,c);else{var g=m.filter(b[3],c,d,!0^f);d||e.push.apply(e,g);return!1}else if(o.match.POS.test(b[0])||o.match.CHILD.test(b[0]))return!0;return b},POS:function(a){a.unshift(!0);return a}},filters:{enabled:function(a){return a.disabled===!1&&a.type!=="hidden"},disabled:function(a){return a.disabled===!0},checked:function(a){return a.checked===!0},selected:function(a){a.parentNode&&a.parentNode.selectedIndex;return a.selected===!0},parent:function(a){return!!a.firstChild},empty:function(a){return!a.firstChild},has:function(a,b,c){return!!m(c[3],a).length},header:function(a){return/h\d/i.test(a.nodeName)},text:function(a){var b=a.getAttribute("type"),c=a.type;return a.nodeName.toLowerCase()==="input"&&"text"===c&&(b===c||b===null)},radio:function(a){return a.nodeName.toLowerCase()==="input"&&"radio"===a.type},checkbox:function(a){return a.nodeName.toLowerCase()==="input"&&"checkbox"===a.type},file:function(a){return a.nodeName.toLowerCase()==="input"&&"file"===a.type},password:function(a){return a.nodeName.toLowerCase()==="input"&&"password"===a.type},submit:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"submit"===a.type},image:function(a){return a.nodeName.toLowerCase()==="input"&&"image"===a.type},reset:function(a){var b=a.nodeName.toLowerCase();return(b==="input"||b==="button")&&"reset"===a.type},button:function(a){var b=a.nodeName.toLowerCase();return b==="input"&&"button"===a.type||b==="button"},input:function(a){return/input|select|textarea|button/i.test(a.nodeName)},focus:function(a){return a===a.ownerDocument.activeElement}},setFilters:{first:function(a,b){return b===0},last:function(a,b,c,d){return b===d.length-1},even:function(a,b){return b%2===0},odd:function(a,b){return b%2===1},lt:function(a,b,c){return b<c[3]-0},gt:function(a,b,c){return b>c[3]-0},nth:function(a,b,c){return c[3]-0===b},eq:function(a,b,c){return c[3]-0===b}},filter:{PSEUDO:function(a,b,c,d){var e=b[1],f=o.filters[e];if(f)return f(a,c,b,d);if(e==="contains")return(a.textContent||a.innerText||n([a])||"").indexOf(b[3])>=0;if(e==="not"){var g=b[3];for(var h=0,i=g.length;h<i;h++)if(g[h]===a)return!1;return!0}m.error(e)},CHILD:function(a,b){var c,e,f,g,h,i,j,k=b[1],l=a;switch(k){case"only":case"first":while(l=l.previousSibling)if(l.nodeType===1)return!1;if(k==="first")return!0;l=a;case"last":while(l=l.nextSibling)if(l.nodeType===1)return!1;return!0;case"nth":c=b[2],e=b[3];if(c===1&&e===0)return!0;f=b[0],g=a.parentNode;if(g&&(g[d]!==f||!a.nodeIndex)){i=0;for(l=g.firstChild;l;l=l.nextSibling)l.nodeType===1&&(l.nodeIndex=++i);g[d]=f}j=a.nodeIndex-e;return c===0?j===0:j%c===0&&j/c>=0}},ID:function(a,b){return a.nodeType===1&&a.getAttribute("id")===b},TAG:function(a,b){return b==="*"&&a.nodeType===1||!!a.nodeName&&a.nodeName.toLowerCase()===b},CLASS:function(a,b){return(" "+(a.className||a.getAttribute("class"))+" ").indexOf(b)>-1},ATTR:function(a,b){var c=b[1],d=m.attr?m.attr(a,c):o.attrHandle[c]?o.attrHandle[c](a):a[c]!=null?a[c]:a.getAttribute(c),e=d+"",f=b[2],g=b[4];return d==null?f==="!=":!f&&m.attr?d!=null:f==="="?e===g:f==="*="?e.indexOf(g)>=0:f==="~="?(" "+e+" ").indexOf(g)>=0:g?f==="!="?e!==g:f==="^="?e.indexOf(g)===0:f==="$="?e.substr(e.length-g.length)===g:f==="|="?e===g||e.substr(0,g.length+1)===g+"-":!1:e&&d!==!1},POS:function(a,b,c,d){var e=b[2],f=o.setFilters[e];if(f)return f(a,c,b,d)}}},p=o.match.POS,q=function(a,b){return"\\"+(b-0+1)};for(var r in o.match)o.match[r]=new RegExp(o.match[r].source+/(?![^\[]*\])(?![^\(]*\))/.source),o.leftMatch[r]=new RegExp(/(^(?:.|\r|\n)*?)/.source+o.match[r].source.replace(/\\(\d+)/g,q));var s=function(a,b){a=Array.prototype.slice.call(a,0);if(b){b.push.apply(b,a);return b}return a};try{Array.prototype.slice.call(c.documentElement.childNodes,0)[0].nodeType}catch(t){s=function(a,b){var c=0,d=b||[];if(g.call(a)==="[object Array]")Array.prototype.push.apply(d,a);else if(typeof a.length=="number")for(var e=a.length;c<e;c++)d.push(a[c]);else for(;a[c];c++)d.push(a[c]);return d}}var u,v;c.documentElement.compareDocumentPosition?u=function(a,b){if(a===b){h=!0;return 0}if(!a.compareDocumentPosition||!b.compareDocumentPosition)return a.compareDocumentPosition?-1:1;return a.compareDocumentPosition(b)&4?-1:1}:(u=function(a,b){if(a===b){h=!0;return 0}if(a.sourceIndex&&b.sourceIndex)return a.sourceIndex-b.sourceIndex;var c,d,e=[],f=[],g=a.parentNode,i=b.parentNode,j=g;if(g===i)return v(a,b);if(!g)return-1;if(!i)return 1;while(j)e.unshift(j),j=j.parentNode;j=i;while(j)f.unshift(j),j=j.parentNode;c=e.length,d=f.length;for(var k=0;k<c&&k<d;k++)if(e[k]!==f[k])return v(e[k],f[k]);return k===c?v(a,f[k],-1):v(e[k],b,1)},v=function(a,b,c){if(a===b)return c;var d=a.nextSibling;while(d){if(d===b)return-1;d=d.nextSibling}return 1}),function(){var a=c.createElement("div"),d="script"+(new Date).getTime(),e=c.documentElement;a.innerHTML="<a name='"+d+"'/>",e.insertBefore(a,e.firstChild),c.getElementById(d)&&(o.find.ID=function(a,c,d){if(typeof c.getElementById!="undefined"&&!d){var e=c.getElementById(a[1]);return e?e.id===a[1]||typeof e.getAttributeNode!="undefined"&&e.getAttributeNode("id").nodeValue===a[1]?[e]:b:[]}},o.filter.ID=function(a,b){var c=typeof a.getAttributeNode!="undefined"&&a.getAttributeNode("id");return a.nodeType===1&&c&&c.nodeValue===b}),e.removeChild(a),e=a=null}(),function(){var a=c.createElement("div");a.appendChild(c.createComment("")),a.getElementsByTagName("*").length>0&&(o.find.TAG=function(a,b){var c=b.getElementsByTagName(a[1]);if(a[1]==="*"){var d=[];for(var e=0;c[e];e++)c[e].nodeType===1&&d.push(c[e]);c=d}return c}),a.innerHTML="<a href='#'></a>",a.firstChild&&typeof a.firstChild.getAttribute!="undefined"&&a.firstChild.getAttribute("href")!=="#"&&(o.attrHandle.href=function(a){return a.getAttribute("href",2)}),a=null}(),c.querySelectorAll&&function(){var a=m,b=c.createElement("div"),d="__sizzle__";b.innerHTML="<p class='TEST'></p>";if(!b.querySelectorAll||b.querySelectorAll(".TEST").length!==0){m=function(b,e,f,g){e=e||c;if(!g&&!m.isXML(e)){var h=/^(\w+$)|^\.([\w\-]+$)|^#([\w\-]+$)/.exec(b);if(h&&(e.nodeType===1||e.nodeType===9)){if(h[1])return s(e.getElementsByTagName(b),f);if(h[2]&&o.find.CLASS&&e.getElementsByClassName)return s(e.getElementsByClassName(h[2]),f)}if(e.nodeType===9){if(b==="body"&&e.body)return s([e.body],f);if(h&&h[3]){var i=e.getElementById(h[3]);if(!i||!i.parentNode)return s([],f);if(i.id===h[3])return s([i],f)}try{return s(e.querySelectorAll(b),f)}catch(j){}}else if(e.nodeType===1&&e.nodeName.toLowerCase()!=="object"){var k=e,l=e.getAttribute("id"),n=l||d,p=e.parentNode,q=/^\s*[+~]/.test(b);l?n=n.replace(/'/g,"\\$&"):e.setAttribute("id",n),q&&p&&(e=e.parentNode);try{if(!q||p)return s(e.querySelectorAll("[id='"+n+"'] "+b),f)}catch(r){}finally{l||k.removeAttribute("id")}}}return a(b,e,f,g)};for(var e in a)m[e]=a[e];b=null}}(),function(){var a=c.documentElement,b=a.matchesSelector||a.mozMatchesSelector||a.webkitMatchesSelector||a.msMatchesSelector;if(b){var d=!b.call(c.createElement("div"),"div"),e=!1;try{b.call(c.documentElement,"[test!='']:sizzle")}catch(f){e=!0}m.matchesSelector=function(a,c){c=c.replace(/\=\s*([^'"\]]*)\s*\]/g,"='$1']");if(!m.isXML(a))try{if(e||!o.match.PSEUDO.test(c)&&!/!=/.test(c)){var f=b.call(a,c);if(f||!d||a.document&&a.document.nodeType!==11)return f}}catch(g){}return m(c,null,null,[a]).length>0}}}(),function(){var a=c.createElement("div");a.innerHTML="<div class='test e'></div><div class='test'></div>";if(!!a.getElementsByClassName&&a.getElementsByClassName("e").length!==0){a.lastChild.className="e";if(a.getElementsByClassName("e").length===1)return;o.order.splice(1,0,"CLASS"),o.find.CLASS=function(a,b,c){if(typeof b.getElementsByClassName!="undefined"&&!c)return b.getElementsByClassName(a[1])},a=null}}(),c.documentElement.contains?m.contains=function(a,b){return a!==b&&(a.contains?a.contains(b):!0)}:c.documentElement.compareDocumentPosition?m.contains=function(a,b){return!!(a.compareDocumentPosition(b)&16)}:m.contains=function(){return!1},m.isXML=function(a){var b=(a?a.ownerDocument||a:0).documentElement;return b?b.nodeName!=="HTML":!1};var y=function(a,b,c){var d,e=[],f="",g=b.nodeType?[b]:b;while(d=o.match.PSEUDO.exec(a))f+=d[0],a=a.replace(o.match.PSEUDO,"");a=o.relative[a]?a+"*":a;for(var h=0,i=g.length;h<i;h++)m(a,g[h],e,c);return m.filter(f,e)};m.attr=f.attr,m.selectors.attrMap={},f.find=m,f.expr=m.selectors,f.expr[":"]=f.expr.filters,f.unique=m.uniqueSort,f.text=m.getText,f.isXMLDoc=m.isXML,f.contains=m.contains}();var L=/Until$/,M=/^(?:parents|prevUntil|prevAll)/,N=/,/,O=/^.[^:#\[\.,]*$/,P=Array.prototype.slice,Q=f.expr.match.POS,R={children:!0,contents:!0,next:!0,prev:!0};f.fn.extend({find:function(a){var b=this,c,d;if(typeof a!="string")return f(a).filter(function(){for(c=0,d=b.length;c<d;c++)if(f.contains(b[c],this))return!0});var e=this.pushStack("","find",a),g,h,i;for(c=0,d=this.length;c<d;c++){g=e.length,f.find(a,this[c],e);if(c>0)for(h=g;h<e.length;h++)for(i=0;i<g;i++)if(e[i]===e[h]){e.splice(h--,1);break}}return e},has:function(a){var b=f(a);return this.filter(function(){for(var a=0,c=b.length;a<c;a++)if(f.contains(this,b[a]))return!0})},not:function(a){return this.pushStack(T(this,a,!1),"not",a)},filter:function(a){return this.pushStack(T(this,a,!0),"filter",a)},is:function(a){return!!a&&(typeof a=="string"?Q.test(a)?f(a,this.context).index(this[0])>=0:f.filter(a,this).length>0:this.filter(a).length>0)},closest:function(a,b){var c=[],d,e,g=this[0];if(f.isArray(a)){var h=1;while(g&&g.ownerDocument&&g!==b){for(d=0;d<a.length;d++)f(g).is(a[d])&&c.push({selector:a[d],elem:g,level:h});g=g.parentNode,h++}return c}var i=Q.test(a)||typeof a!="string"?f(a,b||this.context):0;for(d=0,e=this.length;d<e;d++){g=this[d];while(g){if(i?i.index(g)>-1:f.find.matchesSelector(g,a)){c.push(g);break}g=g.parentNode;if(!g||!g.ownerDocument||g===b||g.nodeType===11)break}}c=c.length>1?f.unique(c):c;return this.pushStack(c,"closest",a)},index:function(a){if(!a)return this[0]&&this[0].parentNode?this.prevAll().length:-1;if(typeof a=="string")return f.inArray(this[0],f(a));return f.inArray(a.jquery?a[0]:a,this)},add:function(a,b){var c=typeof a=="string"?f(a,b):f.makeArray(a&&a.nodeType?[a]:a),d=f.merge(this.get(),c);return this.pushStack(S(c[0])||S(d[0])?d:f.unique(d))},andSelf:function(){return this.add(this.prevObject)}}),f.each({parent:function(a){var b=a.parentNode;return b&&b.nodeType!==11?b:null},parents:function(a){return f.dir(a,"parentNode")},parentsUntil:function(a,b,c){return f.dir(a,"parentNode",c)},next:function(a){return f.nth(a,2,"nextSibling")},prev:function(a){return f.nth(a,2,"previousSibling")},nextAll:function(a){return f.dir(a,"nextSibling")},prevAll:function(a){return f.dir(a,"previousSibling")},nextUntil:function(a,b,c){return f.dir(a,"nextSibling",c)},prevUntil:function(a,b,c){return f.dir(a,"previousSibling",c)},siblings:function(a){return f.sibling(a.parentNode.firstChild,a)},children:function(a){return f.sibling(a.firstChild)},contents:function(a){return f.nodeName(a,"iframe")?a.contentDocument||a.contentWindow.document:f.makeArray(a.childNodes)}},function(a,b){f.fn[a]=function(c,d){var e=f.map(this,b,c);L.test(a)||(d=c),d&&typeof d=="string"&&(e=f.filter(d,e)),e=this.length>1&&!R[a]?f.unique(e):e,(this.length>1||N.test(d))&&M.test(a)&&(e=e.reverse());return this.pushStack(e,a,P.call(arguments).join(","))}}),f.extend({filter:function(a,b,c){c&&(a=":not("+a+")");return b.length===1?f.find.matchesSelector(b[0],a)?[b[0]]:[]:f.find.matches(a,b)},dir:function(a,c,d){var e=[],g=a[c];while(g&&g.nodeType!==9&&(d===b||g.nodeType!==1||!f(g).is(d)))g.nodeType===1&&e.push(g),g=g[c];return e},nth:function(a,b,c,d){b=b||1;var e=0;for(;a;a=a[c])if(a.nodeType===1&&++e===b)break;return a},sibling:function(a,b){var c=[];for(;a;a=a.nextSibling)a.nodeType===1&&a!==b&&c.push(a);return c}});var V="abbr|article|aside|audio|canvas|datalist|details|figcaption|figure|footer|header|hgroup|mark|meter|nav|output|progress|section|summary|time|video",W=/ jQuery\d+="(?:\d+|null)"/g,X=/^\s+/,Y=/<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,Z=/<([\w:]+)/,$=/<tbody/i,_=/<|&#?\w+;/,ba=/<(?:script|style)/i,bb=/<(?:script|object|embed|option|style)/i,bc=new RegExp("<(?:"+V+")","i"),bd=/checked\s*(?:[^=]|=\s*.checked.)/i,be=/\/(java|ecma)script/i,bf=/^\s*<!(?:\[CDATA\[|\-\-)/,bg={option:[1,"<select multiple='multiple'>","</select>"],legend:[1,"<fieldset>","</fieldset>"],thead:[1,"<table>","</table>"],tr:[2,"<table><tbody>","</tbody></table>"],td:[3,"<table><tbody><tr>","</tr></tbody></table>"],col:[2,"<table><tbody></tbody><colgroup>","</colgroup></table>"],area:[1,"<map>","</map>"],_default:[0,"",""]},bh=U(c);bg.optgroup=bg.option,bg.tbody=bg.tfoot=bg.colgroup=bg.caption=bg.thead,bg.th=bg.td,f.support.htmlSerialize||(bg._default=[1,"div<div>","</div>"]),f.fn.extend({text:function(a){if(f.isFunction(a))return this.each(function(b){var c=f(this);c.text(a.call(this,b,c.text()))});if(typeof a!="object"&&a!==b)return this.empty().append((this[0]&&this[0].ownerDocument||c).createTextNode(a));return f.text(this)},wrapAll:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapAll(a.call(this,b))});if(this[0]){var b=f(a,this[0].ownerDocument).eq(0).clone(!0);this[0].parentNode&&b.insertBefore(this[0]),b.map(function(){var a=this;while(a.firstChild&&a.firstChild.nodeType===1)a=a.firstChild;return a}).append(this)}return this},wrapInner:function(a){if(f.isFunction(a))return this.each(function(b){f(this).wrapInner(a.call(this,b))});return this.each(function(){var b=f(this),c=b.contents();c.length?c.wrapAll(a):b.append(a)})},wrap:function(a){var b=f.isFunction(a);return this.each(function(c){f(this).wrapAll(b?a.call(this,c):a)})},unwrap:function(){return this.parent().each(function(){f.nodeName(this,"body")||f(this).replaceWith(this.childNodes)}).end()},append:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.appendChild(a)})},prepend:function(){return this.domManip(arguments,!0,function(a){this.nodeType===1&&this.insertBefore(a,this.firstChild)})},before:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this)});if(arguments.length){var a=f.clean(arguments);a.push.apply(a,this.toArray());return this.pushStack(a,"before",arguments)}},after:function(){if(this[0]&&this[0].parentNode)return this.domManip(arguments,!1,function(a){this.parentNode.insertBefore(a,this.nextSibling)});if(arguments.length){var a=this.pushStack(this,"after",arguments);a.push.apply(a,f.clean(arguments));return a}},remove:function(a,b){for(var c=0,d;(d=this[c])!=null;c++)if(!a||f.filter(a,[d]).length)!b&&d.nodeType===1&&(f.cleanData(d.getElementsByTagName("*")),f.cleanData([d])),d.parentNode&&d.parentNode.removeChild(d);return this},empty:function() +{for(var a=0,b;(b=this[a])!=null;a++){b.nodeType===1&&f.cleanData(b.getElementsByTagName("*"));while(b.firstChild)b.removeChild(b.firstChild)}return this},clone:function(a,b){a=a==null?!1:a,b=b==null?a:b;return this.map(function(){return f.clone(this,a,b)})},html:function(a){if(a===b)return this[0]&&this[0].nodeType===1?this[0].innerHTML.replace(W,""):null;if(typeof a=="string"&&!ba.test(a)&&(f.support.leadingWhitespace||!X.test(a))&&!bg[(Z.exec(a)||["",""])[1].toLowerCase()]){a=a.replace(Y,"<$1></$2>");try{for(var c=0,d=this.length;c<d;c++)this[c].nodeType===1&&(f.cleanData(this[c].getElementsByTagName("*")),this[c].innerHTML=a)}catch(e){this.empty().append(a)}}else f.isFunction(a)?this.each(function(b){var c=f(this);c.html(a.call(this,b,c.html()))}):this.empty().append(a);return this},replaceWith:function(a){if(this[0]&&this[0].parentNode){if(f.isFunction(a))return this.each(function(b){var c=f(this),d=c.html();c.replaceWith(a.call(this,b,d))});typeof a!="string"&&(a=f(a).detach());return this.each(function(){var b=this.nextSibling,c=this.parentNode;f(this).remove(),b?f(b).before(a):f(c).append(a)})}return this.length?this.pushStack(f(f.isFunction(a)?a():a),"replaceWith",a):this},detach:function(a){return this.remove(a,!0)},domManip:function(a,c,d){var e,g,h,i,j=a[0],k=[];if(!f.support.checkClone&&arguments.length===3&&typeof j=="string"&&bd.test(j))return this.each(function(){f(this).domManip(a,c,d,!0)});if(f.isFunction(j))return this.each(function(e){var g=f(this);a[0]=j.call(this,e,c?g.html():b),g.domManip(a,c,d)});if(this[0]){i=j&&j.parentNode,f.support.parentNode&&i&&i.nodeType===11&&i.childNodes.length===this.length?e={fragment:i}:e=f.buildFragment(a,this,k),h=e.fragment,h.childNodes.length===1?g=h=h.firstChild:g=h.firstChild;if(g){c=c&&f.nodeName(g,"tr");for(var l=0,m=this.length,n=m-1;l<m;l++)d.call(c?bi(this[l],g):this[l],e.cacheable||m>1&&l<n?f.clone(h,!0,!0):h)}k.length&&f.each(k,bp)}return this}}),f.buildFragment=function(a,b,d){var e,g,h,i,j=a[0];b&&b[0]&&(i=b[0].ownerDocument||b[0]),i.createDocumentFragment||(i=c),a.length===1&&typeof j=="string"&&j.length<512&&i===c&&j.charAt(0)==="<"&&!bb.test(j)&&(f.support.checkClone||!bd.test(j))&&(f.support.html5Clone||!bc.test(j))&&(g=!0,h=f.fragments[j],h&&h!==1&&(e=h)),e||(e=i.createDocumentFragment(),f.clean(a,i,e,d)),g&&(f.fragments[j]=h?e:1);return{fragment:e,cacheable:g}},f.fragments={},f.each({appendTo:"append",prependTo:"prepend",insertBefore:"before",insertAfter:"after",replaceAll:"replaceWith"},function(a,b){f.fn[a]=function(c){var d=[],e=f(c),g=this.length===1&&this[0].parentNode;if(g&&g.nodeType===11&&g.childNodes.length===1&&e.length===1){e[b](this[0]);return this}for(var h=0,i=e.length;h<i;h++){var j=(h>0?this.clone(!0):this).get();f(e[h])[b](j),d=d.concat(j)}return this.pushStack(d,a,e.selector)}}),f.extend({clone:function(a,b,c){var d,e,g,h=f.support.html5Clone||!bc.test("<"+a.nodeName)?a.cloneNode(!0):bo(a);if((!f.support.noCloneEvent||!f.support.noCloneChecked)&&(a.nodeType===1||a.nodeType===11)&&!f.isXMLDoc(a)){bk(a,h),d=bl(a),e=bl(h);for(g=0;d[g];++g)e[g]&&bk(d[g],e[g])}if(b){bj(a,h);if(c){d=bl(a),e=bl(h);for(g=0;d[g];++g)bj(d[g],e[g])}}d=e=null;return h},clean:function(a,b,d,e){var g;b=b||c,typeof b.createElement=="undefined"&&(b=b.ownerDocument||b[0]&&b[0].ownerDocument||c);var h=[],i;for(var j=0,k;(k=a[j])!=null;j++){typeof k=="number"&&(k+="");if(!k)continue;if(typeof k=="string")if(!_.test(k))k=b.createTextNode(k);else{k=k.replace(Y,"<$1></$2>");var l=(Z.exec(k)||["",""])[1].toLowerCase(),m=bg[l]||bg._default,n=m[0],o=b.createElement("div");b===c?bh.appendChild(o):U(b).appendChild(o),o.innerHTML=m[1]+k+m[2];while(n--)o=o.lastChild;if(!f.support.tbody){var p=$.test(k),q=l==="table"&&!p?o.firstChild&&o.firstChild.childNodes:m[1]==="<table>"&&!p?o.childNodes:[];for(i=q.length-1;i>=0;--i)f.nodeName(q[i],"tbody")&&!q[i].childNodes.length&&q[i].parentNode.removeChild(q[i])}!f.support.leadingWhitespace&&X.test(k)&&o.insertBefore(b.createTextNode(X.exec(k)[0]),o.firstChild),k=o.childNodes}var r;if(!f.support.appendChecked)if(k[0]&&typeof (r=k.length)=="number")for(i=0;i<r;i++)bn(k[i]);else bn(k);k.nodeType?h.push(k):h=f.merge(h,k)}if(d){g=function(a){return!a.type||be.test(a.type)};for(j=0;h[j];j++)if(e&&f.nodeName(h[j],"script")&&(!h[j].type||h[j].type.toLowerCase()==="text/javascript"))e.push(h[j].parentNode?h[j].parentNode.removeChild(h[j]):h[j]);else{if(h[j].nodeType===1){var s=f.grep(h[j].getElementsByTagName("script"),g);h.splice.apply(h,[j+1,0].concat(s))}d.appendChild(h[j])}}return h},cleanData:function(a){var b,c,d=f.cache,e=f.event.special,g=f.support.deleteExpando;for(var h=0,i;(i=a[h])!=null;h++){if(i.nodeName&&f.noData[i.nodeName.toLowerCase()])continue;c=i[f.expando];if(c){b=d[c];if(b&&b.events){for(var j in b.events)e[j]?f.event.remove(i,j):f.removeEvent(i,j,b.handle);b.handle&&(b.handle.elem=null)}g?delete i[f.expando]:i.removeAttribute&&i.removeAttribute(f.expando),delete d[c]}}}});var bq=/alpha\([^)]*\)/i,br=/opacity=([^)]*)/,bs=/([A-Z]|^ms)/g,bt=/^-?\d+(?:px)?$/i,bu=/^-?\d/,bv=/^([\-+])=([\-+.\de]+)/,bw={position:"absolute",visibility:"hidden",display:"block"},bx=["Left","Right"],by=["Top","Bottom"],bz,bA,bB;f.fn.css=function(a,c){if(arguments.length===2&&c===b)return this;return f.access(this,a,c,!0,function(a,c,d){return d!==b?f.style(a,c,d):f.css(a,c)})},f.extend({cssHooks:{opacity:{get:function(a,b){if(b){var c=bz(a,"opacity","opacity");return c===""?"1":c}return a.style.opacity}}},cssNumber:{fillOpacity:!0,fontWeight:!0,lineHeight:!0,opacity:!0,orphans:!0,widows:!0,zIndex:!0,zoom:!0},cssProps:{"float":f.support.cssFloat?"cssFloat":"styleFloat"},style:function(a,c,d,e){if(!!a&&a.nodeType!==3&&a.nodeType!==8&&!!a.style){var g,h,i=f.camelCase(c),j=a.style,k=f.cssHooks[i];c=f.cssProps[i]||i;if(d===b){if(k&&"get"in k&&(g=k.get(a,!1,e))!==b)return g;return j[c]}h=typeof d,h==="string"&&(g=bv.exec(d))&&(d=+(g[1]+1)*+g[2]+parseFloat(f.css(a,c)),h="number");if(d==null||h==="number"&&isNaN(d))return;h==="number"&&!f.cssNumber[i]&&(d+="px");if(!k||!("set"in k)||(d=k.set(a,d))!==b)try{j[c]=d}catch(l){}}},css:function(a,c,d){var e,g;c=f.camelCase(c),g=f.cssHooks[c],c=f.cssProps[c]||c,c==="cssFloat"&&(c="float");if(g&&"get"in g&&(e=g.get(a,!0,d))!==b)return e;if(bz)return bz(a,c)},swap:function(a,b,c){var d={};for(var e in b)d[e]=a.style[e],a.style[e]=b[e];c.call(a);for(e in b)a.style[e]=d[e]}}),f.curCSS=f.css,f.each(["height","width"],function(a,b){f.cssHooks[b]={get:function(a,c,d){var e;if(c){if(a.offsetWidth!==0)return bC(a,b,d);f.swap(a,bw,function(){e=bC(a,b,d)});return e}},set:function(a,b){if(!bt.test(b))return b;b=parseFloat(b);if(b>=0)return b+"px"}}}),f.support.opacity||(f.cssHooks.opacity={get:function(a,b){return br.test((b&&a.currentStyle?a.currentStyle.filter:a.style.filter)||"")?parseFloat(RegExp.$1)/100+"":b?"1":""},set:function(a,b){var c=a.style,d=a.currentStyle,e=f.isNumeric(b)?"alpha(opacity="+b*100+")":"",g=d&&d.filter||c.filter||"";c.zoom=1;if(b>=1&&f.trim(g.replace(bq,""))===""){c.removeAttribute("filter");if(d&&!d.filter)return}c.filter=bq.test(g)?g.replace(bq,e):g+" "+e}}),f(function(){f.support.reliableMarginRight||(f.cssHooks.marginRight={get:function(a,b){var c;f.swap(a,{display:"inline-block"},function(){b?c=bz(a,"margin-right","marginRight"):c=a.style.marginRight});return c}})}),c.defaultView&&c.defaultView.getComputedStyle&&(bA=function(a,b){var c,d,e;b=b.replace(bs,"-$1").toLowerCase(),(d=a.ownerDocument.defaultView)&&(e=d.getComputedStyle(a,null))&&(c=e.getPropertyValue(b),c===""&&!f.contains(a.ownerDocument.documentElement,a)&&(c=f.style(a,b)));return c}),c.documentElement.currentStyle&&(bB=function(a,b){var c,d,e,f=a.currentStyle&&a.currentStyle[b],g=a.style;f===null&&g&&(e=g[b])&&(f=e),!bt.test(f)&&bu.test(f)&&(c=g.left,d=a.runtimeStyle&&a.runtimeStyle.left,d&&(a.runtimeStyle.left=a.currentStyle.left),g.left=b==="fontSize"?"1em":f||0,f=g.pixelLeft+"px",g.left=c,d&&(a.runtimeStyle.left=d));return f===""?"auto":f}),bz=bA||bB,f.expr&&f.expr.filters&&(f.expr.filters.hidden=function(a){var b=a.offsetWidth,c=a.offsetHeight;return b===0&&c===0||!f.support.reliableHiddenOffsets&&(a.style&&a.style.display||f.css(a,"display"))==="none"},f.expr.filters.visible=function(a){return!f.expr.filters.hidden(a)});var bD=/%20/g,bE=/\[\]$/,bF=/\r?\n/g,bG=/#.*$/,bH=/^(.*?):[ \t]*([^\r\n]*)\r?$/mg,bI=/^(?:color|date|datetime|datetime-local|email|hidden|month|number|password|range|search|tel|text|time|url|week)$/i,bJ=/^(?:about|app|app\-storage|.+\-extension|file|res|widget):$/,bK=/^(?:GET|HEAD)$/,bL=/^\/\//,bM=/\?/,bN=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi,bO=/^(?:select|textarea)/i,bP=/\s+/,bQ=/([?&])_=[^&]*/,bR=/^([\w\+\.\-]+:)(?:\/\/([^\/?#:]*)(?::(\d+))?)?/,bS=f.fn.load,bT={},bU={},bV,bW,bX=["*/"]+["*"];try{bV=e.href}catch(bY){bV=c.createElement("a"),bV.href="",bV=bV.href}bW=bR.exec(bV.toLowerCase())||[],f.fn.extend({load:function(a,c,d){if(typeof a!="string"&&bS)return bS.apply(this,arguments);if(!this.length)return this;var e=a.indexOf(" ");if(e>=0){var g=a.slice(e,a.length);a=a.slice(0,e)}var h="GET";c&&(f.isFunction(c)?(d=c,c=b):typeof c=="object"&&(c=f.param(c,f.ajaxSettings.traditional),h="POST"));var i=this;f.ajax({url:a,type:h,dataType:"html",data:c,complete:function(a,b,c){c=a.responseText,a.isResolved()&&(a.done(function(a){c=a}),i.html(g?f("<div>").append(c.replace(bN,"")).find(g):c)),d&&i.each(d,[c,b,a])}});return this},serialize:function(){return f.param(this.serializeArray())},serializeArray:function(){return this.map(function(){return this.elements?f.makeArray(this.elements):this}).filter(function(){return this.name&&!this.disabled&&(this.checked||bO.test(this.nodeName)||bI.test(this.type))}).map(function(a,b){var c=f(this).val();return c==null?null:f.isArray(c)?f.map(c,function(a,c){return{name:b.name,value:a.replace(bF,"\r\n")}}):{name:b.name,value:c.replace(bF,"\r\n")}}).get()}}),f.each("ajaxStart ajaxStop ajaxComplete ajaxError ajaxSuccess ajaxSend".split(" "),function(a,b){f.fn[b]=function(a){return this.on(b,a)}}),f.each(["get","post"],function(a,c){f[c]=function(a,d,e,g){f.isFunction(d)&&(g=g||e,e=d,d=b);return f.ajax({type:c,url:a,data:d,success:e,dataType:g})}}),f.extend({getScript:function(a,c){return f.get(a,b,c,"script")},getJSON:function(a,b,c){return f.get(a,b,c,"json")},ajaxSetup:function(a,b){b?b_(a,f.ajaxSettings):(b=a,a=f.ajaxSettings),b_(a,b);return a},ajaxSettings:{url:bV,isLocal:bJ.test(bW[1]),global:!0,type:"GET",contentType:"application/x-www-form-urlencoded",processData:!0,async:!0,accepts:{xml:"application/xml, text/xml",html:"text/html",text:"text/plain",json:"application/json, text/javascript","*":bX},contents:{xml:/xml/,html:/html/,json:/json/},responseFields:{xml:"responseXML",text:"responseText"},converters:{"* text":a.String,"text html":!0,"text json":f.parseJSON,"text xml":f.parseXML},flatOptions:{context:!0,url:!0}},ajaxPrefilter:bZ(bT),ajaxTransport:bZ(bU),ajax:function(a,c){function w(a,c,l,m){if(s!==2){s=2,q&&clearTimeout(q),p=b,n=m||"",v.readyState=a>0?4:0;var o,r,u,w=c,x=l?cb(d,v,l):b,y,z;if(a>=200&&a<300||a===304){if(d.ifModified){if(y=v.getResponseHeader("Last-Modified"))f.lastModified[k]=y;if(z=v.getResponseHeader("Etag"))f.etag[k]=z}if(a===304)w="notmodified",o=!0;else try{r=cc(d,x),w="success",o=!0}catch(A){w="parsererror",u=A}}else{u=w;if(!w||a)w="error",a<0&&(a=0)}v.status=a,v.statusText=""+(c||w),o?h.resolveWith(e,[r,w,v]):h.rejectWith(e,[v,w,u]),v.statusCode(j),j=b,t&&g.trigger("ajax"+(o?"Success":"Error"),[v,d,o?r:u]),i.fireWith(e,[v,w]),t&&(g.trigger("ajaxComplete",[v,d]),--f.active||f.event.trigger("ajaxStop"))}}typeof a=="object"&&(c=a,a=b),c=c||{};var d=f.ajaxSetup({},c),e=d.context||d,g=e!==d&&(e.nodeType||e instanceof f)?f(e):f.event,h=f.Deferred(),i=f.Callbacks("once memory"),j=d.statusCode||{},k,l={},m={},n,o,p,q,r,s=0,t,u,v={readyState:0,setRequestHeader:function(a,b){if(!s){var c=a.toLowerCase();a=m[c]=m[c]||a,l[a]=b}return this},getAllResponseHeaders:function(){return s===2?n:null},getResponseHeader:function(a){var c;if(s===2){if(!o){o={};while(c=bH.exec(n))o[c[1].toLowerCase()]=c[2]}c=o[a.toLowerCase()]}return c===b?null:c},overrideMimeType:function(a){s||(d.mimeType=a);return this},abort:function(a){a=a||"abort",p&&p.abort(a),w(0,a);return this}};h.promise(v),v.success=v.done,v.error=v.fail,v.complete=i.add,v.statusCode=function(a){if(a){var b;if(s<2)for(b in a)j[b]=[j[b],a[b]];else b=a[v.status],v.then(b,b)}return this},d.url=((a||d.url)+"").replace(bG,"").replace(bL,bW[1]+"//"),d.dataTypes=f.trim(d.dataType||"*").toLowerCase().split(bP),d.crossDomain==null&&(r=bR.exec(d.url.toLowerCase()),d.crossDomain=!(!r||r[1]==bW[1]&&r[2]==bW[2]&&(r[3]||(r[1]==="http:"?80:443))==(bW[3]||(bW[1]==="http:"?80:443)))),d.data&&d.processData&&typeof d.data!="string"&&(d.data=f.param(d.data,d.traditional)),b$(bT,d,c,v);if(s===2)return!1;t=d.global,d.type=d.type.toUpperCase(),d.hasContent=!bK.test(d.type),t&&f.active++===0&&f.event.trigger("ajaxStart");if(!d.hasContent){d.data&&(d.url+=(bM.test(d.url)?"&":"?")+d.data,delete d.data),k=d.url;if(d.cache===!1){var x=f.now(),y=d.url.replace(bQ,"$1_="+x);d.url=y+(y===d.url?(bM.test(d.url)?"&":"?")+"_="+x:"")}}(d.data&&d.hasContent&&d.contentType!==!1||c.contentType)&&v.setRequestHeader("Content-Type",d.contentType),d.ifModified&&(k=k||d.url,f.lastModified[k]&&v.setRequestHeader("If-Modified-Since",f.lastModified[k]),f.etag[k]&&v.setRequestHeader("If-None-Match",f.etag[k])),v.setRequestHeader("Accept",d.dataTypes[0]&&d.accepts[d.dataTypes[0]]?d.accepts[d.dataTypes[0]]+(d.dataTypes[0]!=="*"?", "+bX+"; q=0.01":""):d.accepts["*"]);for(u in d.headers)v.setRequestHeader(u,d.headers[u]);if(d.beforeSend&&(d.beforeSend.call(e,v,d)===!1||s===2)){v.abort();return!1}for(u in{success:1,error:1,complete:1})v[u](d[u]);p=b$(bU,d,c,v);if(!p)w(-1,"No Transport");else{v.readyState=1,t&&g.trigger("ajaxSend",[v,d]),d.async&&d.timeout>0&&(q=setTimeout(function(){v.abort("timeout")},d.timeout));try{s=1,p.send(l,w)}catch(z){if(s<2)w(-1,z);else throw z}}return v},param:function(a,c){var d=[],e=function(a,b){b=f.isFunction(b)?b():b,d[d.length]=encodeURIComponent(a)+"="+encodeURIComponent(b)};c===b&&(c=f.ajaxSettings.traditional);if(f.isArray(a)||a.jquery&&!f.isPlainObject(a))f.each(a,function(){e(this.name,this.value)});else for(var g in a)ca(g,a[g],c,e);return d.join("&").replace(bD,"+")}}),f.extend({active:0,lastModified:{},etag:{}});var cd=f.now(),ce=/(\=)\?(&|$)|\?\?/i;f.ajaxSetup({jsonp:"callback",jsonpCallback:function(){return f.expando+"_"+cd++}}),f.ajaxPrefilter("json jsonp",function(b,c,d){var e=b.contentType==="application/x-www-form-urlencoded"&&typeof b.data=="string";if(b.dataTypes[0]==="jsonp"||b.jsonp!==!1&&(ce.test(b.url)||e&&ce.test(b.data))){var g,h=b.jsonpCallback=f.isFunction(b.jsonpCallback)?b.jsonpCallback():b.jsonpCallback,i=a[h],j=b.url,k=b.data,l="$1"+h+"$2";b.jsonp!==!1&&(j=j.replace(ce,l),b.url===j&&(e&&(k=k.replace(ce,l)),b.data===k&&(j+=(/\?/.test(j)?"&":"?")+b.jsonp+"="+h))),b.url=j,b.data=k,a[h]=function(a){g=[a]},d.always(function(){a[h]=i,g&&f.isFunction(i)&&a[h](g[0])}),b.converters["script json"]=function(){g||f.error(h+" was not called");return g[0]},b.dataTypes[0]="json";return"script"}}),f.ajaxSetup({accepts:{script:"text/javascript, application/javascript, application/ecmascript, application/x-ecmascript"},contents:{script:/javascript|ecmascript/},converters:{"text script":function(a){f.globalEval(a);return a}}}),f.ajaxPrefilter("script",function(a){a.cache===b&&(a.cache=!1),a.crossDomain&&(a.type="GET",a.global=!1)}),f.ajaxTransport("script",function(a){if(a.crossDomain){var d,e=c.head||c.getElementsByTagName("head")[0]||c.documentElement;return{send:function(f,g){d=c.createElement("script"),d.async="async",a.scriptCharset&&(d.charset=a.scriptCharset),d.src=a.url,d.onload=d.onreadystatechange=function(a,c){if(c||!d.readyState||/loaded|complete/.test(d.readyState))d.onload=d.onreadystatechange=null,e&&d.parentNode&&e.removeChild(d),d=b,c||g(200,"success")},e.insertBefore(d,e.firstChild)},abort:function(){d&&d.onload(0,1)}}}});var cf=a.ActiveXObject?function(){for(var a in ch)ch[a](0,1)}:!1,cg=0,ch;f.ajaxSettings.xhr=a.ActiveXObject?function(){return!this.isLocal&&ci()||cj()}:ci,function(a){f.extend(f.support,{ajax:!!a,cors:!!a&&"withCredentials"in a})}(f.ajaxSettings.xhr()),f.support.ajax&&f.ajaxTransport(function(c){if(!c.crossDomain||f.support.cors){var d;return{send:function(e,g){var h=c.xhr(),i,j;c.username?h.open(c.type,c.url,c.async,c.username,c.password):h.open(c.type,c.url,c.async);if(c.xhrFields)for(j in c.xhrFields)h[j]=c.xhrFields[j];c.mimeType&&h.overrideMimeType&&h.overrideMimeType(c.mimeType),!c.crossDomain&&!e["X-Requested-With"]&&(e["X-Requested-With"]="XMLHttpRequest");try{for(j in e)h.setRequestHeader(j,e[j])}catch(k){}h.send(c.hasContent&&c.data||null),d=function(a,e){var j,k,l,m,n;try{if(d&&(e||h.readyState===4)){d=b,i&&(h.onreadystatechange=f.noop,cf&&delete ch[i]);if(e)h.readyState!==4&&h.abort();else{j=h.status,l=h.getAllResponseHeaders(),m={},n=h.responseXML,n&&n.documentElement&&(m.xml=n),m.text=h.responseText;try{k=h.statusText}catch(o){k=""}!j&&c.isLocal&&!c.crossDomain?j=m.text?200:404:j===1223&&(j=204)}}}catch(p){e||g(-1,p)}m&&g(j,k,m,l)},!c.async||h.readyState===4?d():(i=++cg,cf&&(ch||(ch={},f(a).unload(cf)),ch[i]=d),h.onreadystatechange=d)},abort:function(){d&&d(0,1)}}}});var ck={},cl,cm,cn=/^(?:toggle|show|hide)$/,co=/^([+\-]=)?([\d+.\-]+)([a-z%]*)$/i,cp,cq=[["height","marginTop","marginBottom","paddingTop","paddingBottom"],["width","marginLeft","marginRight","paddingLeft","paddingRight"],["opacity"]],cr;f.fn.extend({show:function(a,b,c){var d,e;if(a||a===0)return this.animate(cu("show",3),a,b,c);for(var g=0,h=this.length;g<h;g++)d=this[g],d.style&&(e=d.style.display,!f._data(d,"olddisplay")&&e==="none"&&(e=d.style.display=""),e===""&&f.css(d,"display")==="none"&&f._data(d,"olddisplay",cv(d.nodeName)));for(g=0;g<h;g++){d=this[g];if(d.style){e=d.style.display;if(e===""||e==="none")d.style.display=f._data(d,"olddisplay")||""}}return this},hide:function(a,b,c){if(a||a===0)return this.animate(cu("hide",3),a,b,c);var d,e,g=0,h=this.length;for(;g<h;g++)d=this[g],d.style&&(e=f.css(d,"display"),e!=="none"&&!f._data(d,"olddisplay")&&f._data(d,"olddisplay",e));for(g=0;g<h;g++)this[g].style&&(this[g].style.display="none");return this},_toggle:f.fn.toggle,toggle:function(a,b,c){var d=typeof a=="boolean";f.isFunction(a)&&f.isFunction(b)?this._toggle.apply(this,arguments):a==null||d?this.each(function(){var b=d?a:f(this).is(":hidden");f(this)[b?"show":"hide"]()}):this.animate(cu("toggle",3),a,b,c);return this},fadeTo:function(a,b,c,d){return this.filter(":hidden").css("opacity",0).show().end().animate({opacity:b},a,c,d)},animate:function(a,b,c,d){function g(){e.queue===!1&&f._mark(this);var b=f.extend({},e),c=this.nodeType===1,d=c&&f(this).is(":hidden"),g,h,i,j,k,l,m,n,o;b.animatedProperties={};for(i in a){g=f.camelCase(i),i!==g&&(a[g]=a[i],delete a[i]),h=a[g],f.isArray(h)?(b.animatedProperties[g]=h[1],h=a[g]=h[0]):b.animatedProperties[g]=b.specialEasing&&b.specialEasing[g]||b.easing||"swing";if(h==="hide"&&d||h==="show"&&!d)return b.complete.call(this);c&&(g==="height"||g==="width")&&(b.overflow=[this.style.overflow,this.style.overflowX,this.style.overflowY],f.css(this,"display")==="inline"&&f.css(this,"float")==="none"&&(!f.support.inlineBlockNeedsLayout||cv(this.nodeName)==="inline"?this.style.display="inline-block":this.style.zoom=1))}b.overflow!=null&&(this.style.overflow="hidden");for(i in a)j=new f.fx(this,b,i),h=a[i],cn.test(h)?(o=f._data(this,"toggle"+i)||(h==="toggle"?d?"show":"hide":0),o?(f._data(this,"toggle"+i,o==="show"?"hide":"show"),j[o]()):j[h]()):(k=co.exec(h),l=j.cur(),k?(m=parseFloat(k[2]),n=k[3]||(f.cssNumber[i]?"":"px"),n!=="px"&&(f.style(this,i,(m||1)+n),l=(m||1)/j.cur()*l,f.style(this,i,l+n)),k[1]&&(m=(k[1]==="-="?-1:1)*m+l),j.custom(l,m,n)):j.custom(l,h,""));return!0}var e=f.speed(b,c,d);if(f.isEmptyObject(a))return this.each(e.complete,[!1]);a=f.extend({},a);return e.queue===!1?this.each(g):this.queue(e.queue,g)},stop:function(a,c,d){typeof a!="string"&&(d=c,c=a,a=b),c&&a!==!1&&this.queue(a||"fx",[]);return this.each(function(){function h(a,b,c){var e=b[c];f.removeData(a,c,!0),e.stop(d)}var b,c=!1,e=f.timers,g=f._data(this);d||f._unmark(!0,this);if(a==null)for(b in g)g[b]&&g[b].stop&&b.indexOf(".run")===b.length-4&&h(this,g,b);else g[b=a+".run"]&&g[b].stop&&h(this,g,b);for(b=e.length;b--;)e[b].elem===this&&(a==null||e[b].queue===a)&&(d?e[b](!0):e[b].saveState(),c=!0,e.splice(b,1));(!d||!c)&&f.dequeue(this,a)})}}),f.each({slideDown:cu("show",1),slideUp:cu("hide",1),slideToggle:cu("toggle",1),fadeIn:{opacity:"show"},fadeOut:{opacity:"hide"},fadeToggle:{opacity:"toggle"}},function(a,b){f.fn[a]=function(a,c,d){return this.animate(b,a,c,d)}}),f.extend({speed:function(a,b,c){var d=a&&typeof a=="object"?f.extend({},a):{complete:c||!c&&b||f.isFunction(a)&&a,duration:a,easing:c&&b||b&&!f.isFunction(b)&&b};d.duration=f.fx.off?0:typeof d.duration=="number"?d.duration:d.duration in f.fx.speeds?f.fx.speeds[d.duration]:f.fx.speeds._default;if(d.queue==null||d.queue===!0)d.queue="fx";d.old=d.complete,d.complete=function(a){f.isFunction(d.old)&&d.old.call(this),d.queue?f.dequeue(this,d.queue):a!==!1&&f._unmark(this)};return d},easing:{linear:function(a,b,c,d){return c+d*a},swing:function(a,b,c,d){return(-Math.cos(a*Math.PI)/2+.5)*d+c}},timers:[],fx:function(a,b,c){this.options=b,this.elem=a,this.prop=c,b.orig=b.orig||{}}}),f.fx.prototype={update:function(){this.options.step&&this.options.step.call(this.elem,this.now,this),(f.fx.step[this.prop]||f.fx.step._default)(this)},cur:function(){if(this.elem[this.prop]!=null&&(!this.elem.style||this.elem.style[this.prop]==null))return this.elem[this.prop];var a,b=f.css(this.elem,this.prop);return isNaN(a=parseFloat(b))?!b||b==="auto"?0:b:a},custom:function(a,c,d){function h(a){return e.step(a)}var e=this,g=f.fx;this.startTime=cr||cs(),this.end=c,this.now=this.start=a,this.pos=this.state=0,this.unit=d||this.unit||(f.cssNumber[this.prop]?"":"px"),h.queue=this.options.queue,h.elem=this.elem,h.saveState=function(){e.options.hide&&f._data(e.elem,"fxshow"+e.prop)===b&&f._data(e.elem,"fxshow"+e.prop,e.start)},h()&&f.timers.push(h)&&!cp&&(cp=setInterval(g.tick,g.interval))},show:function(){var a=f._data(this.elem,"fxshow"+this.prop);this.options.orig[this.prop]=a||f.style(this.elem,this.prop),this.options.show=!0,a!==b?this.custom(this.cur(),a):this.custom(this.prop==="width"||this.prop==="height"?1:0,this.cur()),f(this.elem).show()},hide:function(){this.options.orig[this.prop]=f._data(this.elem,"fxshow"+this.prop)||f.style(this.elem,this.prop),this.options.hide=!0,this.custom(this.cur(),0)},step:function(a){var b,c,d,e=cr||cs(),g=!0,h=this.elem,i=this.options;if(a||e>=i.duration+this.startTime){this.now=this.end,this.pos=this.state=1,this.update(),i.animatedProperties[this.prop]=!0;for(b in i.animatedProperties)i.animatedProperties[b]!==!0&&(g=!1);if(g){i.overflow!=null&&!f.support.shrinkWrapBlocks&&f.each(["","X","Y"],function(a,b){h.style["overflow"+b]=i.overflow[a]}),i.hide&&f(h).hide();if(i.hide||i.show)for(b in i.animatedProperties)f.style(h,b,i.orig[b]),f.removeData(h,"fxshow"+b,!0),f.removeData(h,"toggle"+b,!0);d=i.complete,d&&(i.complete=!1,d.call(h))}return!1}i.duration==Infinity?this.now=e:(c=e-this.startTime,this.state=c/i.duration,this.pos=f.easing[i.animatedProperties[this.prop]](this.state,c,0,1,i.duration),this.now=this.start+(this.end-this.start)*this.pos),this.update();return!0}},f.extend(f.fx,{tick:function(){var a,b=f.timers,c=0;for(;c<b.length;c++)a=b[c],!a()&&b[c]===a&&b.splice(c--,1);b.length||f.fx.stop()},interval:13,stop:function(){clearInterval(cp),cp=null},speeds:{slow:600,fast:200,_default:400},step:{opacity:function(a){f.style(a.elem,"opacity",a.now)},_default:function(a){a.elem.style&&a.elem.style[a.prop]!=null?a.elem.style[a.prop]=a.now+a.unit:a.elem[a.prop]=a.now}}}),f.each(["width","height"],function(a,b){f.fx.step[b]=function(a){f.style(a.elem,b,Math.max(0,a.now)+a.unit)}}),f.expr&&f.expr.filters&&(f.expr.filters.animated=function(a){return f.grep(f.timers,function(b){return a===b.elem}).length});var cw=/^t(?:able|d|h)$/i,cx=/^(?:body|html)$/i;"getBoundingClientRect"in c.documentElement?f.fn.offset=function(a){var b=this[0],c;if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);try{c=b.getBoundingClientRect()}catch(d){}var e=b.ownerDocument,g=e.documentElement;if(!c||!f.contains(g,b))return c?{top:c.top,left:c.left}:{top:0,left:0};var h=e.body,i=cy(e),j=g.clientTop||h.clientTop||0,k=g.clientLeft||h.clientLeft||0,l=i.pageYOffset||f.support.boxModel&&g.scrollTop||h.scrollTop,m=i.pageXOffset||f.support.boxModel&&g.scrollLeft||h.scrollLeft,n=c.top+l-j,o=c.left+m-k;return{top:n,left:o}}:f.fn.offset=function(a){var b=this[0];if(a)return this.each(function(b){f.offset.setOffset(this,a,b)});if(!b||!b.ownerDocument)return null;if(b===b.ownerDocument.body)return f.offset.bodyOffset(b);var c,d=b.offsetParent,e=b,g=b.ownerDocument,h=g.documentElement,i=g.body,j=g.defaultView,k=j?j.getComputedStyle(b,null):b.currentStyle,l=b.offsetTop,m=b.offsetLeft;while((b=b.parentNode)&&b!==i&&b!==h){if(f.support.fixedPosition&&k.position==="fixed")break;c=j?j.getComputedStyle(b,null):b.currentStyle,l-=b.scrollTop,m-=b.scrollLeft,b===d&&(l+=b.offsetTop,m+=b.offsetLeft,f.support.doesNotAddBorder&&(!f.support.doesAddBorderForTableAndCells||!cw.test(b.nodeName))&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),e=d,d=b.offsetParent),f.support.subtractsBorderForOverflowNotVisible&&c.overflow!=="visible"&&(l+=parseFloat(c.borderTopWidth)||0,m+=parseFloat(c.borderLeftWidth)||0),k=c}if(k.position==="relative"||k.position==="static")l+=i.offsetTop,m+=i.offsetLeft;f.support.fixedPosition&&k.position==="fixed"&&(l+=Math.max(h.scrollTop,i.scrollTop),m+=Math.max(h.scrollLeft,i.scrollLeft));return{top:l,left:m}},f.offset={bodyOffset:function(a){var b=a.offsetTop,c=a.offsetLeft;f.support.doesNotIncludeMarginInBodyOffset&&(b+=parseFloat(f.css(a,"marginTop"))||0,c+=parseFloat(f.css(a,"marginLeft"))||0);return{top:b,left:c}},setOffset:function(a,b,c){var d=f.css(a,"position");d==="static"&&(a.style.position="relative");var e=f(a),g=e.offset(),h=f.css(a,"top"),i=f.css(a,"left"),j=(d==="absolute"||d==="fixed")&&f.inArray("auto",[h,i])>-1,k={},l={},m,n;j?(l=e.position(),m=l.top,n=l.left):(m=parseFloat(h)||0,n=parseFloat(i)||0),f.isFunction(b)&&(b=b.call(a,c,g)),b.top!=null&&(k.top=b.top-g.top+m),b.left!=null&&(k.left=b.left-g.left+n),"using"in b?b.using.call(a,k):e.css(k)}},f.fn.extend({position:function(){if(!this[0])return null;var a=this[0],b=this.offsetParent(),c=this.offset(),d=cx.test(b[0].nodeName)?{top:0,left:0}:b.offset();c.top-=parseFloat(f.css(a,"marginTop"))||0,c.left-=parseFloat(f.css(a,"marginLeft"))||0,d.top+=parseFloat(f.css(b[0],"borderTopWidth"))||0,d.left+=parseFloat(f.css(b[0],"borderLeftWidth"))||0;return{top:c.top-d.top,left:c.left-d.left}},offsetParent:function(){return this.map(function(){var a=this.offsetParent||c.body;while(a&&!cx.test(a.nodeName)&&f.css(a,"position")==="static")a=a.offsetParent;return a})}}),f.each(["Left","Top"],function(a,c){var d="scroll"+c;f.fn[d]=function(c){var e,g;if(c===b){e=this[0];if(!e)return null;g=cy(e);return g?"pageXOffset"in g?g[a?"pageYOffset":"pageXOffset"]:f.support.boxModel&&g.document.documentElement[d]||g.document.body[d]:e[d]}return this.each(function(){g=cy(this),g?g.scrollTo(a?f(g).scrollLeft():c,a?c:f(g).scrollTop()):this[d]=c})}}),f.each(["Height","Width"],function(a,c){var d=c.toLowerCase();f.fn["inner"+c]=function(){var a=this[0];return a?a.style?parseFloat(f.css(a,d,"padding")):this[d]():null},f.fn["outer"+c]=function(a){var b=this[0];return b?b.style?parseFloat(f.css(b,d,a?"margin":"border")):this[d]():null},f.fn[d]=function(a){var e=this[0];if(!e)return a==null?null:this;if(f.isFunction(a))return this.each(function(b){var c=f(this);c[d](a.call(this,b,c[d]()))});if(f.isWindow(e)){var g=e.document.documentElement["client"+c],h=e.document.body;return e.document.compatMode==="CSS1Compat"&&g||h&&h["client"+c]||g}if(e.nodeType===9)return Math.max(e.documentElement["client"+c],e.body["scroll"+c],e.documentElement["scroll"+c],e.body["offset"+c],e.documentElement["offset"+c]);if(a===b){var i=f.css(e,d),j=parseFloat(i);return f.isNumeric(j)?j:i}return this.css(d,typeof a=="string"?a:a+"px")}}),a.jQuery=a.$=f,typeof define=="function"&&define.amd&&define.amd.jQuery&&define("jquery",[],function(){return f})})(window); \ No newline at end of file diff --git a/lib/msgpack.rb b/lib/msgpack.rb deleted file mode 100644 index a6a109e5..00000000 --- a/lib/msgpack.rb +++ /dev/null @@ -1,48 +0,0 @@ -require "msgpack/version" - -if defined?(RUBY_ENGINE) && RUBY_ENGINE == "jruby" # This is same with `/java/ =~ RUBY_VERSION` - require "msgpack/msgpack.jar" - JRuby::Util.load_ext("org.msgpack.jruby.MessagePackLibrary") -else - require "msgpack/msgpack" -end - -require "msgpack/buffer" -require "msgpack/packer" -require "msgpack/unpacker" -require "msgpack/factory" -require "msgpack/symbol" -require "msgpack/core_ext" -require "msgpack/timestamp" -require "msgpack/time" - -module MessagePack - DefaultFactory = MessagePack::Factory.new - - def load(src, param = nil) - unpacker = nil - - if src.is_a? String - unpacker = DefaultFactory.unpacker param - unpacker.feed_reference src - else - unpacker = DefaultFactory.unpacker src, param - end - - unpacker.full_unpack - end - alias :unpack :load - - module_function :load - module_function :unpack - - def pack(v, io = nil, options = nil) - packer = DefaultFactory.packer(io, options) - packer.write v - packer.full_pack - end - alias :dump :pack - - module_function :pack - module_function :dump -end diff --git a/lib/msgpack/bigint.rb b/lib/msgpack/bigint.rb deleted file mode 100644 index 95b85a54..00000000 --- a/lib/msgpack/bigint.rb +++ /dev/null @@ -1,69 +0,0 @@ -# frozen_string_literal: true - -module MessagePack - module Bigint - # We split the bigint in 32bits chunks so that individual part fits into - # a MRI immediate Integer. - CHUNK_BITLENGTH = 32 - FORMAT = 'CL>*' - - if Integer.instance_method(:[]).arity != 1 # Ruby 2.7 and newer - # Starting from Ruby 2.7 we can address arbitrary bitranges inside an Integer with Integer#[] - # This allows to not allocate any Integer. - def self.to_msgpack_ext(bigint) - members = [] - - if bigint < 0 - bigint = -bigint - members << 1 - else - members << 0 - end - - offset = 0 - length = bigint.bit_length - while offset < length - members << bigint[offset, CHUNK_BITLENGTH] - offset += CHUNK_BITLENGTH - end - - members.pack(FORMAT) - end - else - # On 2.6 and older since we can't address arbitrary bitranges, so we fallback to shifting the bigint. - # This means that after each shift, we may allocate another Integer instance. - BASE = (2**CHUNK_BITLENGTH) - 1 - def self.to_msgpack_ext(bigint) - members = [] - - if bigint < 0 - bigint = -bigint - members << 1 - else - members << 0 - end - - while bigint > 0 - members << (bigint & BASE) - bigint = bigint >> CHUNK_BITLENGTH - end - - members.pack(FORMAT) - end - end - - def self.from_msgpack_ext(data) - parts = data.unpack(FORMAT) - - sign = parts.shift - sum = parts.pop.to_i - - parts.reverse_each do |part| - sum = sum << CHUNK_BITLENGTH - sum += part - end - - sign == 0 ? sum : -sum - end - end -end diff --git a/lib/msgpack/buffer.rb b/lib/msgpack/buffer.rb deleted file mode 100644 index eb582db2..00000000 --- a/lib/msgpack/buffer.rb +++ /dev/null @@ -1,9 +0,0 @@ -module MessagePack - class Buffer - # see ext for other methods - - # The semantic of duping a buffer is just too weird. - undef_method :dup - undef_method :clone - end -end diff --git a/lib/msgpack/core_ext.rb b/lib/msgpack/core_ext.rb deleted file mode 100644 index 2a1880d9..00000000 --- a/lib/msgpack/core_ext.rb +++ /dev/null @@ -1,139 +0,0 @@ -module MessagePack - module CoreExt - def to_msgpack(packer_or_io = nil) - if packer_or_io - if packer_or_io.is_a?(MessagePack::Packer) - to_msgpack_with_packer packer_or_io - else - MessagePack.pack(self, packer_or_io) - end - else - MessagePack.pack(self) - end - end - end -end - -class NilClass - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_nil - packer - end -end - -class TrueClass - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_true - packer - end -end - -class FalseClass - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_false - packer - end -end - -class Float - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_float self - packer - end -end - -class String - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_string self - packer - end -end - -class Array - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_array self - packer - end -end - -class Hash - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_hash self - packer - end -end - -class Symbol - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_symbol self - packer - end -end - -if 1.class.name == "Integer" - class Integer - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_int self - packer - end - end -else - class Fixnum - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_int self - packer - end - end - - class Bignum - include MessagePack::CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_int self - packer - end - end -end - -module MessagePack - class ExtensionValue - include CoreExt - - private - def to_msgpack_with_packer(packer) - packer.write_extension self - packer - end - end -end diff --git a/lib/msgpack/factory.rb b/lib/msgpack/factory.rb deleted file mode 100644 index dfe0201c..00000000 --- a/lib/msgpack/factory.rb +++ /dev/null @@ -1,211 +0,0 @@ -module MessagePack - class Factory - # see ext for other methods - - def register_type(type, klass, options = { packer: :to_msgpack_ext, unpacker: :from_msgpack_ext }) - raise FrozenError, "can't modify frozen MessagePack::Factory" if frozen? - - if options - options = options.dup - case packer = options[:packer] - when nil, Proc - # all good - when String, Symbol - options[:packer] = packer.to_sym.to_proc - when Method - options[:packer] = packer.to_proc - when packer.respond_to?(:call) - options[:packer] = packer.method(:call).to_proc - else - raise ::TypeError, "expected :packer argument to be a callable object, got: #{packer.inspect}" - end - - case unpacker = options[:unpacker] - when nil, Proc - # all good - when String, Symbol - options[:unpacker] = klass.method(unpacker).to_proc - when Method - options[:unpacker] = unpacker.to_proc - when packer.respond_to?(:call) - options[:unpacker] = unpacker.method(:call).to_proc - else - raise ::TypeError, "expected :unpacker argument to be a callable object, got: #{unpacker.inspect}" - end - end - - register_type_internal(type, klass, options) - end - - # [ {type: id, class: Class(or nil), packer: arg, unpacker: arg}, ... ] - def registered_types(selector=:both) - packer, unpacker = registered_types_internal - # packer: Class -> [tid, proc, _flags] - # unpacker: tid -> [klass, proc, _flags] - - list = [] - - case selector - when :both - packer.each_pair do |klass, ary| - type = ary[0] - packer_proc = ary[1] - unpacker_proc = nil - if unpacker.has_key?(type) - unpacker_proc = unpacker.delete(type)[1] - end - list << {type: type, class: klass, packer: packer_proc, unpacker: unpacker_proc} - end - - # unpacker definition only - unpacker.each_pair do |type, ary| - list << {type: type, class: ary[0], packer: nil, unpacker: ary[1]} - end - - when :packer - packer.each_pair do |klass, ary| - if ary[1] - list << {type: ary[0], class: klass, packer: ary[1]} - end - end - - when :unpacker - unpacker.each_pair do |type, ary| - if ary[1] - list << {type: type, class: ary[0], unpacker: ary[1]} - end - end - - else - raise ArgumentError, "invalid selector #{selector}" - end - - list.sort{|a, b| a[:type] <=> b[:type] } - end - - def type_registered?(klass_or_type, selector=:both) - case klass_or_type - when Class - klass = klass_or_type - registered_types(selector).any?{|entry| klass <= entry[:class] } - when Integer - type = klass_or_type - registered_types(selector).any?{|entry| type == entry[:type] } - else - raise ArgumentError, "class or type id" - end - end - - def load(src, param = nil) - unpacker = nil - - if src.is_a? String - unpacker = unpacker(param) - unpacker.feed(src) - else - unpacker = unpacker(src, param) - end - - unpacker.full_unpack - end - alias :unpack :load - - def dump(v, *rest) - packer = packer(*rest) - packer.write(v) - packer.full_pack - end - alias :pack :dump - - def pool(size = 1, **options) - Pool.new( - frozen? ? self : dup.freeze, - size, - options.empty? ? nil : options, - ) - end - - class Pool - if RUBY_ENGINE == "ruby" - class MemberPool - def initialize(size, &block) - @size = size - @new_member = block - @members = [] - end - - def with - member = @members.pop || @new_member.call - begin - yield member - ensure - # If the pool is already full, we simply drop the extra member. - # This is because contrary to a connection pool, creating an extra instance - # is extremely unlikely to cause some kind of resource exhaustion. - # - # We could cycle the members (keep the newer one) but first It's more work and second - # the older member might have been created pre-fork, so it might be at least partially - # in shared memory. - if member && @members.size < @size - member.reset - @members << member - end - end - end - end - else - class MemberPool - def initialize(size, &block) - @size = size - @new_member = block - @members = [] - @mutex = Mutex.new - end - - def with - member = @mutex.synchronize { @members.pop } || @new_member.call - begin - yield member - ensure - member.reset - @mutex.synchronize do - if member && @members.size < @size - @members << member - end - end - end - end - end - end - - def initialize(factory, size, options = nil) - options = nil if !options || options.empty? - @factory = factory - @packers = MemberPool.new(size) { factory.packer(options).freeze } - @unpackers = MemberPool.new(size) { factory.unpacker(options).freeze } - end - - def load(data) - @unpackers.with do |unpacker| - unpacker.feed(data) - unpacker.full_unpack - end - end - - def dump(object) - @packers.with do |packer| - packer.write(object) - packer.full_pack - end - end - - def unpacker(&block) - @unpackers.with(&block) - end - - def packer(&block) - @packers.with(&block) - end - end - end -end diff --git a/lib/msgpack/packer.rb b/lib/msgpack/packer.rb deleted file mode 100644 index c05c7892..00000000 --- a/lib/msgpack/packer.rb +++ /dev/null @@ -1,37 +0,0 @@ -module MessagePack - class Packer - # see ext for other methods - - # The semantic of duping a packer is just too weird. - undef_method :dup - undef_method :clone - - def register_type(type, klass, method_name = nil, &block) - raise ArgumentError, "expected Module/Class got: #{klass.inspect}" unless klass.is_a?(Module) - register_type_internal(type, klass, block || method_name.to_proc) - end - - def registered_types - list = [] - - registered_types_internal.each_pair do |klass, ary| - list << {type: ary[0], class: klass, packer: ary[1]} - end - - list.sort{|a, b| a[:type] <=> b[:type] } - end - - def type_registered?(klass_or_type) - case klass_or_type - when Class - klass = klass_or_type - registered_types.any?{|entry| klass <= entry[:class] } - when Integer - type = klass_or_type - registered_types.any?{|entry| type == entry[:type] } - else - raise ArgumentError, "class or type id" - end - end - end -end diff --git a/lib/msgpack/symbol.rb b/lib/msgpack/symbol.rb deleted file mode 100644 index ebe77a29..00000000 --- a/lib/msgpack/symbol.rb +++ /dev/null @@ -1,26 +0,0 @@ -class Symbol - # to_msgpack_ext is supposed to return a binary string. - # The canonical way to do it for symbols would be: - # [to_s].pack('A*') - # However in this instance we can take a shortcut - if method_defined?(:name) - alias_method :to_msgpack_ext, :name - else - alias_method :to_msgpack_ext, :to_s - end - - def self.from_msgpack_ext(data) - # from_msgpack_ext is supposed to parse a binary string. - # The canonical way to do it for symbols would be: - # data.unpack1('A*').to_sym - # However in this instance we can take a shortcut - - # We assume the string encoding is UTF-8, and let Ruby create either - # an ASCII symbol or UTF-8 symbol. - data.force_encoding(Encoding::UTF_8).to_sym - rescue EncodingError - # If somehow the string wasn't valid UTF-8 not valid ASCII, we fallback - # to what has been the historical behavior of creating a binary symbol - data.force_encoding(Encoding::BINARY).to_sym - end -end diff --git a/lib/msgpack/time.rb b/lib/msgpack/time.rb deleted file mode 100644 index 2e289c63..00000000 --- a/lib/msgpack/time.rb +++ /dev/null @@ -1,29 +0,0 @@ -# frozen_string_literal: true - -# MessagePack extention packer and unpacker for built-in Time class -module MessagePack - module Time - # 3-arg Time.at is available Ruby >= 2.5 - TIME_AT_3_AVAILABLE = begin - !!::Time.at(0, 0, :nanosecond) - rescue ArgumentError - false - end - - Unpacker = if TIME_AT_3_AVAILABLE - lambda do |payload| - tv = MessagePack::Timestamp.from_msgpack_ext(payload) - ::Time.at(tv.sec, tv.nsec, :nanosecond) - end - else - lambda do |payload| - tv = MessagePack::Timestamp.from_msgpack_ext(payload) - ::Time.at(tv.sec, tv.nsec / 1000.0r) - end - end - - Packer = lambda { |time| - MessagePack::Timestamp.to_msgpack_ext(time.tv_sec, time.tv_nsec) - } - end -end diff --git a/lib/msgpack/timestamp.rb b/lib/msgpack/timestamp.rb deleted file mode 100644 index 02ae96f3..00000000 --- a/lib/msgpack/timestamp.rb +++ /dev/null @@ -1,76 +0,0 @@ -# frozen_string_literal: true - -module MessagePack - class Timestamp # a.k.a. "TimeSpec" - # Because the byte-order of MessagePack is big-endian in, - # pack() and unpack() specifies ">". - # See https://docs.ruby-lang.org/en/trunk/Array.html#method-i-pack for details. - - # The timestamp extension type defined in the MessagePack spec. - # See https://github.com/msgpack/msgpack/blob/master/spec.md#timestamp-extension-type for details. - TYPE = -1 - - TIMESTAMP32_MAX_SEC = (1 << 32) - 1 - TIMESTAMP64_MAX_SEC = (1 << 34) - 1 - - # @return [Integer] - attr_reader :sec - - # @return [Integer] - attr_reader :nsec - - # @param [Integer] sec - # @param [Integer] nsec - def initialize(sec, nsec) - @sec = sec - @nsec = nsec - end - - def self.from_msgpack_ext(data) - case data.length - when 4 - # timestamp32 (sec: uint32be) - sec, = data.unpack('L>') - new(sec, 0) - when 8 - # timestamp64 (nsec: uint30be, sec: uint34be) - n, s = data.unpack('L>2') - sec = ((n & 0b11) << 32) | s - nsec = n >> 2 - new(sec, nsec) - when 12 - # timestam96 (nsec: uint32be, sec: int64be) - nsec, sec = data.unpack('L>q>') - new(sec, nsec) - else - raise MalformedFormatError, "Invalid timestamp data size: #{data.length}" - end - end - - def self.to_msgpack_ext(sec, nsec) - if sec >= 0 && nsec >= 0 && sec <= TIMESTAMP64_MAX_SEC - if nsec === 0 && sec <= TIMESTAMP32_MAX_SEC - # timestamp32 = (sec: uint32be) - [sec].pack('L>') - else - # timestamp64 (nsec: uint30be, sec: uint34be) - nsec30 = nsec << 2 - sec_high2 = sec >> 32 # high 2 bits (`x & 0b11` is redandunt) - sec_low32 = sec & 0xffffffff # low 32 bits - [nsec30 | sec_high2, sec_low32].pack('L>2') - end - else - # timestamp96 (nsec: uint32be, sec: int64be) - [nsec, sec].pack('L>q>') - end - end - - def to_msgpack_ext - self.class.to_msgpack_ext(sec, nsec) - end - - def ==(other) - other.class == self.class && sec == other.sec && nsec == other.nsec - end - end -end diff --git a/lib/msgpack/unpacker.rb b/lib/msgpack/unpacker.rb deleted file mode 100644 index e8bd7153..00000000 --- a/lib/msgpack/unpacker.rb +++ /dev/null @@ -1,41 +0,0 @@ -module MessagePack - class Unpacker - # see ext for other methods - - # The semantic of duping an unpacker is just too weird. - undef_method :dup - undef_method :clone - - def register_type(type, klass = nil, method_name = nil, &block) - if klass && method_name - block = klass.method(method_name).to_proc - elsif !block_given? - raise ArgumentError, "register_type takes either 3 arguments or a block" - end - register_type_internal(type, klass, block) - end - - def registered_types - list = [] - - registered_types_internal.each_pair do |type, ary| - list << {type: type, class: ary[0], unpacker: ary[1]} - end - - list.sort{|a, b| a[:type] <=> b[:type] } - end - - def type_registered?(klass_or_type) - case klass_or_type - when Class - klass = klass_or_type - registered_types.any?{|entry| klass == entry[:class] } - when Integer - type = klass_or_type - registered_types.any?{|entry| type == entry[:type] } - else - raise ArgumentError, "class or type id" - end - end - end -end diff --git a/lib/msgpack/version.rb b/lib/msgpack/version.rb deleted file mode 100644 index bf8e8107..00000000 --- a/lib/msgpack/version.rb +++ /dev/null @@ -1,6 +0,0 @@ -module MessagePack - VERSION = "1.8.0" - # Note for maintainers: - # Don't miss building/releasing the JRuby version (rake buld:java) - # See "How to build -java rubygems" in README for more details. -end diff --git a/method_list.html b/method_list.html new file mode 100644 index 00000000..a3280202 --- /dev/null +++ b/method_list.html @@ -0,0 +1,726 @@ +<!DOCTYPE html> +<html > + <head> + <meta name="viewport" content="width=device-width, initial-scale=1.0"> + <meta charset="utf-8" /> + + <link rel="stylesheet" href="css/full_list.css" type="text/css" media="screen" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" media="screen" /> + + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/full_list.js"></script> + + + <title>Method List</title> + <base id="base_target" target="_parent" /> + </head> + <body> + <div id="content"> + <div class="fixed_header"> + <h1 id="full_list_header">Method List</h1> + <div id="full_list_nav"> + + <span><a target="_self" href="class_list.html"> + Classes + </a></span> + + <span><a target="_self" href="method_list.html"> + Methods + </a></span> + + <span><a target="_self" href="file_list.html"> + Files + </a></span> + + </div> + + <div id="search"> + <label for="search-class">Search:</label> + <input id="search-class" type="text" /> + </div> + </div> + + <ul id="full_list" class="method"> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#<<-instance_method" title="MessagePack::Buffer#<< (method)">#<<</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#buffer-instance_method" title="MessagePack::Packer#buffer (method)">#buffer</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#buffer-instance_method" title="MessagePack::Unpacker#buffer (method)">#buffer</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#clear-instance_method" title="MessagePack::Buffer#clear (method)">#clear</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#close-instance_method" title="MessagePack::Buffer#close (method)">#close</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#dump-instance_method" title="MessagePack::Factory#dump (method)">#dump</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory/Pool.html#dump-instance_method" title="MessagePack::Factory::Pool#dump (method)">#dump</a></span> + <small>MessagePack::Factory::Pool</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack.html#dump-class_method" title="MessagePack.dump (method)">dump</a></span> + <small>MessagePack</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#each-instance_method" title="MessagePack::Unpacker#each (method)">#each</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#empty%3F-instance_method" title="MessagePack::Packer#empty? (method)">#empty?</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#empty%3F-instance_method" title="MessagePack::Buffer#empty? (method)">#empty?</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#feed-instance_method" title="MessagePack::Unpacker#feed (method)">#feed</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#feed_each-instance_method" title="MessagePack::Unpacker#feed_each (method)">#feed_each</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#flush-instance_method" title="MessagePack::Buffer#flush (method)">#flush</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#flush-instance_method" title="MessagePack::Packer#flush (method)">#flush</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Timestamp.html#from_msgpack_ext-class_method" title="MessagePack::Timestamp.from_msgpack_ext (method)">from_msgpack_ext</a></span> + <small>MessagePack::Timestamp</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#full_pack-instance_method" title="MessagePack::Packer#full_pack (method)">#full_pack</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#initialize-instance_method" title="MessagePack::Unpacker#initialize (method)">#initialize</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#initialize-instance_method" title="MessagePack::Buffer#initialize (method)">#initialize</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#initialize-instance_method" title="MessagePack::Packer#initialize (method)">#initialize</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#initialize-instance_method" title="MessagePack::Factory#initialize (method)">#initialize</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Timestamp.html#initialize-instance_method" title="MessagePack::Timestamp#initialize (method)">#initialize</a></span> + <small>MessagePack::Timestamp</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#io-instance_method" title="MessagePack::Buffer#io (method)">#io</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory/Pool.html#load-instance_method" title="MessagePack::Factory::Pool#load (method)">#load</a></span> + <small>MessagePack::Factory::Pool</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#load-instance_method" title="MessagePack::Factory#load (method)">#load</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack.html#load-class_method" title="MessagePack.load (method)">load</a></span> + <small>MessagePack</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Timestamp.html#nsec-instance_method" title="MessagePack::Timestamp#nsec (method)">#nsec</a></span> + <small>MessagePack::Timestamp</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack.html#pack-class_method" title="MessagePack.pack (method)">pack</a></span> + <small>MessagePack</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#packer-instance_method" title="MessagePack::Factory#packer (method)">#packer</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory/Pool.html#packer-instance_method" title="MessagePack::Factory::Pool#packer (method)">#packer</a></span> + <small>MessagePack::Factory::Pool</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/ExtensionValue.html#payload-instance_method" title="MessagePack::ExtensionValue#payload (method)">#payload</a></span> + <small>MessagePack::ExtensionValue</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#pool-instance_method" title="MessagePack::Factory#pool (method)">#pool</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#read-instance_method" title="MessagePack::Buffer#read (method)">#read</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#read-instance_method" title="MessagePack::Unpacker#read (method)">#read</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#read_all-instance_method" title="MessagePack::Buffer#read_all (method)">#read_all</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#read_array_header-instance_method" title="MessagePack::Unpacker#read_array_header (method)">#read_array_header</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#read_map_header-instance_method" title="MessagePack::Unpacker#read_map_header (method)">#read_map_header</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#register_type-instance_method" title="MessagePack::Packer#register_type (method)">#register_type</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#register_type-instance_method" title="MessagePack::Unpacker#register_type (method)">#register_type</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#register_type-instance_method" title="MessagePack::Factory#register_type (method)">#register_type</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#registered_types-instance_method" title="MessagePack::Unpacker#registered_types (method)">#registered_types</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#registered_types-instance_method" title="MessagePack::Packer#registered_types (method)">#registered_types</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#registered_types-instance_method" title="MessagePack::Factory#registered_types (method)">#registered_types</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#reset-instance_method" title="MessagePack::Unpacker#reset (method)">#reset</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#reset-instance_method" title="MessagePack::Packer#reset (method)">#reset</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Timestamp.html#sec-instance_method" title="MessagePack::Timestamp#sec (method)">#sec</a></span> + <small>MessagePack::Timestamp</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#size-instance_method" title="MessagePack::Buffer#size (method)">#size</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#size-instance_method" title="MessagePack::Packer#size (method)">#size</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#skip-instance_method" title="MessagePack::Unpacker#skip (method)">#skip</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#skip-instance_method" title="MessagePack::Buffer#skip (method)">#skip</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#skip_all-instance_method" title="MessagePack::Buffer#skip_all (method)">#skip_all</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#skip_nil-instance_method" title="MessagePack::Unpacker#skip_nil (method)">#skip_nil</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#to_a-instance_method" title="MessagePack::Buffer#to_a (method)">#to_a</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#to_a-instance_method" title="MessagePack::Packer#to_a (method)">#to_a</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="FalseClass.html#to_msgpack-instance_method" title="FalseClass#to_msgpack (method)">#to_msgpack</a></span> + <small>FalseClass</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="Fixnum.html#to_msgpack-instance_method" title="Fixnum#to_msgpack (method)">#to_msgpack</a></span> + <small>Fixnum</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="Bignum.html#to_msgpack-instance_method" title="Bignum#to_msgpack (method)">#to_msgpack</a></span> + <small>Bignum</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="Float.html#to_msgpack-instance_method" title="Float#to_msgpack (method)">#to_msgpack</a></span> + <small>Float</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="String.html#to_msgpack-instance_method" title="String#to_msgpack (method)">#to_msgpack</a></span> + <small>String</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="Array.html#to_msgpack-instance_method" title="Array#to_msgpack (method)">#to_msgpack</a></span> + <small>Array</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="Symbol.html#to_msgpack-instance_method" title="Symbol#to_msgpack (method)">#to_msgpack</a></span> + <small>Symbol</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="Hash.html#to_msgpack-instance_method" title="Hash#to_msgpack (method)">#to_msgpack</a></span> + <small>Hash</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="NilClass.html#to_msgpack-instance_method" title="NilClass#to_msgpack (method)">#to_msgpack</a></span> + <small>NilClass</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="TrueClass.html#to_msgpack-instance_method" title="TrueClass#to_msgpack (method)">#to_msgpack</a></span> + <small>TrueClass</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Timestamp.html#to_msgpack_ext-class_method" title="MessagePack::Timestamp.to_msgpack_ext (method)">to_msgpack_ext</a></span> + <small>MessagePack::Timestamp</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#to_str-instance_method" title="MessagePack::Buffer#to_str (method)">#to_str</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#to_str-instance_method" title="MessagePack::Packer#to_str (method)">#to_str</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/ExtensionValue.html#type-instance_method" title="MessagePack::ExtensionValue#type (method)">#type</a></span> + <small>MessagePack::ExtensionValue</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#type_registered%3F-instance_method" title="MessagePack::Factory#type_registered? (method)">#type_registered?</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Unpacker.html#type_registered%3F-instance_method" title="MessagePack::Unpacker#type_registered? (method)">#type_registered?</a></span> + <small>MessagePack::Unpacker</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#type_registered%3F-instance_method" title="MessagePack::Packer#type_registered? (method)">#type_registered?</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack.html#unpack-class_method" title="MessagePack.unpack (method)">unpack</a></span> + <small>MessagePack</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory/Pool.html#unpacker-instance_method" title="MessagePack::Factory::Pool#unpacker (method)">#unpacker</a></span> + <small>MessagePack::Factory::Pool</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Factory.html#unpacker-instance_method" title="MessagePack::Factory#unpacker (method)">#unpacker</a></span> + <small>MessagePack::Factory</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#write-instance_method" title="MessagePack::Buffer#write (method)">#write</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write-instance_method" title="MessagePack::Packer#write (method)">#write</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write_array_header-instance_method" title="MessagePack::Packer#write_array_header (method)">#write_array_header</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write_bin-instance_method" title="MessagePack::Packer#write_bin (method)">#write_bin</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write_bin_header-instance_method" title="MessagePack::Packer#write_bin_header (method)">#write_bin_header</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write_float32-instance_method" title="MessagePack::Packer#write_float32 (method)">#write_float32</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write_map_header-instance_method" title="MessagePack::Packer#write_map_header (method)">#write_map_header</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write_nil-instance_method" title="MessagePack::Packer#write_nil (method)">#write_nil</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + <li class="odd "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Buffer.html#write_to-instance_method" title="MessagePack::Buffer#write_to (method)">#write_to</a></span> + <small>MessagePack::Buffer</small> + </div> + </li> + + + <li class="even "> + <div class="item"> + <span class='object_link'><a href="MessagePack/Packer.html#write_to-instance_method" title="MessagePack::Packer#write_to (method)">#write_to</a></span> + <small>MessagePack::Packer</small> + </div> + </li> + + + + </ul> + </div> + </body> +</html> diff --git a/msgpack.gemspec b/msgpack.gemspec deleted file mode 100644 index 426f2ff4..00000000 --- a/msgpack.gemspec +++ /dev/null @@ -1,36 +0,0 @@ -$LOAD_PATH.push File.expand_path("../lib", __FILE__) -require 'msgpack/version' - -Gem::Specification.new do |s| - s.name = "msgpack" - s.version = MessagePack::VERSION - s.summary = "MessagePack, a binary-based efficient data interchange format." - s.description = %q{MessagePack is a binary-based efficient object serialization library. It enables to exchange structured objects between many languages like JSON. But unlike JSON, it is very fast and small.} - s.authors = ["Sadayuki Furuhashi", "Theo Hultberg", "Satoshi Tagomori"] - s.email = ["frsyuki@gmail.com", "theo@iconara.net", "tagomoris@gmail.com"] - s.license = "Apache-2.0" - s.homepage = "http://msgpack.org/" - s.require_paths = ["lib"] - if /java/ =~ RUBY_PLATFORM - s.files = Dir['lib/**/*.rb', 'lib/**/*.jar', 'LICENSE'] - s.platform = Gem::Platform.new('java') - else - s.files = `git ls-files -z`.split("\x0").reject do |f| - (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features|bench|doclib|msgpack.org.md|Gemfile|Rakefile)|\.(?:git|circleci|rubocop)|appveyor)}) - end - s.extensions = ["ext/msgpack/extconf.rb"] - end - - s.required_ruby_version = ">= 2.5" - - s.add_development_dependency 'bundler' - s.add_development_dependency 'rake' - s.add_development_dependency 'rake-compiler', ['>= 1.1.9'] - s.add_development_dependency 'rspec', ['~> 3.3'] - s.add_development_dependency 'ruby_memcheck' - s.add_development_dependency 'yard' - s.add_development_dependency 'json' - s.add_development_dependency 'benchmark-ips', ['~> 2.10.0'] - - s.metadata["changelog_uri"] = "https://github.com/msgpack/msgpack-ruby/blob/master/ChangeLog" -end diff --git a/msgpack.org.md b/msgpack.org.md deleted file mode 100644 index 66af86d0..00000000 --- a/msgpack.org.md +++ /dev/null @@ -1,55 +0,0 @@ -# MessagePack for Ruby - -``` -require 'msgpack' -msg = [1,2,3].to_msgpack #=> "\x93\x01\x02\x03" -MessagePack.unpack(msg) #=> [1,2,3] -``` - -## Install - -Add msgpack to your Gemfile to install with Bundler: - -``` -# Gemfile -gem 'msgpack' -``` - -Or, use RubyGems to install: - -``` -gem install msgpack -``` - -## Use cases - -* Create REST API returing MessagePack using Rails + [RABL](https://github.com/nesquena/rabl) -* Store objects efficiently in memcached or Redis -* Upload data in efficient format from mobile devices. See also MessagePack for [Objective-C](https://github.com/msgpack/msgpack-objectivec) and [Java](https://github.com/msgpack/msgpack-java) - -## Links - -* [GitHub repo msgpack/msgpack-ruby](https://github.com/msgpack/msgpack-ruby) -* [API documentation](https://ruby.msgpack.org/) - -## Streaming API - -``` -# serialize a 2-element array [e1, e2] -pk = MessagePack::Packer.new(io) -pk.write_array_header(2).write(e1).write(e2).flush -``` - -``` -# deserialize objects from an IO -u = MessagePack::Unpacker.new(io) -u.each { |obj| ... } -``` - -``` -# event-driven deserialization -def on_read(data) - @u ||= MessagePack::Unpacker.new - @u.feed_each(data) { |obj| ... } -end -``` diff --git a/spec/bigint_spec.rb b/spec/bigint_spec.rb deleted file mode 100644 index 8e6829aa..00000000 --- a/spec/bigint_spec.rb +++ /dev/null @@ -1,26 +0,0 @@ -require 'spec_helper' - -describe MessagePack::Bigint do - it 'serialize and deserialize arbitrary sized integer' do - [ - 1, - -1, - 120938120391283122132313, - -21903120391203912391023920332103, - 210290021321301203912933021323, - ].each do |int| - expect(MessagePack::Bigint.from_msgpack_ext(MessagePack::Bigint.to_msgpack_ext(int))).to be == int - end - end - - it 'has a stable format' do - { - 120938120391283122132313 => "\x00\x9F\xF4UY\x11\x92\x9A?\x00\x00\x19\x9C".b, - -21903120391203912391023920332103 => "\x01/\xB2\xBDG\xBD\xDE\xAA\xEBt\xCC\x8A\xC1\x00\x00\x01\x14".b, - 210290021321301203912933021323 => "\x00\xC4\xD8\x96\x8Bm\xCB\xC7\x03\xA7{\xD4\"\x00\x00\x00\x02".b, - }.each do |int, payload| - expect(MessagePack::Bigint.to_msgpack_ext(int)).to be == payload - expect(MessagePack::Bigint.from_msgpack_ext(payload)).to be == int - end - end -end diff --git a/spec/cases.json b/spec/cases.json deleted file mode 100644 index fd390d48..00000000 --- a/spec/cases.json +++ /dev/null @@ -1 +0,0 @@ -[false,true,null,0,0,0,0,0,0,0,0,0,-1,-1,-1,-1,-1,127,127,255,65535,4294967295,-32,-32,-128,-32768,-2147483648,0.0,-0.0,1.0,-1.0,"a","a","a","","","",[0],[0],[0],[],[],[],{},{},{},{"a":97},{"a":97},{"a":97},[[]],[["a"]]] \ No newline at end of file diff --git a/spec/cases.msg b/spec/cases.msg deleted file mode 100644 index 5ec08c6a..00000000 Binary files a/spec/cases.msg and /dev/null differ diff --git a/spec/cases_compact.msg b/spec/cases_compact.msg deleted file mode 100644 index 8812442d..00000000 Binary files a/spec/cases_compact.msg and /dev/null differ diff --git a/spec/cases_spec.rb b/spec/cases_spec.rb deleted file mode 100644 index 6a71b41c..00000000 --- a/spec/cases_spec.rb +++ /dev/null @@ -1,39 +0,0 @@ -require 'spec_helper' -require 'json' - -describe MessagePack do - here = File.dirname(__FILE__) - CASES = File.read("#{here}/cases.msg") - CASES_JSON = File.read("#{here}/cases.json") - CASES_COMPACT = File.read("#{here}/cases_compact.msg") - - it 'compare with json' do - ms = [] - MessagePack::Unpacker.new.feed_each(CASES) {|m| - ms << m - } - - js = JSON.load(CASES_JSON) - - ms.zip(js) {|m,j| - m.should == j - } - end - - it 'compare with compat' do - ms = [] - MessagePack::Unpacker.new.feed_each(CASES) {|m| - ms << m - } - - cs = [] - MessagePack::Unpacker.new.feed_each(CASES_COMPACT) {|c| - cs << c - } - - ms.zip(cs) {|m,c| - m.should == c - } - end -end - diff --git a/spec/cruby/buffer_io_spec.rb b/spec/cruby/buffer_io_spec.rb deleted file mode 100644 index 3c012e84..00000000 --- a/spec/cruby/buffer_io_spec.rb +++ /dev/null @@ -1,255 +0,0 @@ -require 'spec_helper' -require 'random_compat' - -require 'stringio' -if defined?(Encoding) - Encoding.default_external = 'ASCII-8BIT' -end - -describe Buffer do - r = Random.new - random_seed = r.seed - puts "buffer_io random seed: 0x#{random_seed.to_s(16)}" - - let :source do - '' - end - - def set_source(s) - source.replace(s) - end - - let :io do - StringIO.new(source.dup) - end - - let :buffer do - Buffer.new(io) - end - - it 'io returns internal io' do - buffer.io.should == io - end - - it 'close closes internal io' do - expect(io).to receive(:close) - buffer.close - end - - it 'short feed and read all' do - set_source 'aa' - buffer.read.should == 'aa' - end - - it 'short feed and read short' do - set_source 'aa' - buffer.read(1).should == 'a' - buffer.read(1).should == 'a' - buffer.read(1).should == nil - end - - it 'long feed and read all' do - set_source ' '*(1024*1024) - s = buffer.read - s.size.should == source.size - s.should == source - end - - it 'long feed and read mixed' do - set_source ' '*(1024*1024) - buffer.read(10).should == source.slice!(0, 10) - buffer.read(10).should == source.slice!(0, 10) - buffer.read(10).should == source.slice!(0, 10) - s = buffer.read - s.size.should == source.size - s.should == source - end - - it 'eof' do - set_source '' - buffer.read.should == '' - end - - it 'eof 2' do - set_source 'a' - buffer.read.should == 'a' - buffer.read.should == '' - end - - it 'write short once and flush' do - buffer.write('aa') - buffer.flush - io.string.should == 'aa' - end - - it 'write short twice and flush' do - buffer.write('a') - buffer.write('a') - buffer.flush - io.string.should == 'aa' - end - - it 'write long once and flush' do - s = ' '*(1024*1024) - buffer.write s - buffer.flush - io.string.size.should == s.size - io.string.should == s - end - - it 'write short multi and flush' do - s = ' '*(1024*1024) - 1024.times { - buffer.write ' '*1024 - } - buffer.flush - io.string.size.should == s.size - io.string.should == s - end - - it 'random read' do - r = Random.new(random_seed) - - 50.times { - fragments = [] - - r.rand(4).times do - n = r.rand(1024*1400) - s = r.bytes(n) - fragments << s - end - - io = StringIO.new(fragments.join) - b = Buffer.new(io) - - fragments.each {|s| - x = b.read(s.size) - x.size.should == s.size - x.should == s - } - b.empty?.should == true - b.read.should == '' - } - end - - it 'random read_all' do - r = Random.new(random_seed) - - 50.times { - fragments = [] - r.bytes(0) - - r.rand(4).times do - n = r.rand(1024*1400) - s = r.bytes(n) - fragments << s - end - - io = StringIO.new(fragments.join) - b = Buffer.new(io) - - fragments.each {|s| - x = b.read_all(s.size) - x.size.should == s.size - x.should == s - } - b.empty?.should == true - lambda { - b.read_all(1) - }.should raise_error(EOFError) - } - end - - it 'random skip' do - r = Random.new(random_seed) - - 50.times { - fragments = [] - - r.rand(4).times do - n = r.rand(1024*1400) - s = r.bytes(n) - fragments << s - end - - io = StringIO.new(fragments.join) - b = Buffer.new(io) - - fragments.each {|s| - b.skip(s.size).should == s.size - } - b.empty?.should == true - b.skip(1).should == 0 - } - end - - it 'random skip_all' do - r = Random.new(random_seed) - - 50.times { - fragments = [] - - r.rand(4).times do - n = r.rand(1024*1400) - s = r.bytes(n) - fragments << s - end - - io = StringIO.new(fragments.join) - b = Buffer.new(io) - - fragments.each {|s| - lambda { - b.skip_all(s.size) - }.should_not raise_error - } - b.empty?.should == true - lambda { - b.skip_all(1) - }.should raise_error(EOFError) - } - end - - it 'random write and flush' do - r = Random.new(random_seed) - - 50.times { - s = r.bytes(0) - io = StringIO.new - b = Buffer.new(io) - - r.rand(4).times do - n = r.rand(1024*1400) - x = r.bytes(n) - s << x - b.write(x) - end - - (io.string.size + b.size).should == s.size - - b.flush - - io.string.size.should == s.size - io.string.should == s - } - end - - it 'random write and clear' do - r = Random.new(random_seed) - b = Buffer.new - - 50.times { - s = r.bytes(0) - - r.rand(4).times do - n = r.rand(1024*1400) - x = r.bytes(n) - s << x - b.write(x) - end - - b.size.should == s.size - b.clear - } - end -end diff --git a/spec/cruby/buffer_packer.rb b/spec/cruby/buffer_packer.rb deleted file mode 100644 index f9cd1dfd..00000000 --- a/spec/cruby/buffer_packer.rb +++ /dev/null @@ -1,29 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -require 'stringio' -if defined?(Encoding) - Encoding.default_external = 'ASCII-8BIT' -end - -describe Packer do - let :packer do - Packer.new - end - - it 'initialize' do - Packer.new - Packer.new(nil) - Packer.new(StringIO.new) - Packer.new({}) - Packer.new(StringIO.new, {}) - end - - it 'buffer' do - o1 = packer.buffer.object_id - packer.buffer << 'frsyuki' - packer.buffer.to_s.should == 'frsyuki' - packer.buffer.object_id.should == o1 - end -end - diff --git a/spec/cruby/buffer_spec.rb b/spec/cruby/buffer_spec.rb deleted file mode 100644 index 3ee0188e..00000000 --- a/spec/cruby/buffer_spec.rb +++ /dev/null @@ -1,608 +0,0 @@ -require 'spec_helper' -require 'random_compat' - -require 'stringio' -if defined?(Encoding) - Encoding.default_external = 'ASCII-8BIT' -end - -describe Buffer do - STATIC_EXAMPLES = {} - STATIC_EXAMPLES[:empty01] = '' - STATIC_EXAMPLES[:empty02] = '' - STATIC_EXAMPLES[:copy01] = 'short' - STATIC_EXAMPLES[:copy02] = 'short'*2 - STATIC_EXAMPLES[:ref01] = 'short'*128 - STATIC_EXAMPLES[:ref02] = 'short'*128*2 - STATIC_EXAMPLES[:ref03] = 'a'*((1024*1024+2)*2) - STATIC_EXAMPLES[:refcopy01] = 'short'*128 - STATIC_EXAMPLES[:expand01] = 'short'*1024 - STATIC_EXAMPLES[:expand02] = 'short'*(127+1024) - STATIC_EXAMPLES[:offset01] = 'ort'+'short' - STATIC_EXAMPLES[:offset02] = 'ort'+'short'*127 - STATIC_EXAMPLES[:offset03] = 'ort'+'short'*(126+1024) - - if ''.respond_to?(:force_encoding) - STATIC_EXAMPLES.each_value {|v| v.force_encoding('ASCII-8BIT') } - end - STATIC_EXAMPLES.each_value {|v| v.freeze } - - r = Random.new - random_seed = r.seed - puts "buffer random seed: 0x#{random_seed.to_s(16)}" - - let :random_cases_examples do - r = Random.new(random_seed) - cases = {} - examples = {} - - 10.times do |i| - b = Buffer.new - s = r.bytes(0) - r.rand(3).times do - n = r.rand(1024*1400) - x = r.bytes(n) - s << x - b << x - end - r.rand(2).times do - n = r.rand(1024*1400) - b.read(n) - s.slice!(0, n) - end - key = :"random#{"%02d" % i}" - cases[key] = b - examples[key] = s - end - - [cases, examples] - end - - let :static_cases do - map = {} - map[:empty01] = empty01 - map[:empty02] = empty02 - map[:copy01] = copy01 - map[:copy02] = copy02 - map[:ref01] = ref01 - map[:ref02] = ref02 - map[:ref03] = ref03 - map[:refcopy01] = refcopy01 - map[:expand01] = expand01 - map[:expand02] = expand02 - map[:offset01] = offset01 - map[:offset02] = offset02 - map[:offset03] = offset03 - map - end - - let :static_examples do - STATIC_EXAMPLES - end - - let :random_cases do - random_cases_examples[0] - end - - let :random_examples do - random_cases_examples[1] - end - - let :cases do - static_cases.merge(random_cases) - end - - let :examples do - static_examples.merge(random_examples) - end - - let :case_keys do - examples.keys - end - - let :empty01 do - Buffer.new - end - - let :empty02 do - b = Buffer.new - b << 'a' - b.read_all(1) - b - end - - let :copy01 do - # one copy chunk - b = Buffer.new - b << 'short' - b - end - - let :copy02 do - # one copy chunk - b = Buffer.new - b << 'short' - b << 'short' - b - end - - let :expand02 do - # one copy chunk / expanded - b = Buffer.new - 1024.times do - b << 'short' - end - b - end - - let :ref01 do - # one reference chunk - b = Buffer.new - b << 'short'*128 - b.to_s - b - end - - let :ref02 do - # two reference chunks - b = Buffer.new - b << 'short'*128 - b.to_s - b << 'short'*128 - b.to_a - b - end - - let :ref03 do - # two reference chunks - b = Buffer.new - b << 'a'*(1024*1024+2) - b << 'a'*(1024*1024+2) - b - end - - let :refcopy01 do - # one reference chunk + one copy chunk - b = Buffer.new - b << 'short'*127 - b.to_s - b << 'short' - b - end - - let :expand01 do - # one copy chunk / expanded - b = Buffer.new - 1024.times do - b << 'short' - end - b - end - - let :expand02 do - # one reference chunk + one copy chunk / expanded - b = Buffer.new - b << 'short'*127 - b.to_s - 1024.times do - b << 'short' - end - b - end - - let :offset01 do - # one copy chunk / offset - b = Buffer.new - b << 'short' - b << 'short' - b.skip(2) - b - end - - let :offset02 do - # one reference chunk / offset - b = Buffer.new - b << 'short'*127 - b.to_s - b.skip(2) - b << 'short' - b - end - - let :offset03 do - # one reference chunk / offset + one copy chunk / expanded - b = Buffer.new - b << 'short'*127 - b.to_s - 1024.times do - b << 'short' - end - b.skip(2) - b - end - - it 'empty?' do - empty01.empty?.should == true - empty02.empty?.should == true - end - - it 'size' do - case_keys.each {|k| - cases[k].size.should == examples[k].size - } - end - - it 'short write increments size' do - case_keys.each {|k| - sz = examples[k].size - 10.times do |i| - cases[k].write 'short' - sz += 'short'.size - cases[k].size.should == sz - end - } - end - - it 'read with limit decrements size' do - case_keys.each {|k| - sz = examples[k].size - next if sz < 2 - - cases[k].read(1).should == examples[k][0,1] - sz -= 1 - cases[k].size.should == sz - - cases[k].read(1).should == examples[k][1,1] - sz -= 1 - cases[k].size.should == sz - } - end - - it 'read_all with limit decrements size' do - case_keys.each {|k| - sz = examples[k].size - next if sz < 2 - - cases[k].read_all(1).should == examples[k][0,1] - sz -= 1 - cases[k].size.should == sz - - cases[k].read_all(1).should == examples[k][1,1] - sz -= 1 - cases[k].size.should == sz - } - end - - it 'skip decrements size' do - case_keys.each {|k| - sz = examples[k].size - next if sz < 2 - - cases[k].skip(1).should == 1 - sz -= 1 - cases[k].size.should == sz - - cases[k].skip(1).should == 1 - sz -= 1 - cases[k].size.should == sz - } - end - - it 'skip_all decrements size' do - case_keys.each {|k| - sz = examples[k].size - next if sz < 2 - - cases[k].skip_all(1) - sz -= 1 - cases[k].size.should == sz - - cases[k].skip_all(1) - sz -= 1 - cases[k].size.should == sz - } - end - - it 'read_all against insufficient buffer raises EOFError and consumes nothing' do - case_keys.each {|k| - sz = examples[k].size - lambda { - cases[k].read_all(sz+1) - }.should raise_error(EOFError) - cases[k].size.should == sz - } - end - - it 'skip_all against insufficient buffer raises EOFError and consumes nothing' do - case_keys.each {|k| - sz = examples[k].size - lambda { - cases[k].skip_all(sz+1) - }.should raise_error(EOFError) - cases[k].size.should == sz - } - end - - it 'read against insufficient buffer consumes all buffer or return nil' do - case_keys.each {|k| - sz = examples[k].size - if sz == 0 - cases[k].read(sz+1).should == nil - else - cases[k].read(sz+1).should == examples[k] - end - cases[k].size.should == 0 - } - end - - it 'skip against insufficient buffer consumes all buffer' do - case_keys.each {|k| - sz = examples[k].size - cases[k].skip(sz+1).should == examples[k].size - cases[k].size.should == 0 - } - end - - it 'read with no arguments consumes all buffer and returns string and do not return nil' do - case_keys.each {|k| - cases[k].read_all.should == examples[k] - cases[k].size.should == 0 - } - end - - it 'read_all with no arguments consumes all buffer and returns string' do - case_keys.each {|k| - cases[k].read_all.should == examples[k] - cases[k].size.should == 0 - } - end - - it 'to_s returns a string and consume nothing' do - case_keys.each {|k| - cases[k].to_s.should == examples[k] - cases[k].size.should == examples[k].size - } - end - - it 'to_s and modify' do - case_keys.each {|k| - s = cases[k].to_s - s << 'x' - cases[k].to_s.should == examples[k] - } - end - - it 'big write and modify reference' do - big2 = "a" * (1024*1024 + 2) - - case_keys.each {|k| - big1 = "a" * (1024*1024 + 2) - cases[k].write(big1) - big1 << 'x' - cases[k].read.should == examples[k] + big2 - } - end - - it 'big write -> short write' do - big1 = "a" * (1024*1024 + 2) - - case_keys.each {|k| - sz = examples[k].size - - cases[k].write big1 - cases[k].size.should == sz + big1.size - - cases[k].write("c") - cases[k].size.should == sz + big1.size + 1 - - cases[k].read_all.should == examples[k] + big1 + "c" - cases[k].size.should == 0 - cases[k].empty?.should == true - } - end - - it 'big write 2'do - big1 = "a" * (1024*1024 + 2) - big2 = "b" * (1024*1024 + 2) - - case_keys.each {|k| - sz = examples[k].size - - cases[k].write big1 - cases[k].write big2 - cases[k].size.should == sz + big1.size + big2.size - - cases[k].read_all(sz + big1.size).should == examples[k] + big1 - cases[k].size.should == big2.size - - cases[k].read.should == big2 - cases[k].size.should == 0 - cases[k].empty?.should == true - } - end - - it 'read 0' do - case_keys.each {|k| - cases[k].read(0).should == '' - cases[k].read.should == examples[k] - } - end - - it 'skip 0' do - case_keys.each {|k| - cases[k].skip(0).should == 0 - cases[k].read.should == examples[k] - } - end - - it 'read_all 0' do - case_keys.each {|k| - cases[k].read_all(0).should == '' - cases[k].read_all.should == examples[k] - } - end - - it 'skip_all 0' do - case_keys.each {|k| - cases[k].skip_all(0) - cases[k].read_all.should == examples[k] - } - end - - it 'write_to' do - case_keys.each {|k| - sio = StringIO.new - cases[k].write_to(sio).should == examples[k].size - cases[k].size.should == 0 - sio.string.should == examples[k] - } - end - - it 'random read/write' do - r = Random.new(random_seed) - s = r.bytes(0) - b = Buffer.new - - 10.times { - # write - r.rand(4).times do - n = r.rand(1024*1400) - x = r.bytes(n) - s << x - b.write(x) - end - - # read - r.rand(3).times do - n = r.rand(1024*1400) - ex = s.slice!(0, n) - ex = nil if ex.empty? - x = b.read(n) - x.size == ex.size if x != nil - x.should == ex - b.size.should == s.size - end - } - end - - it 'random read_all/write' do - r = Random.new(random_seed) - s = r.bytes(0) - b = Buffer.new - - 10.times { - # write - r.rand(4).times do - n = r.rand(1024*1400) - x = r.bytes(n) - s << x - b.write(x) - end - - # read_all - r.rand(3).times do - n = r.rand(1024*1400) - begin - x = b.read_all(n) - ex = s.slice!(0, n) - x.size == n - x.should == ex - b.size.should == s.size - rescue EOFError - b.size.should == s.size - b.read.should == s - s.clear - break - end - end - } - end - - it 'random skip write' do - r = Random.new(random_seed) - s = r.bytes(0) - b = Buffer.new - - 10.times { - # write - r.rand(4).times do - n = r.rand(1024*1400) - x = r.bytes(n) - s << x - b.write(x) - end - - # skip - r.rand(3).times do - n = r.rand(1024*1400) - ex = s.slice!(0, n) - b.skip(n).should == ex.size - b.size.should == s.size - end - } - end - - it 'random skip_all write' do - r = Random.new(random_seed) - s = r.bytes(0) - b = Buffer.new - - 10.times { - # write - r.rand(4).times do - n = r.rand(1024*1400) - x = r.bytes(n) - s << x - b.write(x) - end - - # skip_all - r.rand(3).times do - n = r.rand(1024*1400) - begin - b.skip_all(n) - s.slice!(0, n) - b.size.should == s.size - ensure EOFError - b.size.should == s.size - b.read.should == s - s.clear - break - end - end - } - end - - it "defines a function for ObjectSpace.memsize_of" do - skip "JRuby doesn't support ObjectSpace.memsize_of" if IS_JRUBY - - buffer = MessagePack::Buffer.new - empty_size = ObjectSpace.memsize_of(buffer) - expect(empty_size).to be < 400 - 10.times do - buffer << "a" * 500 - end - memsize = ObjectSpace.memsize_of(buffer) - expect(memsize).to be > empty_size - buffer.read(10) - expect(ObjectSpace.memsize_of(buffer)).to be == memsize - buffer.read_all - expect(ObjectSpace.memsize_of(buffer)).to be == empty_size - end - - it "doesn't allow #dup or #clone" do - expect(subject).to_not respond_to :dup - expect(subject).to_not respond_to :clone - end - - it "doesn't crash when marking an uninitialized buffer" do - stress = GC.stress - begin - GC.stress = true - - MessagePack::Buffer.new - ensure - GC.stress = stress - end - end -end diff --git a/spec/cruby/buffer_unpacker.rb b/spec/cruby/buffer_unpacker.rb deleted file mode 100644 index 2d1f0a3c..00000000 --- a/spec/cruby/buffer_unpacker.rb +++ /dev/null @@ -1,19 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -describe Unpacker do - let :unpacker do - Unpacker.new - end - - let :packer do - Packer.new - end - - it 'buffer' do - o1 = unpacker.buffer.object_id - unpacker.buffer << 'frsyuki' - unpacker.buffer.to_s.should == 'frsyuki' - unpacker.buffer.object_id.should == o1 - end -end diff --git a/spec/cruby/unpacker_spec.rb b/spec/cruby/unpacker_spec.rb deleted file mode 100644 index 2f55c4d1..00000000 --- a/spec/cruby/unpacker_spec.rb +++ /dev/null @@ -1,70 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -describe Unpacker do - let :unpacker do - Unpacker.new - end - - let :packer do - Packer.new - end - - it 'skip_nil succeeds' do - unpacker.feed("\xc0") - unpacker.skip_nil.should == true - end - - it 'skip_nil fails' do - unpacker.feed("\x90") - unpacker.skip_nil.should == false - end - - it 'skip skips objects' do - packer.write(1) - packer.write(2) - packer.write(3) - packer.write(4) - packer.write(5) - - unpacker = Unpacker.new - unpacker.feed(packer.to_s) - - unpacker.read.should == 1 - unpacker.skip - unpacker.read.should == 3 - unpacker.skip - unpacker.read.should == 5 - end - - it 'skip raises EOFError' do - lambda { - unpacker.skip - }.should raise_error(EOFError) - end - - it 'skip_nil raises EOFError' do - lambda { - unpacker.skip_nil - }.should raise_error(EOFError) - end - - it 'skip raises level stack too deep error' do - 512.times { packer.write_array_header(1) } - packer.write(nil) - - unpacker = Unpacker.new - unpacker.feed(packer.to_s) - lambda { - unpacker.skip - }.should raise_error(MessagePack::StackError) - end - - it 'skip raises invalid byte error' do - unpacker.feed("\xc1") - lambda { - unpacker.skip - }.should raise_error(MessagePack::MalformedFormatError) - end -end - diff --git a/spec/ext_value_spec.rb b/spec/ext_value_spec.rb deleted file mode 100644 index eb0447c8..00000000 --- a/spec/ext_value_spec.rb +++ /dev/null @@ -1,99 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -describe MessagePack::ExtensionValue do - subject do - described_class.new(1, "data") - end - - describe '#type/#type=' do - it 'returns value set by #initialize' do - subject.type.should == 1 - end - - it 'assigns a value' do - subject.type = 2 - subject.type.should == 2 - end - end - - describe '#payload/#payload=' do - it 'returns value set by #initialize' do - subject.payload.should == "data" - end - - it 'assigns a value' do - subject.payload = "a" - subject.payload.should == "a" - end - end - - describe '#==/#eql?/#hash' do - it 'returns equivalent if the content is same' do - ext1 = MessagePack::ExtensionValue.new(1, "data") - ext2 = MessagePack::ExtensionValue.new(1, "data") - (ext1 == ext2).should be true - ext1.eql?(ext2).should be true - (ext1.hash == ext2.hash).should be true - end - - it 'returns not equivalent if type is not same' do - ext1 = MessagePack::ExtensionValue.new(1, "data") - ext2 = MessagePack::ExtensionValue.new(2, "data") - (ext1 == ext2).should be false - ext1.eql?(ext2).should be false - (ext1.hash == ext2.hash).should be false - end - - it 'returns not equivalent if payload is not same' do - ext1 = MessagePack::ExtensionValue.new(1, "data") - ext2 = MessagePack::ExtensionValue.new(1, "value") - (ext1 == ext2).should be false - ext1.eql?(ext2).should be false - (ext1.hash == ext2.hash).should be false - end - end - - describe '#to_msgpack' do - it 'serializes very short payload' do - ext = MessagePack::ExtensionValue.new(1, "a"*2).to_msgpack - ext.should == "\xd5\x01" + "a"*2 - end - - it 'serializes short payload' do - ext = MessagePack::ExtensionValue.new(1, "a"*18).to_msgpack - ext.should == "\xc7\x12\x01" + "a"*18 - end - - it 'serializes long payload' do - ext = MessagePack::ExtensionValue.new(1, "a"*65540).to_msgpack - ext.should == "\xc9\x00\x01\x00\x04\x01" + "a"*65540 - end - - it 'with a packer serializes to a packer' do - ext = MessagePack::ExtensionValue.new(1, "aa") - packer = MessagePack::Packer.new - ext.to_msgpack(packer) - packer.buffer.to_s.should == "\xd5\x01aa" - end - - [-129, -65540, -(2**40), 128, 65540, 2**40].each do |type| - context "with invalid type (#{type})" do - it 'raises RangeError' do - lambda { MessagePack::ExtensionValue.new(type, "a").to_msgpack }.should raise_error(RangeError) - end - end - end - end - - describe '#dup' do - it 'duplicates' do - ext1 = MessagePack::ExtensionValue.new(1, "data") - ext2 = ext1.dup - ext2.type = 2 - ext2.payload = "data2" - ext1.type.should == 1 - ext1.payload.should == "data" - end - end -end diff --git a/spec/exttypes.rb b/spec/exttypes.rb deleted file mode 100644 index b4abaaf3..00000000 --- a/spec/exttypes.rb +++ /dev/null @@ -1,51 +0,0 @@ -class DummyTimeStamp1 - TYPE = 15 - - attr_reader :utime, :usec, :time - - def initialize(utime, usec) - @utime = utime - @usec = usec - @time = Time.at(utime, usec) - end - - def ==(other) - self.utime == other.utime && self.usec == other.usec - end - - def self.type_id - 15 - end - - def self.from_msgpack_ext(data) - new(*data.unpack('I*')) - end - - def to_msgpack_ext - [@utime,@usec].pack('I*') - end -end - -class DummyTimeStamp2 - TYPE = 16 - - attr_reader :utime, :usec, :time - - def initialize(utime, usec) - @utime = utime - @usec = usec - @time = Time.at(utime, usec) - end - - def ==(other) - self.utime == other.utime && self.usec == other.usec - end - - def self.deserialize(data) - new(* data.split(',', 2).map(&:to_i)) - end - - def serialize - [@utime,@usec].map(&:to_s).join(',') - end -end diff --git a/spec/factory_spec.rb b/spec/factory_spec.rb deleted file mode 100644 index 25bea66f..00000000 --- a/spec/factory_spec.rb +++ /dev/null @@ -1,794 +0,0 @@ -require 'spec_helper' - -describe MessagePack::Factory do - subject do - described_class.new - end - - describe '#packer' do - it 'creates a Packer instance' do - subject.packer.should be_kind_of(MessagePack::Packer) - end - - it 'creates new instance' do - subject.packer.object_id.should_not == subject.packer.object_id - end - end - - describe '#unpacker' do - it 'creates a Unpacker instance' do - subject.unpacker.should be_kind_of(MessagePack::Unpacker) - end - - it 'creates new instance' do - subject.unpacker.object_id.should_not == subject.unpacker.object_id - end - - it 'creates unpacker with symbolize_keys option' do - unpacker = subject.unpacker(symbolize_keys: true) - unpacker.feed(MessagePack.pack({'k'=>'v'})) - unpacker.read.should == {:k => 'v'} - end - - it 'creates unpacker with allow_unknown_ext option' do - unpacker = subject.unpacker(allow_unknown_ext: true) - unpacker.feed(MessagePack::ExtensionValue.new(1, 'a').to_msgpack) - unpacker.read.should == MessagePack::ExtensionValue.new(1, 'a') - end - - it 'creates unpacker without allow_unknown_ext option' do - unpacker = subject.unpacker - unpacker.feed(MessagePack::ExtensionValue.new(1, 'a').to_msgpack) - expect{ unpacker.read }.to raise_error(MessagePack::UnknownExtTypeError) - end - - it 'does not share the extension registry with unpackers' do - subject.register_type(0x00, Symbol) - expect do - unpacker = subject.unpacker - expect do - unpacker.register_type(0x01) {} - end.to change { unpacker.registered_types } - - second_unpacker = subject.unpacker - expect do - second_unpacker.register_type(0x01) {} - end.to_not change { unpacker.registered_types } - end.to_not change { subject.registered_types } - end - end - - describe '#dump and #load' do - it 'can be used like a standard coder' do - subject.register_type(0x00, Symbol) - expect(subject.load(subject.dump(:symbol))).to be == :symbol - end - - it 'is alias as pack and unpack' do - subject.register_type(0x00, Symbol) - expect(subject.unpack(subject.pack(:symbol))).to be == :symbol - end - - it 'accept options' do - hash = subject.unpack(MessagePack.pack('k' => 'v'), symbolize_keys: true) - expect(hash).to be == { k: 'v' } - end - end - - describe '#freeze' do - it 'can freeze factory instance to deny new registrations anymore' do - subject.register_type(0x00, Symbol) - subject.freeze - expect(subject.frozen?).to be_truthy - expect{ subject.register_type(0x01, Array) }.to raise_error(FrozenError, "can't modify frozen MessagePack::Factory") - end - end - - class MyType - def initialize(a, b) - @a = a - @b = b - end - - attr_reader :a, :b - - def to_msgpack_ext - [a, b].pack('CC') - end - - def self.from_msgpack_ext(data) - new(*data.unpack('CC')) - end - - def to_msgpack_ext_only_a - [a, 0].pack('CC') - end - - def self.from_msgpack_ext_only_b(data) - a, b = *data.unpack('CC') - new(0, b) - end - end - - class MyType2 < MyType - end - - describe '#registered_types' do - it 'returns Array' do - expect(subject.registered_types).to be_instance_of(Array) - end - - it 'returns Array of Hash contains :type, :class, :packer, :unpacker' do - subject.register_type(0x20, ::MyType) - subject.register_type(0x21, ::MyType2) - - list = subject.registered_types - - expect(list.size).to eq(2) - expect(list[0]).to be_instance_of(Hash) - expect(list[1]).to be_instance_of(Hash) - expect(list[0].keys.sort).to eq([:type, :class, :packer, :unpacker].sort) - expect(list[1].keys.sort).to eq([:type, :class, :packer, :unpacker].sort) - - expect(list[0][:type]).to eq(0x20) - expect(list[0][:class]).to eq(::MyType) - expect(list[0][:packer]).to be_a(Proc) - expect(list[0][:unpacker]).to be_a(Proc) - - expect(list[1][:type]).to eq(0x21) - expect(list[1][:class]).to eq(::MyType2) - expect(list[1][:packer]).to be_a(Proc) - expect(list[1][:unpacker]).to be_a(Proc) - end - - it 'returns Array of Hash which has nil for unregistered feature' do - subject.register_type(0x20, ::MyType, packer: :to_msgpack_ext) - subject.register_type(0x21, ::MyType2, unpacker: :from_msgpack_ext) - - list = subject.registered_types - - expect(list.size).to eq(2) - expect(list[0]).to be_instance_of(Hash) - expect(list[1]).to be_instance_of(Hash) - expect(list[0].keys.sort).to eq([:type, :class, :packer, :unpacker].sort) - expect(list[1].keys.sort).to eq([:type, :class, :packer, :unpacker].sort) - - expect(list[0][:type]).to eq(0x20) - expect(list[0][:class]).to eq(::MyType) - expect(list[0][:packer]).to be_a(Proc) - expect(list[0][:unpacker]).to be_nil - - expect(list[1][:type]).to eq(0x21) - expect(list[1][:class]).to eq(::MyType2) - expect(list[1][:packer]).to be_nil - expect(list[1][:unpacker]).to be_a(Proc) - - list = subject.registered_types(:packer) - expect(list.size).to eq(1) - expect(list[0]).to be_instance_of(Hash) - expect(list[0].keys.sort).to eq([:type, :class, :packer].sort) - - expect(list[0][:type]).to eq(0x20) - expect(list[0][:class]).to eq(::MyType) - expect(list[0][:packer]).to be_a(Proc) - - list = subject.registered_types(:unpacker) - expect(list.size).to eq(1) - expect(list[0]).to be_instance_of(Hash) - expect(list[0].keys.sort).to eq([:type, :class, :unpacker].sort) - - expect(list[0][:type]).to eq(0x21) - expect(list[0][:class]).to eq(::MyType2) - expect(list[0][:unpacker]).to be_a(Proc) - end - end - - describe '#type_registered?' do - it 'receive Class or Integer, and return bool' do - expect(subject.type_registered?(0x00)).to be_falsy - expect(subject.type_registered?(0x01)).to be_falsy - expect(subject.type_registered?(::MyType)).to be_falsy - end - - it 'has option to specify what types are registered for' do - expect(subject.type_registered?(0x00, :both)).to be_falsy - expect(subject.type_registered?(0x00, :packer)).to be_falsy - expect(subject.type_registered?(0x00, :unpacker)).to be_falsy - expect{ subject.type_registered?(0x00, :something) }.to raise_error(ArgumentError) - end - - it 'returns true if specified type or class is already registered' do - subject.register_type(0x20, ::MyType) - subject.register_type(0x21, ::MyType2) - - expect(subject.type_registered?(0x00)).to be_falsy - expect(subject.type_registered?(0x01)).to be_falsy - - expect(subject.type_registered?(0x20)).to be_truthy - expect(subject.type_registered?(0x21)).to be_truthy - expect(subject.type_registered?(::MyType)).to be_truthy - expect(subject.type_registered?(::MyType2)).to be_truthy - end - end - - describe '#register_type' do - let :src do - ::MyType.new(1, 2) - end - - it 'registers #to_msgpack_ext and .from_msgpack_ext by default' do - subject.register_type(0x7f, ::MyType) - - data = subject.packer.write(src).to_s - my = subject.unpacker.feed(data).read - my.a.should == 1 - my.b.should == 2 - end - - it 'registers custom packer method name' do - subject.register_type(0x7f, ::MyType, packer: :to_msgpack_ext_only_a, unpacker: :from_msgpack_ext) - - data = subject.packer.write(src).to_s - my = subject.unpacker.feed(data).read - my.a.should == 1 - my.b.should == 0 - end - - it 'registers custom unpacker method name' do - subject.register_type(0x7f, ::MyType, packer: :to_msgpack_ext, unpacker: 'from_msgpack_ext_only_b') - - data = subject.packer.write(src).to_s - my = subject.unpacker.feed(data).read - my.a.should == 0 - my.b.should == 2 - end - - it 'registers custom proc objects' do - pk = lambda {|obj| [obj.a + obj.b].pack('C') } - uk = lambda {|data| ::MyType.new(data.unpack('C').first, -1) } - subject.register_type(0x7f, ::MyType, packer: pk, unpacker: uk) - - data = subject.packer.write(src).to_s - my = subject.unpacker.feed(data).read - my.a.should == 3 - my.b.should == -1 - end - - it 'does not affect existent packer and unpackers' do - subject.register_type(0x7f, ::MyType) - packer = subject.packer - unpacker = subject.unpacker - - subject.register_type(0x7f, ::MyType, packer: :to_msgpack_ext_only_a, unpacker: :from_msgpack_ext_only_b) - - data = packer.write(src).to_s - my = unpacker.feed(data).read - my.a.should == 1 - my.b.should == 2 - end - - it 'handles Symbol type with `packer: nil`' do - factory = MessagePack::Factory.new - factory.register_type(0x00, Symbol, packer: nil) - expect(factory.load(factory.dump(:foo))).to be == "foo" - end - - describe "registering multiple ext type for the same class" do - let(:payload) do - factory = MessagePack::Factory.new - factory.register_type(0x01, Symbol, packer: :to_s, unpacker: :to_sym.to_proc) - factory.dump(:foobar) - end - - it "select the type based on code for deserialization" do - factory = MessagePack::Factory.new - factory.register_type(0x00, Symbol, packer: -> (value) { raise NotImplementedError }, unpacker: -> (value) { raise NotImplementedError }) - factory.register_type(0x01, Symbol, packer: :to_s, unpacker: :to_sym.to_proc) - factory.register_type(0x02, Symbol, packer: -> (value) { raise NotImplementedError }, unpacker: -> (value) { raise NotImplementedError }) - - expect(factory.load(payload)).to be == :foobar - end - - it "uses the last registered packer for serialization" do - factory = MessagePack::Factory.new - factory.register_type(0x00, Symbol, packer: -> (value) { raise NotImplementedError }, unpacker: -> (value) { raise NotImplementedError }) - factory.register_type(0x02, Symbol, packer: -> (value) { raise NotImplementedError }, unpacker: -> (value) { raise NotImplementedError }) - factory.register_type(0x01, Symbol, packer: :to_s, unpacker: :to_sym.to_proc) - - expect(factory.dump(:foobar)).to be == payload - end - end - - describe "registering an ext type for a module" do - before do - mod = Module.new do - def self.from_msgpack_ext(data) - "unpacked #{data}" - end - - def to_msgpack_ext - 'value_msgpacked' - end - end - stub_const('Mod', mod) - end - let(:factory) { described_class.new } - before { factory.register_type(0x01, Mod) } - - describe "packing an object whose class included the module" do - subject { factory.packer.pack(value).to_s } - before { stub_const('Value', Class.new{ include Mod }) } - let(:value) { Value.new } - it { is_expected.to eq "\xC7\x0F\x01value_msgpacked".force_encoding(Encoding::BINARY) } - end - - describe "packing an object which has been extended by the module" do - subject { factory.packer.pack(object).to_s } - let(:object) { Object.new.extend Mod } - it { is_expected.to eq "\xC7\x0F\x01value_msgpacked".force_encoding(Encoding::BINARY) } - end - - describe "unpacking with the module" do - subject { factory.unpacker.feed("\xC7\x06\x01module".force_encoding(Encoding::BINARY)).unpack } - it { is_expected.to eq "unpacked module" } - end - end - - describe "registering an ext type for Integer" do - let(:factory) { described_class.new } - let(:bigint) { 10**150 } - - it 'does not work by default without passing `oversized_integer_extension: true`' do - factory.register_type(0x01, Integer, packer: :to_s, unpacker: method(:Integer)) - - expect do - factory.dump(bigint) - end.to raise_error RangeError - end - - it 'raises ArgumentError if the type is not Integer' do - expect do - factory.register_type(0x01, MyType, packer: :to_s, unpacker: method(:Integer), oversized_integer_extension: true) - end.to raise_error(ArgumentError) - end - - it 'invokes the packer if registered with `oversized_integer_extension: true`' do - factory.register_type(0x01, Integer, packer: :to_s, unpacker: method(:Integer), oversized_integer_extension: true) - - expect(factory.load(factory.dump(bigint))).to be == bigint - end - - it 'does not use the oversized_integer_extension packer for integers fitting in native types' do - factory.register_type( - 0x01, - Integer, - packer: ->(int) { raise NotImplementedError }, - unpacker: ->(payload) { raise NotImplementedError }, - oversized_integer_extension: true - ) - - expect(factory.dump(42)).to eq(MessagePack.dump(42)) - end - end - - describe "registering ext type with recursive serialization" do - before do - stub_const("Point", Struct.new(:x, :y, :z)) - end - - it 'can receive the packer as argument (proc)' do - factory = MessagePack::Factory.new - factory.register_type(0x00, Symbol) - factory.register_type( - 0x01, - Point, - packer: ->(point, packer) do - packer.write(point.to_h) - nil - end, - unpacker: ->(unpacker) do - attrs = unpacker.read - Point.new(attrs.fetch(:x), attrs.fetch(:y), attrs.fetch(:z)) - end, - recursive: true, - ) - - point = Point.new(1, 2, 3) - payload = factory.dump(point) - expect(factory.load(payload)).to be == point - end - - it 'can receive the packer as argument (Method)' do - mod = Module.new - mod.define_singleton_method(:packer) do |point, packer| - packer.write(point.to_h) - nil - end - - mod.define_singleton_method(:unpacker) do |unpacker| - attrs = unpacker.read - Point.new(attrs.fetch(:x), attrs.fetch(:y), attrs.fetch(:z)) - end - - factory = MessagePack::Factory.new - factory.register_type(0x00, Symbol) - factory.register_type( - 0x01, - Point, - packer: mod.method(:packer), - unpacker: mod.method(:unpacker), - recursive: true, - ) - - point = Point.new(1, 2, 3) - payload = factory.dump(point) - expect(factory.load(payload)).to be == point - end - - it 'respect message pack format' do - factory = MessagePack::Factory.new - factory.register_type(0x00, Symbol) - factory.register_type( - 0x01, - Point, - packer: ->(point, packer) do - packer.write(point.to_a) - nil - end, - unpacker: ->(unpacker) do - attrs = unpacker.read - Point.new(*attrs) - end, - recursive: true, - ) - - point = Point.new(1, 2, 3) - expect(factory.dump(point)).to be == "\xD6\x01".b + MessagePack.dump([1, 2, 3]) - end - - it 'sets the correct length' do - factory = MessagePack::Factory.new - factory.register_type(0x00, Symbol) - factory.register_type( - 0x01, - Point, - packer: ->(point, packer) do - packer.write(point.to_h) - nil - end, - unpacker: ->(unpacker) do - attrs = unpacker.read - Point.new(attrs.fetch(:x), attrs.fetch(:y), attrs.fetch(:z)) - end, - recursive: true, - ) - - point = Point.new(1, 2, 3) - payload = factory.dump([1, point, 3]) - - obj = MessagePack::Factory.new.load(payload, allow_unknown_ext: true) - expect(obj).to be == [ - 1, - MessagePack::ExtensionValue.new(1, factory.dump(x: 1, y: 2, z: 3)), - 3, - ] - - expect(factory.load(payload)).to be == [ - 1, - Point.new(1, 2, 3), - 3, - ] - end - - it 'can be nested' do - factory = MessagePack::Factory.new - factory.register_type( - 0x02, - Set, - packer: ->(set, packer) do - packer.write(set.to_a) - nil - end, - unpacker: ->(unpacker) do - unpacker.read.to_set - end, - recursive: true, - ) - - expected = Set[1, Set[2, Set[3]]] - payload = factory.dump(expected) - expect(payload).to be == "\xC7\v\x02\x92\x01\xC7\x06\x02\x92\x02\xD5\x02\x91\x03".b - expect(factory.load(factory.dump(expected))).to be == expected - end - end - end - - describe 'the special treatment of symbols with ext type' do - def roundtrip(object, options = nil) - subject.load(subject.dump(object), options) - end - - context 'using the optimized symbol unpacker' do - before do - skip if IS_JRUBY # JRuby implementation doesn't support the optimized symbols unpacker for now - subject.register_type( - 0x00, - ::Symbol, - packer: :to_msgpack_ext, - unpacker: :from_msgpack_ext, - optimized_symbols_parsing: true, - ) - end - - it 'lets symbols survive a roundtrip' do - expect(roundtrip(:symbol)).to be :symbol - end - - it 'works with empty symbol' do - expect(roundtrip(:"")).to be :"" - end - - it 'preserves encoding for ASCII symbols' do - expect(:symbol.encoding).to be Encoding::US_ASCII - expect(roundtrip(:symbol)).to be :symbol - expect(roundtrip(:symbol).encoding).to be Encoding::US_ASCII - end - - it 'preserves encoding for UTF-8 symbols' do - expect(:"fée".encoding).to be Encoding::UTF_8 - expect(roundtrip(:"fée").encoding).to be Encoding::UTF_8 - expect(roundtrip(:"fée")).to be :"fée" - end - end - - context 'if no ext type is registered for symbols' do - it 'converts symbols to string' do - expect(roundtrip(:symbol)).to eq 'symbol' - end - end - - context 'if an ext type is registered for symbols' do - context 'if using the default serializer' do - before { subject.register_type(0x00, ::Symbol) } - - it 'lets symbols survive a roundtrip' do - expect(roundtrip(:symbol)).to be :symbol - end - - it 'works with hash keys' do - expect(roundtrip(symbol: 1)).to be == { symbol: 1 } - end - - it 'works with frozen: true option' do - expect(roundtrip(:symbol, freeze: true)).to be :symbol - end - - it 'preserves encoding for ASCII symbols' do - expect(:symbol.encoding).to be Encoding::US_ASCII - expect(roundtrip(:symbol)).to be :symbol - expect(roundtrip(:symbol).encoding).to be Encoding::US_ASCII - end - - it 'preserves encoding for UTF-8 symbols' do - expect(:"fée".encoding).to be Encoding::UTF_8 - expect(roundtrip(:"fée")).to be :"fée" - expect(roundtrip(:"fée").encoding).to be Encoding::UTF_8 - end - - it 'does not handle symbols in other encodings' do - symbol = "fàe".encode(Encoding::ISO_8859_1).to_sym - expect(symbol.encoding).to be Encoding::ISO_8859_1 - - if IS_JRUBY - # JRuby doesn't quite behave like MRI here. - # "fàe".force_encoding(Encoding::BINARY).to_sym is able to lookup the existing ISO-8859-1 symbol - # It likely is a JRuby bug. - expect(roundtrip(symbol).encoding).to be Encoding::ISO_8859_1 - else - expect(roundtrip(symbol).encoding).to be Encoding::BINARY - end - end - end - - context 'if using a custom serializer' do - before do - class Symbol - alias_method :to_msgpack_ext_orig, :to_msgpack_ext - def to_msgpack_ext - self.to_s.codepoints.to_a.pack('n*') - end - end - - class << Symbol - alias_method :from_msgpack_ext_orig, :from_msgpack_ext - def from_msgpack_ext(data) - data.unpack('n*').map(&:chr).join.to_sym - end - end - end - - before { subject.register_type(0x00, ::Symbol) } - - it 'lets symbols survive a roundtrip' do - expect(roundtrip(:symbol)).to be :symbol - end - - after do - class Symbol - alias_method :to_msgpack_ext, :to_msgpack_ext_orig - end - - class << Symbol - alias_method :from_msgpack_ext, :from_msgpack_ext_orig - end - end - end - end - end - - describe 'under stressful GC' do - it 'works well' do - begin - GC.stress = true - - f = MessagePack::Factory.new - f.register_type(0x0a, Symbol) - ensure - GC.stress = false - end - end - - it 'does not crash in recursive extensions' do - my_hash_type = Class.new(Hash) - factory = MessagePack::Factory.new - factory.register_type(7, - my_hash_type, - packer: ->(value, packer) do - packer.write(value.to_h) - end, - unpacker: ->(unpacker) { my_hash_type.new(unpacker.read) }, - recursive: true, - ) - - payload = factory.dump( - [my_hash_type.new] - ) - - begin - GC.stress = true - factory.load(payload) - ensure - GC.stress = false - end - end - end - - describe 'memsize' do - it 'works on a fresh factory' do - skip "JRuby doesn't support ObjectSpace.memsize_of" if IS_JRUBY - - f = MessagePack::Factory.new - expect(ObjectSpace.memsize_of(f)).to be_an(Integer) - end - - it 'works on a factory with registered types' do - skip "JRuby doesn't support ObjectSpace.memsize_of" if IS_JRUBY - - f = MessagePack::Factory.new - base_size = ObjectSpace.memsize_of(f) - f.register_type(0x0a, Symbol) - expect(ObjectSpace.memsize_of(f)).to be > base_size - end - end - - describe 'DefaultFactory' do - it 'is a factory' do - MessagePack::DefaultFactory.should be_kind_of(MessagePack::Factory) - end - - require_relative 'exttypes' - - it 'should be referred by MessagePack.pack and MessagePack.unpack' do - MessagePack::DefaultFactory.register_type(DummyTimeStamp1::TYPE, DummyTimeStamp1) - MessagePack::DefaultFactory.register_type(DummyTimeStamp2::TYPE, DummyTimeStamp2, packer: :serialize, unpacker: :deserialize) - - t = Time.now - - dm1 = DummyTimeStamp1.new(t.to_i, t.usec) - expect(MessagePack.unpack(MessagePack.pack(dm1))).to eq(dm1) - - dm2 = DummyTimeStamp1.new(t.to_i, t.usec) - expect(MessagePack.unpack(MessagePack.pack(dm2))).to eq(dm2) - end - end - - describe '#pool' do - let(:factory) { described_class.new } - - it 'responds to serializers interface' do - pool = factory.pool(1) - expect(pool.load(pool.dump(42))).to be == 42 - end - - it 'responds to #packer with a block' do - pool = factory.pool(1) - payload = pool.packer do |packer| - packer.write(42) - packer.full_pack - end - expect(payload).to be == factory.dump(42) - end - - it 'responds to #unpacker with a block' do - pool = factory.pool(1) - payload = factory.dump(42) - - object = pool.unpacker do |unpacker| - unpacker.feed(payload) - unpacker.read - end - expect(object).to be == 42 - end - - it '#packer does not allow to register types' do - pool = factory.pool(1) - expect do - pool.packer do |packer| - packer.register_type(0x20, ::MyType) { "type" } - end - end.to raise_error(FrozenError, "can't modify frozen MessagePack::Packer") - end - - it '#unpacker does not allow to register types' do - pool = factory.pool(1) - expect do - pool.unpacker do |unpacker| - unpacker.register_type(0x20, ::MyType) { "type" } - end - end.to raise_error(FrozenError, "can't modify frozen MessagePack::Unpacker") - end - - it 'types can be registered before the pool is created' do - factory.register_type(0x00, Symbol) - pool = factory.pool(1) - expect(pool.load(pool.dump(:foo))).to be == :foo - end - - it 'types cannot be registered after the pool is created' do - pool = factory.pool(1) - factory.register_type(0x20, ::MyType) - - expect do - pool.dump(MyType.new(1, 2)) - end.to raise_error NoMethodError - - payload = factory.dump(MyType.new(1, 2)) - expect do - pool.load(payload) - end.to raise_error MessagePack::UnknownExtTypeError - end - - it 'support symbolize_keys: true' do - pool = factory.pool(1, symbolize_keys: true) - expect(pool.load(pool.dump('foo' => 1))).to be == { foo: 1 } - end - - it 'support freeze: true' do - pool = factory.pool(1, freeze: true) - expect(pool.load(pool.dump('foo'))).to be_frozen - end - - it 'is thread safe' do - pool = factory.pool(1) - - threads = 10.times.map do - Thread.new do - 1_000.times do |i| - expect(pool.load(pool.dump(i))).to be == i - end - end - end - threads.each(&:join) - end - end -end diff --git a/spec/format_spec.rb b/spec/format_spec.rb deleted file mode 100644 index d416eaac..00000000 --- a/spec/format_spec.rb +++ /dev/null @@ -1,301 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -describe MessagePack do - it "nil" do - check 1, nil - end - - it "true" do - check 1, true - end - - it "false" do - check 1, false - end - - it "zero" do - check 1, 0 - end - - it "positive fixnum" do - check 1, 1 - check 1, (1 << 6) - check 1, (1 << 7)-1 - end - - it "positive int 8" do - check 1, -1 - check 2, (1 << 7) - check 2, (1 << 8) - 1 - end - - it "positive int 16" do - check 3, (1 << 8) - check 3, (1 << 16) - 1 - end - - it "positive int 32" do - check 5, (1 << 16) - check 5, (1 << 32) - 1 - end - - it "positive int 64" do - check 9, (1 << 32) - #check 9, (1<<64)-1 - end - - it "negative fixnum" do - check 1, -1 - check 1, -((1 << 5)-1) - check 1, -(1 << 5) - end - - it "negative int 8" do - check 2, -((1 << 5)+1) - check 2, -(1 << 7) - end - - it "negative int 16" do - check 3, -((1 << 7)+1) - check 3, -(1 << 15) - end - - it "negative int 32" do - check 5, -((1 << 15)+1) - check 5, -(1 << 31) - end - - it "negative int 64" do - check 9, -((1 << 31)+1) - check 9, -(1 << 63) - end - - it "double" do - check 9, 1.0 - check 9, 0.1 - check 9, -0.1 - check 9, -1.0 - end - - it "fixraw" do - check_raw 1, 0 - check_raw 1, (1 << 5)-1 - end - - it "raw 8" do - check_raw 2, (1 << 5) - check_raw 2, (1 << 8)-1 - end - - it "raw 16" do - check_raw 3, (1 << 8) - check_raw 3, (1 << 16)-1 - end - - it "raw 32" do - check_raw 5, (1 << 16) - #check_raw 5, (1 << 32)-1 # memory error - end - - it "str encoding is UTF_8" do - v = pack_unpack('string'.force_encoding(Encoding::UTF_8)) - v.encoding.should == Encoding::UTF_8 - end - - it "str transcode US-ASCII" do - v = pack_unpack('string'.force_encoding(Encoding::US_ASCII)) - v.encoding.should == Encoding::UTF_8 - end - - it "str transcode UTF-16" do - v = pack_unpack('string'.encode(Encoding::UTF_16)) - v.encoding.should == Encoding::UTF_8 - v.should == 'string' - end - - it "str transcode EUC-JP 7bit safe" do - v = pack_unpack('string'.force_encoding(Encoding::EUC_JP)) - v.encoding.should == Encoding::UTF_8 - v.should == 'string' - end - - it "str transcode EUC-JP 7bit unsafe" do - v = pack_unpack([0xa4, 0xa2].pack('C*').force_encoding(Encoding::EUC_JP)) - v.encoding.should == Encoding::UTF_8 - v.should == "\xE3\x81\x82".force_encoding('UTF-8') - end - - it "symbol to str" do - v = pack_unpack(:a) - v.should == "a".force_encoding('UTF-8') - end - - it "symbol to str with encoding" do - a = "\xE3\x81\x82".force_encoding('UTF-8') - v = pack_unpack(a.encode('Shift_JIS').to_sym) - v.encoding.should == Encoding::UTF_8 - v.should == a - end - - it "symbol to bin" do - a = "\xE3\x81\x82".force_encoding('ASCII-8BIT') - v = pack_unpack(a.to_sym) - v.encoding.should == Encoding::ASCII_8BIT - v.should == a - end - - it "bin 8" do - check_bin 2, (1<<8)-1 - end - - it "bin 16" do - check_bin 3, (1<<16)-1 - end - - it "bin 32" do - check_bin 5, (1<<16) - end - - it "bin encoding is ASCII_8BIT" do - pack_unpack('string'.force_encoding(Encoding::ASCII_8BIT)).encoding.should == Encoding::ASCII_8BIT - end - - it "fixarray" do - check_array 1, 0 - check_array 1, (1 << 4)-1 - end - - it "array 16" do - check_array 3, (1 << 4) - #check_array 3, (1 << 16)-1 - end - - it "array 32" do - #check_array 5, (1 << 16) - #check_array 5, (1 << 32)-1 # memory error - end - - it "nil" do - match nil, "\xc0" - end - - it "false" do - match false, "\xc2" - end - - it "true" do - match true, "\xc3" - end - - it "0" do - match 0, "\x00" - end - - it "127" do - match 127, "\x7f" - end - - it "128" do - match 128, "\xcc\x80" - end - - it "256" do - match 256, "\xcd\x01\x00" - end - - it "-1" do - match -1, "\xff" - end - - it "-33" do - match -33, "\xd0\xdf" - end - - it "-129" do - match -129, "\xd1\xff\x7f" - end - - it "{1=>1}" do - obj = {1=>1} - match obj, "\x81\x01\x01" - end - - it "1.0" do - match 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00" - end - - it "[]" do - match [], "\x90" - end - - it "[0, 1, ..., 14]" do - obj = (0..14).to_a - match obj, "\x9f\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e" - end - - it "[0, 1, ..., 15]" do - obj = (0..15).to_a - match obj, "\xdc\x00\x10\x00\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a\x0b\x0c\x0d\x0e\x0f" - end - - it "{}" do - obj = {} - match obj, "\x80" - end - -## FIXME -# it "{0=>0, 1=>1, ..., 14=>14}" do -# a = (0..14).to_a; -# match Hash[*a.zip(a).flatten], "\x8f\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x04\x04\x0a\x0a" -# end -# -# it "{0=>0, 1=>1, ..., 15=>15}" do -# a = (0..15).to_a; -# match Hash[*a.zip(a).flatten], "\xde\x00\x10\x05\x05\x0b\x0b\x00\x00\x06\x06\x0c\x0c\x01\x01\x07\x07\x0d\x0d\x02\x02\x08\x08\x0e\x0e\x03\x03\x09\x09\x0f\x0f\x04\x04\x0a\x0a" -# end - -## FIXME -# it "fixmap" do -# check_map 1, 0 -# check_map 1, (1<<4)-1 -# end -# -# it "map 16" do -# check_map 3, (1<<4) -# check_map 3, (1<<16)-1 -# end -# -# it "map 32" do -# check_map 5, (1<<16) -# #check_map 5, (1<<32)-1 # memory error -# end - - def check(len, obj) - raw = obj.to_msgpack.to_s - raw.length.should == len - MessagePack.unpack(raw).should == obj - end - - def check_raw(overhead, num) - check num+overhead, (" "*num).force_encoding(Encoding::UTF_8) - end - - def check_bin(overhead, num) - check num+overhead, (" "*num).force_encoding(Encoding::ASCII_8BIT) - end - - def check_array(overhead, num) - check num+overhead, Array.new(num) - end - - def match(obj, buf) - raw = obj.to_msgpack.to_s - raw.should == buf - end - - def pack_unpack(obj) - MessagePack.unpack(obj.to_msgpack) - end -end - diff --git a/spec/jruby/benchmarks/shootout_bm.rb b/spec/jruby/benchmarks/shootout_bm.rb deleted file mode 100644 index c995b628..00000000 --- a/spec/jruby/benchmarks/shootout_bm.rb +++ /dev/null @@ -1,73 +0,0 @@ -# encoding: utf-8 - -if RUBY_PLATFORM.include?('java') - # JRuby should use this library, MRI should use the standard gem - $: << File.expand_path('../../../lib', __FILE__) -end - -require 'viiite' -require 'msgpack' -require 'json' -require 'bson' - -if RUBY_PLATFORM.include?('java') - BSON_IMPL = BSON::BSON_JAVA -else - BSON_IMPL = BSON::BSON_C -end - -OBJECT_STRUCTURE = {'x' => ['y', 34, 2**30 + 3, 2.1223423423356, {'hello' => 'world', '5' => [63, 'asjdl']}]} -ENCODED_MSGPACK = "\x81\xA1x\x95\xA1y\"\xCE@\x00\x00\x03\xCB@\x00\xFA\x8E\x9F9\xFA\xC1\x82\xA5hello\xA5world\xA15\x92?\xA5asjdl" -ENCODED_BSON = "d\x00\x00\x00\x04x\x00\\\x00\x00\x00\x020\x00\x02\x00\x00\x00y\x00\x101\x00\"\x00\x00\x00\x102\x00\x03\x00\x00@\x013\x00\xC1\xFA9\x9F\x8E\xFA\x00@\x034\x002\x00\x00\x00\x02hello\x00\x06\x00\x00\x00world\x00\x045\x00\x19\x00\x00\x00\x100\x00?\x00\x00\x00\x021\x00\x06\x00\x00\x00asjdl\x00\x00\x00\x00\x00" -ENCODED_JSON = '{"x":["y",34,1073741827,2.1223423423356,{"hello":"world","5":[63,"asjdl"]}]}' -ITERATIONS = 1_00_000 -IMPLEMENTATIONS = ENV.fetch('IMPLEMENTATIONS', 'json,bson,msgpack').split(',').map(&:to_sym) - -Viiite.bm do |b| - b.variation_point :ruby, Viiite.which_ruby - - IMPLEMENTATIONS.each do |lib| - b.variation_point :lib, lib - - - b.report(:pack) do - ITERATIONS.times do - case lib - when :msgpack then MessagePack.pack(OBJECT_STRUCTURE) - when :bson then BSON_IMPL.serialize(OBJECT_STRUCTURE).to_s - when :json then OBJECT_STRUCTURE.to_json - end - end - end - - b.report(:unpack) do - ITERATIONS.times do - case lib - when :msgpack then MessagePack.unpack(ENCODED_MSGPACK) - when :bson then BSON_IMPL.deserialize(ENCODED_BSON) - when :json then JSON.parse(ENCODED_JSON) - end - end - end - - b.report(:pack_unpack) do - ITERATIONS.times do - case lib - when :msgpack then MessagePack.unpack(MessagePack.pack(OBJECT_STRUCTURE)) - when :bson then BSON_IMPL.deserialize(BSON_IMPL.serialize(OBJECT_STRUCTURE).to_s) - when :json then JSON.parse(OBJECT_STRUCTURE.to_json) - end - end - end - - b.report(:unpack_pack) do - ITERATIONS.times do - case lib - when :msgpack then MessagePack.pack(MessagePack.unpack(ENCODED_MSGPACK)) - when :bson then BSON_IMPL.serialize(BSON_IMPL.deserialize(ENCODED_BSON)).to_s - when :json then OBJECT_STRUCTURE.to_json(JSON.parse(ENCODED_JSON)) - end - end - end - end -end \ No newline at end of file diff --git a/spec/jruby/benchmarks/symbolize_keys_bm.rb b/spec/jruby/benchmarks/symbolize_keys_bm.rb deleted file mode 100644 index 79869218..00000000 --- a/spec/jruby/benchmarks/symbolize_keys_bm.rb +++ /dev/null @@ -1,25 +0,0 @@ -# encoding: utf-8 - -$: << File.expand_path('../../../lib', __FILE__) - -require 'viiite' -require 'msgpack' - - -iterations = 10_000 -data = MessagePack.pack(:hello => 'world', :nested => ['structure', {:value => 42}]) - -Viiite.bm do |b| - b.report(:strings) do - iterations.times do - MessagePack.unpack(data) - end - end - - b.report(:symbols) do - options = {:symbolize_keys => true} - iterations.times do - MessagePack.unpack(data, options) - end - end -end \ No newline at end of file diff --git a/spec/jruby/unpacker_spec.rb b/spec/jruby/unpacker_spec.rb deleted file mode 100644 index 445f2417..00000000 --- a/spec/jruby/unpacker_spec.rb +++ /dev/null @@ -1,186 +0,0 @@ -# encoding: ascii-8bit - -require 'stringio' -require 'tempfile' - -require 'spec_helper' - -describe MessagePack::Unpacker do - let :unpacker do - MessagePack::Unpacker.new - end - - let :packer do - MessagePack::Packer.new - end - - let :buffer1 do - MessagePack.pack(:foo => 'bar') - end - - let :buffer2 do - MessagePack.pack(:hello => {:world => [1, 2, 3]}) - end - - let :buffer3 do - MessagePack.pack(:x => 'y') - end - - describe '#execute/#execute_limit/#finished?' do - let :buffer do - buffer1 + buffer2 + buffer3 - end - - it 'extracts an object from the buffer' do - subject.execute(buffer, 0) - subject.data.should == {'foo' => 'bar'} - end - - it 'extracts an object from the buffer, starting at an offset' do - subject.execute(buffer, buffer1.length) - subject.data.should == {'hello' => {'world' => [1, 2, 3]}} - end - - it 'extracts an object from the buffer, starting at an offset reading bytes up to a limit' do - subject.execute_limit(buffer, buffer1.length, buffer2.length) - subject.data.should == {'hello' => {'world' => [1, 2, 3]}} - end - - it 'extracts nothing if the limit cuts an object in half' do - subject.execute_limit(buffer, buffer1.length, 3) - subject.data.should be_nil - end - - it 'returns the offset where the object ended' do - subject.execute(buffer, 0).should == buffer1.length - subject.execute(buffer, buffer1.length).should == buffer1.length + buffer2.length - end - - it 'is finished if #data returns an object' do - subject.execute_limit(buffer, buffer1.length, buffer2.length) - subject.should be_finished - - subject.execute_limit(buffer, buffer1.length, 3) - subject.should_not be_finished - end - end - - describe '#each' do - context 'with a StringIO stream' do - it 'yields each object in the stream' do - objects = [] - subject.stream = StringIO.new(buffer1 + buffer2 + buffer3) - subject.each do |obj| - objects << obj - end - objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}] - end - end - - context 'with a File stream' do - it 'yields each object in the stream' do - objects = [] - file = Tempfile.new('msgpack') - file.write(buffer1) - file.write(buffer2) - file.write(buffer3) - file.open - subject.stream = file - subject.each do |obj| - objects << obj - end - objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}] - end - end - end - - describe '#fill' do - it 'is a no-op' do - subject.stream = StringIO.new(buffer1 + buffer2 + buffer3) - subject.fill - subject.each { |obj| } - end - end - - def flatten(struct, results = []) - case struct - when Array - struct.each { |v| flatten(v, results) } - when Hash - struct.each { |k, v| flatten(v, flatten(k, results)) } - else - results << struct - end - results - end - - context 'encoding', :encodings do - before :all do - @default_internal = Encoding.default_internal - @default_external = Encoding.default_external - end - - after :all do - Encoding.default_internal = @default_internal - Encoding.default_external = @default_external - end - - let :buffer do - MessagePack.pack({'hello' => 'world', 'nested' => ['object', {"sk\xC3\xA5l".force_encoding('utf-8') => true}]}) - end - - let :unpacker do - described_class.new - end - - before do - Encoding.default_internal = Encoding::UTF_8 - Encoding.default_external = Encoding::ISO_8859_1 - end - - it 'produces results with encoding as binary or string(utf8)' do - unpacker.execute(buffer, 0) - strings = flatten(unpacker.data).grep(String) - strings.map(&:encoding).uniq.sort{|a,b| a.to_s <=> b.to_s}.should == [Encoding::ASCII_8BIT, Encoding::UTF_8] - end - - it 'recodes to internal encoding' do - unpacker.execute(buffer, 0) - unpacker.data['nested'][1].keys.should == ["sk\xC3\xA5l".force_encoding(Encoding::UTF_8)] - end - end - - context 'extensions' do - context 'symbolized keys' do - let :buffer do - MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]}) - end - - let :unpacker do - described_class.new(:symbolize_keys => true) - end - - it 'can symbolize keys when using #execute' do - unpacker.execute(buffer, 0) - unpacker.data.should == {:hello => 'world', :nested => ['object', {:structure => true}]} - end - end - - context 'encoding', :encodings do - let :buffer do - MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]}) - end - - let :unpacker do - described_class.new() - end - - it 'decode binary as ascii-8bit string when using #execute' do - unpacker.execute(buffer, 0) - strings = flatten(unpacker.data).grep(String) - strings.should == %w[hello world nested object structure] - strings.map(&:encoding).uniq.should == [Encoding::ASCII_8BIT] - end - end - end -end diff --git a/spec/msgpack_spec.rb b/spec/msgpack_spec.rb deleted file mode 100644 index dee9883e..00000000 --- a/spec/msgpack_spec.rb +++ /dev/null @@ -1,214 +0,0 @@ -# encoding: ascii-8bit - -require 'spec_helper' - -def utf8enc(str) - str.encode('UTF-8') -end - -def asciienc(str) - str.encode('ASCII-8BIT') -end - -describe MessagePack do - tests = { - 'constant values' => [ - ['true', true, "\xC3"], - ['false', false, "\xC2"], - ['nil', nil, "\xC0"] - ], - 'numbers' => [ - ['zero', 0, "\x00"], - ['127', 127, "\x7F"], - ['128', 128, "\xCC\x80"], - ['256', 256, "\xCD\x01\x00"], - ['-1', -1, "\xFF"], - ['-33', -33, "\xD0\xDF"], - ['-129', -129, "\xD1\xFF\x7F"], - ['small integers', 42, "*"], - ['medium integers', 333, "\xCD\x01M"], - ['large integers', 2**31 - 1, "\xCE\x7F\xFF\xFF\xFF"], - ['huge integers', 2**64 - 1, "\xCF\xFF\xFF\xFF\xFF\xFF\xFF\xFF\xFF"], - ['negative integers', -1, "\xFF"], - ['1.0', 1.0, "\xcb\x3f\xf0\x00\x00\x00\x00\x00\x00"], - ['small floats', 3.14, "\xCB@\t\x1E\xB8Q\xEB\x85\x1F"], - ['big floats', Math::PI * 1_000_000_000_000_000_000, "\xCBC\xC5\xCC\x96\xEF\xD1\x19%"], - ['negative floats', -2.1, "\xCB\xC0\x00\xCC\xCC\xCC\xCC\xCC\xCD"] - ], - 'strings' => [ - ['tiny strings', utf8enc('hello world'), "\xABhello world"], - ['short strings', utf8enc('hello' * 5), "\xB9hellohellohellohellohello"], - ['empty strings', utf8enc(''), "\xA0"] - ], - 'binary strings' => [ - ['tiny strings', asciienc('hello world'), "\xC4\vhello world"], - ['short strings', asciienc('hello' * 5), "\xC4\x19hellohellohellohellohello"], - ['empty strings', asciienc(''), "\xC4\x00"] - ], - 'arrays' => [ - ['empty arrays', [], "\x90"], - ['arrays with strings', [utf8enc("hello"), utf8enc("world")], "\x92\xA5hello\xA5world"], - ['arrays with mixed values', [utf8enc("hello"), utf8enc("world"), 42], "\x93\xA5hello\xA5world*"], - ['arrays of arrays', [[[[1, 2], 3], 4]], "\x91\x92\x92\x92\x01\x02\x03\x04"], - ['empty arrays', [], "\x90"] - ], - 'hashes' => [ - ['empty hashes', {}, "\x80"], - ['hashes', {utf8enc('foo') => utf8enc('bar')}, "\x81\xA3foo\xA3bar"], - ['hashes with mixed keys and values', {utf8enc('foo') => utf8enc('bar'), 3 => utf8enc('three'), utf8enc('four') => 4, utf8enc('x') => [utf8enc('y')], utf8enc('a') => utf8enc('b')}, "\x85\xA3foo\xA3bar\x03\xA5three\xA4four\x04\xA1x\x91\xA1y\xA1a\xA1b"], - ['hashes of hashes', {{utf8enc('x') => {utf8enc('y') => utf8enc('z')}} => utf8enc('s')}, "\x81\x81\xA1x\x81\xA1y\xA1z\xA1s"], - ['hashes with nils', {utf8enc('foo') => nil}, "\x81\xA3foo\xC0"] - ] - } - - tests.each do |ctx, its| - context("with #{ctx}") do - its.each do |desc, unpacked, packed| - it("encodes #{desc}") do - MessagePack.pack(unpacked).should == packed - end - - it "decodes #{desc}" do - MessagePack.unpack(packed).should == unpacked - end - end - end - end - - context 'using other names for .pack and .unpack' do - it 'can unpack with .load' do - MessagePack.load("\xABhello world").should == 'hello world' - end - - it 'can pack with .dump' do - MessagePack.dump(utf8enc('hello world')).should == "\xABhello world" - end - end - - context 'with symbols' do - it 'encodes symbols as strings' do - MessagePack.pack(:symbol).should == "\xA6symbol" - end - end - - context 'with different external encoding', :encodings do - before do - @default_external = Encoding.default_external - @default_internal = Encoding.default_internal - Encoding.default_external = Encoding::UTF_8 - Encoding.default_internal = Encoding::ISO_8859_1 - end - - after do - Encoding.default_external = @default_external - Encoding.default_internal = @default_internal - end - - it 'transcodes strings when encoding' do - input = "sk\xE5l".force_encoding(Encoding::ISO_8859_1) - MessagePack.pack(input).should == "\xA5sk\xC3\xA5l" - end - end - - context 'with other things' do - it 'raises an error on #pack with an unsupported type' do - expect { MessagePack.pack(self) }.to raise_error(NoMethodError, /undefined method .*to_msgpack/) - end - - it 'raises an error on #unpack with garbage' do - skip "but nothing was raised. why?" - expect { MessagePack.unpack('asdka;sd') }.to raise_error(MessagePack::UnpackError) - end - end - - context 'extensions' do - it 'can unpack hashes with symbolized keys' do - packed = MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]}) - unpacked = MessagePack.unpack(packed, :symbolize_keys => true) - unpacked.should == {:hello => 'world', :nested => ['object', {:structure => true}]} - end - - it 'does not symbolize keys even if other options are present' do - packed = MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]}) - unpacked = MessagePack.unpack(packed, :other_option => false) - unpacked.should == {'hello' => 'world', 'nested' => ['object', {'structure' => true}]} - end - - it 'can unpack strings with a specified encoding', :encodings do - packed = MessagePack.pack({utf8enc('hello') => utf8enc('world')}) - unpacked = MessagePack.unpack(packed) - unpacked['hello'].encoding.should == Encoding::UTF_8 - end - - it 'can pack strings with a specified encoding', :encodings do - packed = MessagePack.pack({'hello' => "w\xE5rld".force_encoding(Encoding::ISO_8859_1)}) - packed.index("w\xC3\xA5rld").should_not be_nil - end - end - - context 'in compatibility mode' do - it 'does not use the bin types' do - packed = MessagePack.pack('hello'.force_encoding(Encoding::BINARY), compatibility_mode: true) - packed.should eq("\xA5hello") - packed = MessagePack.pack(('hello' * 100).force_encoding(Encoding::BINARY), compatibility_mode: true) - packed.should start_with("\xDA\x01\xF4") - end - - it 'does not use the str8 type' do - packed = MessagePack.pack('x' * 32, compatibility_mode: true) - packed.should start_with("\xDA\x00\x20") - end - end - - context 'when a Bignum has a small value' do - tests['numbers'].take(10).each do |desc, unpacked, packed| - it("encodes #{desc} to the smallest representation") do - bignum = (1 << 64).coerce(unpacked)[0] - MessagePack.pack(bignum).should eq(packed) - end - end - end - - context 'when the source is na IO-like object' do - require 'tempfile' - require 'stringio' - - it 'work with IO destination object as 2nd argument of MessagePack.pack' do - Tempfile.create("pack-test") do |io| - return_value = MessagePack.pack(utf8enc('hello world'), io) - return_value.should be_nil - - io.rewind - io.read.force_encoding(Encoding::ASCII_8BIT).should eq("\xABhello world".force_encoding(Encoding::ASCII_8BIT)) - end - end - - it 'work with IO-like StringIO destination object as 2nd argument of MessagePack.pack' do - io = StringIO.new - return_value = MessagePack.pack(utf8enc('hello world'), io) - return_value.should be_nil - - io.rewind - io.read.force_encoding(Encoding::ASCII_8BIT).should eq("\xABhello world".force_encoding(Encoding::ASCII_8BIT)) - end - - it 'work with IO source object as source of MessagePack.unpack' do - Tempfile.create("unpack-test") do |io| - MessagePack.pack(utf8enc('hello world'), io) - io.rewind - - return_value = MessagePack.unpack(io) - return_value.should eq(utf8enc('hello world')) - end - end - - it 'work with IO-like StringIO object of MessagePack.unpack' do - io = StringIO.new - MessagePack.pack(utf8enc('hello world'), io) - io.rewind - - return_value = MessagePack.unpack(io) - return_value.should eq(utf8enc('hello world')) - end - end -end diff --git a/spec/pack_spec.rb b/spec/pack_spec.rb deleted file mode 100644 index d7ea5331..00000000 --- a/spec/pack_spec.rb +++ /dev/null @@ -1,61 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -require 'stringio' -if defined?(Encoding) - Encoding.default_external = 'ASCII-8BIT' -end - -describe MessagePack do - it 'to_msgpack returns String' do - nil.to_msgpack.class.should == String - true.to_msgpack.class.should == String - false.to_msgpack.class.should == String - 1.to_msgpack.class.should == String - 1.0.to_msgpack.class.should == String - "".to_msgpack.class.should == String - Hash.new.to_msgpack.class.should == String - Array.new.to_msgpack.class.should == String - end - - class CustomPack01 - def to_msgpack(pk=nil) - return MessagePack.pack(self, pk) unless pk.class == MessagePack::Packer - pk.write_array_header(2) - pk.write(1) - pk.write(2) - return pk - end - end - - class CustomPack02 - def to_msgpack(pk=nil) - [1,2].to_msgpack(pk) - end - end - - it 'calls custom to_msgpack method' do - MessagePack.pack(CustomPack01.new).should == [1,2].to_msgpack - MessagePack.pack(CustomPack02.new).should == [1,2].to_msgpack - CustomPack01.new.to_msgpack.should == [1,2].to_msgpack - CustomPack02.new.to_msgpack.should == [1,2].to_msgpack - end - - it 'calls custom to_msgpack method with io' do - s01 = StringIO.new - MessagePack.pack(CustomPack01.new, s01) - s01.string.should == [1,2].to_msgpack - - s02 = StringIO.new - MessagePack.pack(CustomPack02.new, s02) - s02.string.should == [1,2].to_msgpack - - s03 = StringIO.new - CustomPack01.new.to_msgpack(s03) - s03.string.should == [1,2].to_msgpack - - s04 = StringIO.new - CustomPack02.new.to_msgpack(s04) - s04.string.should == [1,2].to_msgpack - end -end diff --git a/spec/packer_spec.rb b/spec/packer_spec.rb deleted file mode 100644 index 3968622f..00000000 --- a/spec/packer_spec.rb +++ /dev/null @@ -1,619 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -require 'stringio' -require 'tempfile' -require 'zlib' - -if defined?(Encoding) - Encoding.default_external = 'ASCII-8BIT' -end - -describe MessagePack::Packer do - let :packer do - MessagePack::Packer.new - end - - it 'initialize' do - MessagePack::Packer.new - MessagePack::Packer.new(nil) - MessagePack::Packer.new(StringIO.new) - MessagePack::Packer.new({}) - MessagePack::Packer.new(StringIO.new, {}) - end - - it 'gets IO or object which has #write to write/append data to it' do - sample_data = {"message" => "morning!", "num" => 1} - sample_packed = MessagePack.pack(sample_data) - - Tempfile.open("for_io") do |file| - file.sync = true - p1 = MessagePack::Packer.new(file) - p1.write sample_data - p1.flush - - file.rewind - expect(file.read).to eql(sample_packed) - file.unlink - end - - dio = StringIO.new - p2 = MessagePack::Packer.new(dio) - p2.write sample_data - p2.flush - dio.rewind - expect(dio.string).to eql(sample_packed) - - dio = StringIO.new - writer = Zlib::GzipWriter.new(dio) - writer.sync = true - p3 = MessagePack::Packer.new(writer) - p3.write sample_data - p3.flush - writer.flush(Zlib::FINISH) - writer.close - dio.rewind - compressed = dio.string - str = Zlib::GzipReader.wrap(StringIO.new(compressed)){|gz| gz.read } - expect(str).to eql(sample_packed) - - class DummyIO - def initialize - @buf = "".force_encoding('ASCII-8BIT') - @pos = 0 - end - def write(val) - @buf << val.to_s - end - def read(length=nil,outbuf="") - if @pos == @buf.size - nil - elsif length.nil? - val = @buf[@pos..(@buf.size)] - @pos = @buf.size - outbuf << val - outbuf - else - val = @buf[@pos..(@pos + length)] - @pos += val.size - @pos = @buf.size if @pos > @buf.size - outbuf << val - outbuf - end - end - def flush - # nop - end - def close - # nop - end - end - - dio = DummyIO.new - p4 = MessagePack::Packer.new(dio) - p4.write sample_data - p4.flush - expect(dio.read).to eql(sample_packed) - end - - it 'gets options to specify how to pack values' do - u1 = MessagePack::Packer.new - u1.compatibility_mode?.should == false - - u2 = MessagePack::Packer.new(compatibility_mode: true) - u2.compatibility_mode?.should == true - end - - it 'write' do - packer.write([]) - packer.to_s.should == "\x90" - end - - it 'write_nil' do - packer.write_nil - packer.to_s.should == "\xc0" - end - - it 'write_array_header 0' do - packer.write_array_header(0) - packer.to_s.should == "\x90" - end - - it 'write_array_header 1' do - packer.write_array_header(1) - packer.to_s.should == "\x91" - end - - it 'write_map_header 0' do - packer.write_map_header(0) - packer.to_s.should == "\x80" - end - - it 'write_map_header 1' do - packer.write_map_header(1) - packer.to_s.should == "\x81" - end - - it 'write_bin_header 0' do - packer.write_bin_header(0) - packer.to_s.should == "\xC4\x00" - end - - it 'write_bin_header 255' do - packer.write_bin_header(255) - packer.to_s.should == "\xC4\xFF" - end - - it 'write_bin_header 256' do - packer.write_bin_header(256) - packer.to_s.should == "\xC5\x01\x00" - end - - it 'write_bin_header 65535' do - packer.write_bin_header(65535) - packer.to_s.should == "\xC5\xFF\xFF" - end - - it 'write_bin_header 65536' do - packer.write_bin_header(65536) - packer.to_s.should == "\xC6\x00\x01\x00\x00" - end - - it 'write_bin_header 999999' do - packer.write_bin_header(999999) - packer.to_s.should == "\xC6\x00\x0F\x42\x3F" - end - - it 'write_bin' do - packer.write_bin("hello") - packer.to_s.should == "\xC4\x05hello" - end - - describe '#write_float32' do - tests = [ - ['small floats', 3.14, "\xCA\x40\x48\xF5\xC3"], - ['big floats', Math::PI * 1_000_000_000_000_000_000, "\xCA\x5E\x2E\x64\xB7"], - ['negative floats', -2.1, "\xCA\xC0\x06\x66\x66"], - ['integer', 123, "\xCA\x42\xF6\x00\x00"], - ] - - tests.each do |ctx, numeric, packed| - context("with #{ctx}") do - it("encodes #{numeric} as float32") do - packer.write_float32(numeric) - packer.to_s.should == packed - end - end - end - - context 'with non numeric' do - it 'raises argument error' do - expect { packer.write_float32('abc') }.to raise_error(ArgumentError) - end - end - end - - it 'flush' do - io = StringIO.new - pk = MessagePack::Packer.new(io) - pk.write_nil - pk.flush - pk.to_s.should == '' - io.string.should == "\xc0" - end - - it 'to_msgpack returns String' do - nil.to_msgpack.class.should == String - true.to_msgpack.class.should == String - false.to_msgpack.class.should == String - 1.to_msgpack.class.should == String - 1.0.to_msgpack.class.should == String - "".to_msgpack.class.should == String - Hash.new.to_msgpack.class.should == String - Array.new.to_msgpack.class.should == String - end - - it 'to_msgpack with packer equals to_msgpack' do - nil.to_msgpack(MessagePack::Packer.new).to_str.should == nil.to_msgpack - true.to_msgpack(MessagePack::Packer.new).to_str.should == true.to_msgpack - false.to_msgpack(MessagePack::Packer.new).to_str.should == false.to_msgpack - 1.to_msgpack(MessagePack::Packer.new).to_str.should == 1.to_msgpack - 1.0.to_msgpack(MessagePack::Packer.new).to_str.should == 1.0.to_msgpack - "".to_msgpack(MessagePack::Packer.new).to_str.should == "".to_msgpack - Hash.new.to_msgpack(MessagePack::Packer.new).to_str.should == Hash.new.to_msgpack - Array.new.to_msgpack(MessagePack::Packer.new).to_str.should == Array.new.to_msgpack - end - - it 'raises type error on wrong type' do - packer = MessagePack::Packer.new - expect { packer.write_float "hello" }.to raise_error(TypeError) - expect { packer.write_string 1 }.to raise_error(TypeError) - expect { packer.write_bin 1 }.to raise_error(TypeError) - expect { packer.write_array "hello" }.to raise_error(TypeError) - expect { packer.write_hash "hello" }.to raise_error(TypeError) - expect { packer.write_symbol "hello" }.to raise_error(TypeError) - expect { packer.write_int "hello" }.to raise_error(TypeError) - expect { packer.write_extension "hello" }.to raise_error(TypeError) - end - - class CustomPack01 - def to_msgpack(pk=nil) - return MessagePack.pack(self, pk) unless pk.class == MessagePack::Packer - pk.write_array_header(2) - pk.write(1) - pk.write(2) - return pk - end - end - - class CustomPack02 - def to_msgpack(pk=nil) - [1,2].to_msgpack(pk) - end - end - - it 'calls custom to_msgpack method' do - MessagePack.pack(CustomPack01.new).should == [1,2].to_msgpack - MessagePack.pack(CustomPack02.new).should == [1,2].to_msgpack - CustomPack01.new.to_msgpack.should == [1,2].to_msgpack - CustomPack02.new.to_msgpack.should == [1,2].to_msgpack - end - - it 'calls custom to_msgpack method with io' do - s01 = StringIO.new - MessagePack.pack(CustomPack01.new, s01) - s01.string.should == [1,2].to_msgpack - - s02 = StringIO.new - MessagePack.pack(CustomPack02.new, s02) - s02.string.should == [1,2].to_msgpack - - s03 = StringIO.new - CustomPack01.new.to_msgpack(s03) - s03.string.should == [1,2].to_msgpack - - s04 = StringIO.new - CustomPack02.new.to_msgpack(s04) - s04.string.should == [1,2].to_msgpack - end - - context 'in compatibility mode' do - it 'does not use the bin types' do - packed = MessagePack.pack('hello'.force_encoding(Encoding::BINARY), compatibility_mode: true) - packed.should eq("\xA5hello") - packed = MessagePack.pack(('hello' * 100).force_encoding(Encoding::BINARY), compatibility_mode: true) - packed.should start_with("\xDA\x01\xF4") - - packer = MessagePack::Packer.new(compatibility_mode: 1) - packed = packer.pack(('hello' * 100).force_encoding(Encoding::BINARY)) - packed.to_str.should start_with("\xDA\x01\xF4") - end - - it 'does not use the str8 type' do - packed = MessagePack.pack('x' * 32, compatibility_mode: true) - packed.should start_with("\xDA\x00\x20") - end - end - - class ValueOne - def initialize(num) - @num = num - end - def num - @num - end - def to_msgpack_ext - @num.to_msgpack - end - def self.from_msgpack_ext(data) - self.new(MessagePack.unpack(data)) - end - end - - class ValueTwo - def initialize(num) - @num_s = num.to_s - end - def num - @num_s.to_i - end - def to_msgpack_ext - @num_s.to_msgpack - end - def self.from_msgpack_ext(data) - self.new(MessagePack.unpack(data)) - end - end - - describe '#type_registered?' do - it 'receive Class or Integer, and return bool' do - expect(subject.type_registered?(0x00)).to be_falsy - expect(subject.type_registered?(0x01)).to be_falsy - expect(subject.type_registered?(::ValueOne)).to be_falsy - end - - it 'returns true if specified type or class is already registered' do - subject.register_type(0x30, ::ValueOne, :to_msgpack_ext) - subject.register_type(0x31, ::ValueTwo, :to_msgpack_ext) - - expect(subject.type_registered?(0x00)).to be_falsy - expect(subject.type_registered?(0x01)).to be_falsy - - expect(subject.type_registered?(0x30)).to be_truthy - expect(subject.type_registered?(0x31)).to be_truthy - expect(subject.type_registered?(::ValueOne)).to be_truthy - expect(subject.type_registered?(::ValueTwo)).to be_truthy - end - end - - describe '#register_type' do - it 'get type and class mapping for packing' do - packer = MessagePack::Packer.new - packer.register_type(0x01, ValueOne){|obj| obj.to_msgpack_ext } - packer.register_type(0x02, ValueTwo){|obj| obj.to_msgpack_ext } - - packer = MessagePack::Packer.new - packer.register_type(0x01, ValueOne, :to_msgpack_ext) - packer.register_type(0x02, ValueTwo, :to_msgpack_ext) - - packer = MessagePack::Packer.new - packer.register_type(0x01, ValueOne, &:to_msgpack_ext) - packer.register_type(0x02, ValueTwo, &:to_msgpack_ext) - end - - it 'returns a Hash which contains map of Class and type' do - packer = MessagePack::Packer.new - packer.register_type(0x01, ValueOne, :to_msgpack_ext) - packer.register_type(0x02, ValueTwo, :to_msgpack_ext) - - expect(packer.registered_types).to be_a(Array) - expect(packer.registered_types.size).to eq(2) - - one = packer.registered_types[0] - expect(one.keys.sort).to eq([:type, :class, :packer].sort) - expect(one[:type]).to eq(0x01) - expect(one[:class]).to eq(ValueOne) - expect(one[:packer]).to be_a(Proc) - - two = packer.registered_types[1] - expect(two.keys.sort).to eq([:type, :class, :packer].sort) - expect(two[:type]).to eq(0x02) - expect(two[:class]).to eq(ValueTwo) - expect(two[:packer]).to be_a(Proc) - end - - context 'when it has no ext type but a super class has' do - before { stub_const('Value', Class.new) } - before do - Value.class_eval do - def to_msgpack_ext - 'value_msgpacked' - end - end - end - before { packer.register_type(0x01, Value, :to_msgpack_ext) } - - context "when it is a child class" do - before { stub_const('InheritedValue', Class.new(Value)) } - subject { packer.pack(InheritedValue.new).to_s } - - it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" } - - context "when it is a grandchild class" do - before { stub_const('InheritedTwiceValue', Class.new(InheritedValue)) } - subject { packer.pack(InheritedTwiceValue.new).to_s } - - it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" } - end - end - end - - context 'when it and its super class has an ext type' do - before { stub_const('Value', Class.new) } - before do - Value.class_eval do - def to_msgpack_ext - 'value_msgpacked' - end - end - end - before { packer.register_type(0x01, Value, :to_msgpack_ext) } - - context "when it is a child class" do - before { stub_const('InheritedValue', Class.new(Value)) } - before do - InheritedValue.class_eval do - def to_msgpack_ext - 'inherited_value_msgpacked' - end - end - end - - before { packer.register_type(0x02, InheritedValue, :to_msgpack_ext) } - subject { packer.pack(InheritedValue.new).to_s } - - it { is_expected.to eq "\xC7\x19\x02inherited_value_msgpacked" } - end - - context "even when it is a child class" do - before { stub_const('InheritedValue', Class.new(Value)) } - before do - InheritedValue.class_eval do - def to_msgpack_ext - 'inherited_value_msgpacked' - end - end - end - - before { packer.register_type(0x02, InheritedValue, :to_msgpack_ext) } - subject { packer.pack(Value.new).to_s } - - it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" } - end - end - - context 'when it has no ext type but an included module has' do - subject { packer.pack(Value.new).to_s } - - before do - mod = Module.new do - def to_msgpack_ext - 'value_msgpacked' - end - end - stub_const('Mod', mod) - end - before { packer.register_type(0x01, Mod, :to_msgpack_ext) } - - before { stub_const('Value', Class.new{ include Mod }) } - - it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" } - end - - context 'when it has no ext type but it was extended by a module which has one' do - subject { packer.pack(object).to_s } - let(:object) { Object.new.extend Mod } - - before do - mod = Module.new do - def to_msgpack_ext - 'value_msgpacked' - end - end - stub_const('Mod', mod) - end - before { packer.register_type(0x01, Mod, :to_msgpack_ext) } - - - it { is_expected.to eq "\xC7\x0F\x01value_msgpacked" } - end - - shared_examples_for 'extension subclasses core type' do |klass| - before { stub_const('Value', Class.new(klass)) } - let(:object) { Value.new } - subject { packer.pack(object).to_s } - - it "defaults to #{klass.name} packer if no extension is present" do - expect(subject).to eq(MessagePack.dump(klass.new)) - end - - it "uses core type extension for #{klass.name}" do - packer.register_type(0x01, Value, ->(_) { 'value_msgpacked' }) - expect(subject).to eq("\xC7\x0F\x01value_msgpacked") - end - end - it_behaves_like 'extension subclasses core type', Hash - it_behaves_like 'extension subclasses core type', Array - it_behaves_like 'extension subclasses core type', String - - context 'when registering a type for symbols' do - before { packer.register_type(0x00, ::Symbol, :to_msgpack_ext) } - - it 'packs symbols in an ext type' do - expect(packer.pack(:symbol).to_s).to eq "\xc7\x06\x00symbol" - end - end - end - - describe "fixnum and bignum" do - it "fixnum.to_msgpack" do - 23.to_msgpack.should == "\x17" - end - - it "fixnum.to_msgpack(packer)" do - 23.to_msgpack(packer) - packer.to_s.should == "\x17" - end - - it "bignum.to_msgpack" do - -4294967296.to_msgpack.should == "\xD3\xFF\xFF\xFF\xFF\x00\x00\x00\x00" - end - - it "bignum.to_msgpack(packer)" do - -4294967296.to_msgpack(packer) - packer.to_s.should == "\xD3\xFF\xFF\xFF\xFF\x00\x00\x00\x00" - end - - it "unpack(fixnum)" do - MessagePack.unpack("\x17").should == 23 - end - - it "unpack(bignum)" do - MessagePack.unpack("\xD3\xFF\xFF\xFF\xFF\x00\x00\x00\x00").should == -4294967296 - end - end - - describe "ext formats" do - [1, 2, 4, 8, 16].zip([0xd4, 0xd5, 0xd6, 0xd7, 0xd8]).each do |n,b| - it "msgpack fixext #{n} format" do - MessagePack::ExtensionValue.new(1, "a"*n).to_msgpack.should == - [b, 1].pack('CC') + "a"*n - end - end - - it "msgpack ext 8 format" do - MessagePack::ExtensionValue.new(1, "").to_msgpack.should == - [0xc7, 0, 1].pack('CCC') + "" - MessagePack::ExtensionValue.new(-1, "a"*255).to_msgpack.should == - [0xc7, 255, -1].pack('CCC') + "a"*255 - end - - it "msgpack ext 16 format" do - MessagePack::ExtensionValue.new(1, "a"*256).to_msgpack.should == - [0xc8, 256, 1].pack('CnC') + "a"*256 - MessagePack::ExtensionValue.new(-1, "a"*65535).to_msgpack.should == - [0xc8, 65535, -1].pack('CnC') + "a"*65535 - end - - it "msgpack ext 32 format" do - MessagePack::ExtensionValue.new(1, "a"*65536).to_msgpack.should == - [0xc9, 65536, 1].pack('CNC') + "a"*65536 - MessagePack::ExtensionValue.new(-1, "a"*65538).to_msgpack.should == - [0xc9, 65538, -1].pack('CNC') + "a"*65538 - end - end - - it "doesn't allow #dup or #clone" do - expect(subject).to_not respond_to :dup - expect(subject).to_not respond_to :clone - end - - it "doesn't crash when marking an uninitialized buffer" do - stress = GC.stress - begin - GC.stress = true - - MessagePack::Packer.new.buffer - Object.new - ensure - GC.stress = stress - end - end - - it "doesn't crash when using recursive packers concurrently" do - hash_with_indifferent_access = Class.new(Hash) - msgpack = MessagePack::Factory.new - msgpack.register_type( - 0x02, - hash_with_indifferent_access, - packer: ->(value, packer) do - packer.write("a".b * 600_0000) # Over MSGPACK_BUFFER_STRING_WRITE_REFERENCE_DEFAULT - packer.write(value.to_h) - GC.start(full_mark: true, immediate_mark: true, immediate_sweep: true) - end, - unpacker: ->(unpacker) { hash_with_indifferent_access.new(unpacker.read) }, - recursive: true - ) - - packer = msgpack.packer - - top_hash = hash = hash_with_indifferent_access.new - 10.times do - hash["a"] = new_hash = hash_with_indifferent_access.new - hash = new_hash - end - packer.write(top_hash) - packer.write(top_hash) - packer.full_pack - end -end diff --git a/spec/random_compat.rb b/spec/random_compat.rb deleted file mode 100644 index 87dd97e1..00000000 --- a/spec/random_compat.rb +++ /dev/null @@ -1,24 +0,0 @@ - -unless defined? Random - class Random - def initialize(seed=Time.now.to_i) - Kernel.srand(seed) - @seed = seed - end - - attr_reader :seed - - def rand(arg) - Kernel.rand(arg) - end - - def bytes(n) - array = [] - n.times do - array << rand(256) - end - array.pack('C*') - end - end -end - diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb deleted file mode 100644 index 18c4b004..00000000 --- a/spec/spec_helper.rb +++ /dev/null @@ -1,76 +0,0 @@ -require "set" -require "objspace" - -if ENV['SIMPLE_COV'] - require 'simplecov' - SimpleCov.start do - add_filter 'spec/' - add_filter 'pkg/' - add_filter 'vendor/' - end -end - -if ENV['GC_STRESS'] - puts "enable GC.stress" - GC.stress = true -end - -require 'msgpack' -require "msgpack/bigint" - -if GC.respond_to?(:verify_compaction_references) - # This method was added in Ruby 3.0.0. Calling it this way asks the GC to - # move objects around, helping to find object movement bugs. - begin - GC.verify_compaction_references(expand_heap: true, toward: :empty) - rescue NotImplementedError, ArgumentError - # Some platforms don't support compaction - end -end - -if GC.respond_to?(:auto_compact=) - begin - GC.auto_compact = true - rescue NotImplementedError - # Some platforms don't support compaction - end -end - -IS_JRUBY = RUBY_ENGINE == 'jruby' - -IS_TRUFFLERUBY = RUBY_ENGINE == 'truffleruby' - -# checking if Hash#[]= (rb_hash_aset) dedupes string keys -def automatic_string_keys_deduplication? - h = {} - x = {} - r = rand.to_s - h[%W(#{r}).join('')] = :foo - x[%W(#{r}).join('')] = :foo - - x.keys[0].equal?(h.keys[0]) -end - -def string_deduplication? - r1 = rand.to_s - r2 = r1.dup - (-r1).equal?(-r2) -end - -if IS_JRUBY - RSpec.configure do |c| - c.treat_symbols_as_metadata_keys_with_true_values = true - c.filter_run_excluding :encodings => !(defined? Encoding) - end -else - RSpec.configure do |config| - config.expect_with :rspec do |c| - c.syntax = [:should, :expect] - end - end - Packer = MessagePack::Packer - Unpacker = MessagePack::Unpacker - Buffer = MessagePack::Buffer - Factory = MessagePack::Factory - ExtensionValue = MessagePack::ExtensionValue -end diff --git a/spec/timestamp_spec.rb b/spec/timestamp_spec.rb deleted file mode 100644 index f837bd5a..00000000 --- a/spec/timestamp_spec.rb +++ /dev/null @@ -1,159 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -describe MessagePack::Timestamp do - describe 'malformed format' do - it do - expect do - MessagePack::Timestamp.from_msgpack_ext([0xd4, 0x00].pack("C*")) - end.to raise_error(MessagePack::MalformedFormatError) - end - end - - describe 'register_type with Time' do - let(:factory) do - factory = MessagePack::Factory.new - factory.register_type( - MessagePack::Timestamp::TYPE, - Time, - packer: MessagePack::Time::Packer, - unpacker: MessagePack::Time::Unpacker - ) - factory - end - - let(:time) { Time.local(2019, 6, 17, 1, 2, 3, 123_456_789 / 1000.0) } - it 'serializes and deserializes Time' do - prefix_fixext8_with_type_id = [0xd7, -1].pack("c*") - - packed = factory.pack(time) - expect(packed).to start_with(prefix_fixext8_with_type_id) - expect(packed.size).to eq(10) - unpacked = factory.unpack(packed) - expect(unpacked.to_i).to eq(time.to_i) - expect(unpacked.to_f).to eq(time.to_f) - # expect(unpacked).to eq(time) # we can't do it because of nsec (rational vs float?) - end - - let(:time_without_nsec) { Time.local(2019, 6, 17, 1, 2, 3, 0) } - it 'serializes time without nanosec as fixext4' do - prefix_fixext4_with_type_id = [0xd6, -1].pack("c*") - - packed = factory.pack(time_without_nsec) - expect(packed).to start_with(prefix_fixext4_with_type_id) - expect(packed.size).to eq(6) - unpacked = factory.unpack(packed) - expect(unpacked).to eq(time_without_nsec) - end - - let(:time_after_2514) { Time.at(1 << 34) } # the max num of 34bit int means 2514-05-30 01:53:04 UTC - it 'serializes time after 2038 as ext8' do - prefix_ext8_with_12bytes_payload_and_type_id = [0xc7, 12, -1].pack("c*") - - expect(time_after_2514.to_i).to be > 0xffffffff - packed = factory.pack(time_after_2514) - expect(packed).to start_with(prefix_ext8_with_12bytes_payload_and_type_id) - expect(packed.size).to eq(15) - end - - it 'runs correctly (regression)' do - expect(factory.unpack(factory.pack(Time.utc(2200)))).to eq(Time.utc(2200)) - end - - let(:time32_max) { Time.new(2106, 2, 7, 6, 28, 15, "+00:00") } - it 'is serialized into timestamp32' do - expect(factory.pack(time32_max).size).to be 6 - expect(factory.unpack(factory.pack(time32_max)).utc).to eq(time32_max) - end - - let(:time64_min) { Time.new(2106, 2, 7, 6, 28, 16, "+00:00") } - it 'is serialized into timestamp64' do - expect(factory.pack(time64_min).size).to be 10 - expect(factory.unpack(factory.pack(time64_min)).utc).to eq(time64_min) - end - - let(:time64_max) { Time.at(Time.new(2514, 5, 30, 1, 53, 3, "+00:00").to_i, 999999999 / 1000.0r).utc } # TODO: use Time.at(sec, nsec, :nsec) when removing Ruby 2.4 from the list - it 'is serialized into timestamp64' do - expect(factory.pack(time64_max).size).to be 10 - expect(factory.unpack(factory.pack(time64_max)).utc).to eq(time64_max) - end - - let(:time96_positive_min) { Time.new(2514, 5, 30, 1, 53, 4, "+00:00") } - it 'is serialized into timestamp96' do - expect(factory.pack(time96_positive_min).size).to be 15 - expect(factory.unpack(factory.pack(time96_positive_min)).utc).to eq(time96_positive_min) - end - - let(:time96_min) { Time.at(-2**63).utc } - it 'is serialized into timestamp96' do - skip if IS_JRUBY || IS_TRUFFLERUBY # JRuby and TruffleRuby both use underlying Java time classes that do not support |year| >= 1 billion - expect(factory.pack(time96_min).size).to be 15 - expect(factory.unpack(factory.pack(time96_min)).utc).to eq(time96_min) - end - - let(:time96_max) { Time.at(2**63 - 1).utc } - it 'is serialized into timestamp96' do - skip if IS_JRUBY || IS_TRUFFLERUBY # JRuby and TruffleRuby both use underlying Java time classes that do not support |year| >= 1 billion - expect(factory.pack(time96_max).size).to be 15 - expect(factory.unpack(factory.pack(time96_max)).utc).to eq(time96_max) - end - end - - describe 'register_type with MessagePack::Timestamp' do - let(:factory) do - factory = MessagePack::Factory.new - factory.register_type(MessagePack::Timestamp::TYPE, MessagePack::Timestamp) - factory - end - - let(:timestamp) { MessagePack::Timestamp.new(Time.now.tv_sec, 123_456_789) } - it 'serializes and deserializes MessagePack::Timestamp' do - packed = factory.pack(timestamp) - unpacked = factory.unpack(packed) - expect(unpacked).to eq(timestamp) - end - end - - describe 'timestamp32' do - it 'handles [1, 0]' do - t = MessagePack::Timestamp.new(1, 0) - - payload = t.to_msgpack_ext - unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) - - expect(unpacked).to eq(t) - end - end - - describe 'timestamp64' do - it 'handles [1, 1]' do - t = MessagePack::Timestamp.new(1, 1) - - payload = t.to_msgpack_ext - unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) - - expect(unpacked).to eq(t) - end - end - - describe 'timestamp96' do - it 'handles [-1, 0]' do - t = MessagePack::Timestamp.new(-1, 0) - - payload = t.to_msgpack_ext - unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) - - expect(unpacked).to eq(t) - end - - it 'handles [-1, 999_999_999]' do - t = MessagePack::Timestamp.new(-1, 999_999_999) - - payload = t.to_msgpack_ext - unpacked = MessagePack::Timestamp.from_msgpack_ext(payload) - - expect(unpacked).to eq(t) - end - end -end diff --git a/spec/unpack_spec.rb b/spec/unpack_spec.rb deleted file mode 100644 index 73aab5e1..00000000 --- a/spec/unpack_spec.rb +++ /dev/null @@ -1,57 +0,0 @@ -# encoding: ascii-8bit -require 'spec_helper' - -require 'stringio' -if defined?(Encoding) - Encoding.default_external = 'ASCII-8BIT' -end - -describe MessagePack do - it 'MessagePack.unpack symbolize_keys' do - symbolized_hash = {:a => 'b', :c => 'd'} - MessagePack.load(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash - MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash - end - - it 'Unpacker#read symbolize_keys' do - unpacker = MessagePack::Unpacker.new(:symbolize_keys => true) - symbolized_hash = {:a => 'b', :c => 'd'} - unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash - end - - it "msgpack str 8 type" do - MessagePack.unpack([0xd9, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack str 16 type" do - MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack str 32 type" do - MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack bin 8 type" do - MessagePack.unpack([0xc4, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack bin 16 type" do - MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack bin 32 type" do - MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end -end diff --git a/spec/unpacker_spec.rb b/spec/unpacker_spec.rb deleted file mode 100644 index de2f06cd..00000000 --- a/spec/unpacker_spec.rb +++ /dev/null @@ -1,945 +0,0 @@ -require 'stringio' -require 'tempfile' -require 'zlib' - -require 'spec_helper' - -describe MessagePack::Unpacker do - let :unpacker do - MessagePack::Unpacker.new - end - - let :packer do - MessagePack::Packer.new - end - - it 'gets options to specify how to unpack values' do - u1 = MessagePack::Unpacker.new - u1.symbolize_keys?.should == false - u1.freeze?.should == false - u1.allow_unknown_ext?.should == false - - u2 = MessagePack::Unpacker.new(symbolize_keys: true, freeze: true, allow_unknown_ext: true) - u2.symbolize_keys?.should == true - u2.freeze?.should == true - u2.allow_unknown_ext?.should == true - end - - if automatic_string_keys_deduplication? - it 'ensure string hash keys are deduplicated' do - sample_data = [{"foo" => 1}, {"foo" => 2}] - sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT') - unpacker.feed(sample_packed) - hashes = nil - unpacker.each { |obj| hashes = obj } - expect(hashes[0].keys.first).to equal(hashes[1].keys.first) - end - - it 'ensure strings are not deduplicated' do - sample_data = ["foo"] - sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT') - unpacker.feed(sample_packed) - ary = nil - unpacker.each { |obj| ary = obj } - expect(ary.first.frozen?).to eq(false) - end - end - - it 'gets IO or object which has #read to read data from it' do - sample_data = {"message" => "morning!", "num" => 1} - sample_packed = MessagePack.pack(sample_data).force_encoding('ASCII-8BIT') - - Tempfile.open("for_io") do |file| - file.sync = true - file.write sample_packed - file.rewind - - u1 = MessagePack::Unpacker.new(file) - u1.each do |obj| - expect(obj).to eql(sample_data) - end - file.unlink - end - - sio = StringIO.new(sample_packed) - u2 = MessagePack::Unpacker.new(sio) - u2.each do |obj| - expect(obj).to eql(sample_data) - end - - dio = StringIO.new - Zlib::GzipWriter.wrap(dio){|gz| gz.write sample_packed } - reader = Zlib::GzipReader.new(StringIO.new(dio.string)) - u3 = MessagePack::Unpacker.new(reader) - u3.each do |obj| - expect(obj).to eql(sample_data) - end - - class DummyIO - def initialize - @buf = "".force_encoding('ASCII-8BIT') - @pos = 0 - end - def write(val) - @buf << val.to_s - end - def read(length=nil,outbuf="") - if @pos == @buf.size - nil - elsif length.nil? - val = @buf[@pos..(@buf.size)] - @pos = @buf.size - outbuf << val - outbuf - else - val = @buf[@pos..(@pos + length)] - @pos += val.size - @pos = @buf.size if @pos > @buf.size - outbuf << val - outbuf - end - end - def flush - # nop - end - end - - dio = DummyIO.new - dio.write sample_packed - u4 = MessagePack::Unpacker.new(dio) - u4.each do |obj| - expect(obj).to eql(sample_data) - end - end - - it 'read_array_header succeeds' do - unpacker.feed("\x91") - unpacker.read_array_header.should == 1 - end - - it 'read_array_header fails' do - unpacker.feed("\x81") - lambda { - unpacker.read_array_header - }.should raise_error(MessagePack::TypeError) # TypeError is included in UnexpectedTypeError - lambda { - unpacker.read_array_header - }.should raise_error(MessagePack::UnexpectedTypeError) - end - - it 'read_map_header converts an map to key-value sequence' do - packer.write_array_header(2) - packer.write("e") - packer.write(1) - unpacker = MessagePack::Unpacker.new - unpacker.feed(packer.to_s) - unpacker.read_array_header.should == 2 - unpacker.read.should == "e" - unpacker.read.should == 1 - end - - it 'read_map_header succeeds' do - unpacker.feed("\x81") - unpacker.read_map_header.should == 1 - end - - it 'read_map_header converts an map to key-value sequence' do - packer.write_map_header(1) - packer.write("k") - packer.write("v") - unpacker = MessagePack::Unpacker.new - unpacker.feed(packer.to_s) - unpacker.read_map_header.should == 1 - unpacker.read.should == "k" - unpacker.read.should == "v" - end - - it 'read_map_header fails' do - unpacker.feed("\x91") - lambda { - unpacker.read_map_header - }.should raise_error(MessagePack::TypeError) # TypeError is included in UnexpectedTypeError - lambda { - unpacker.read_map_header - }.should raise_error(MessagePack::UnexpectedTypeError) - end - - it 'read raises EOFError before feeding' do - lambda { - unpacker.read - }.should raise_error(EOFError) - end - - let :sample_object do - [1024, {["a","b"]=>["c","d"]}, ["e","f"], "d", 70000, 4.12, 1.5, 1.5, 1.5] - end - - it 'feed and each continue internal state' do - raw = sample_object.to_msgpack.to_s * 4 - objects = [] - - raw.split(//).each do |b| - unpacker.feed(b) - unpacker.each {|c| - objects << c - } - end - - objects.should == [sample_object] * 4 - end - - it 'feed and each empty string' do - raw = sample_object.to_msgpack.to_s - objects = [] - - unpacker.feed("") - unpacker.feed(raw) - unpacker.feed("") - - unpacker.each { |c| - objects << c - } - objects.should == [sample_object] - end - - it 'feed_each continues internal state' do - raw = sample_object.to_msgpack.to_s * 4 - objects = [] - - raw.split(//).each do |b| - unpacker.feed_each(b) {|c| - objects << c - } - end - - objects.should == [sample_object] * 4 - end - - it 'feed_each enumerator' do - raw = sample_object.to_msgpack.to_s * 4 - - enum = unpacker.feed_each(raw) - enum.should be_instance_of(Enumerator) - enum.to_a.should == [sample_object] * 4 - end - - it 'reset clears internal buffer' do - # 1-element array - unpacker.feed("\x91") - unpacker.reset - unpacker.feed("\x01") - - unpacker.each.map {|x| x }.should == [1] - end - - it 'reset clears internal state' do - # 1-element array - unpacker.feed("\x91") - unpacker.each.map {|x| x }.should == [] - - unpacker.reset - - unpacker.feed("\x01") - unpacker.each.map {|x| x }.should == [1] - end - - it 'frozen short strings' do - raw = sample_object.to_msgpack.to_s.force_encoding('UTF-8') - lambda { - unpacker.feed_each(raw.freeze) { } - }.should_not raise_error - end - - it 'frozen long strings' do - raw = (sample_object.to_msgpack.to_s * 10240).force_encoding('UTF-8') - lambda { - unpacker.feed_each(raw.freeze) { } - }.should_not raise_error - end - - it 'read raises invalid byte error' do - unpacker.feed("\xc1") - lambda { - unpacker.read - }.should raise_error(MessagePack::MalformedFormatError) - end - - it "gc mark" do - raw = sample_object.to_msgpack.to_s * 4 - - n = 0 - raw.split(//).each do |b| - GC.start - unpacker.feed_each(b) {|o| - GC.start - o.should == sample_object - n += 1 - } - GC.start - end - - n.should == 4 - end - - it "buffer" do - orig = "a"*32*1024*4 - raw = orig.to_msgpack.to_s - - n = 655 - times = raw.size / n - times += 1 unless raw.size % n == 0 - - off = 0 - parsed = false - - times.times do - parsed.should == false - - seg = raw[off, n] - off += seg.length - - unpacker.feed_each(seg) {|obj| - parsed.should == false - obj.should == orig - parsed = true - } - end - - parsed.should == true - end - - it 'MessagePack.unpack symbolize_keys' do - symbolized_hash = {:a => 'b', :c => 'd'} - MessagePack.load(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash - MessagePack.unpack(MessagePack.pack(symbolized_hash), :symbolize_keys => true).should == symbolized_hash - end - - it 'MessagePack.unpack symbolize_keys preserve encoding' do - hash = { :ascii => 1, :utf8_é => 2} - loaded_hash = MessagePack.load(MessagePack.pack(hash), :symbolize_keys => true) - - hash.keys[0].encoding.should == Encoding::US_ASCII # Ruby coerce symbols to US-ASCII when possible. - loaded_hash.keys[0].should == hash.keys[0] - loaded_hash.keys[0].encoding.should == hash.keys[0].encoding - - hash.keys[1].encoding.should == Encoding::UTF_8 - loaded_hash.keys[1].should == hash.keys[1] - loaded_hash.keys[1].encoding.should == hash.keys[1].encoding - - MessagePack.unpack(MessagePack.pack(hash), :symbolize_keys => true).should == hash - end - - it 'Unpacker#unpack symbolize_keys' do - unpacker = MessagePack::Unpacker.new(:symbolize_keys => true) - symbolized_hash = {:a => 'b', :c => 'd'} - unpacker.feed(MessagePack.pack(symbolized_hash)).read.should == symbolized_hash - end - - it "msgpack str 8 type" do - MessagePack.unpack([0xd9, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xd9, 0x00].pack('C*')).encoding.should == Encoding::UTF_8 - MessagePack.unpack([0xd9, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xd9, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack str 16 type" do - MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xda, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8 - MessagePack.unpack([0xda, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xda, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack str 32 type" do - MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x00].pack('C*')).encoding.should == Encoding::UTF_8 - MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xdb, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack bin 8 type" do - MessagePack.unpack([0xc4, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xc4, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT - MessagePack.unpack([0xc4, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xc4, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack bin 16 type" do - MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xc5, 0x00, 0x00].pack('C*')).encoding.should == Encoding::ASCII_8BIT - MessagePack.unpack([0xc5, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xc5, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end - - it "msgpack bin 32 type" do - MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x00].pack('C*')).should == "" - MessagePack.unpack([0xc6, 0x0, 0x00, 0x00, 0x000].pack('C*')).encoding.should == Encoding::ASCII_8BIT - MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x01].pack('C*') + 'a').should == "a" - MessagePack.unpack([0xc6, 0x00, 0x00, 0x00, 0x02].pack('C*') + 'aa').should == "aa" - end - - describe "ext formats" do - let(:unpacker) { MessagePack::Unpacker.new(allow_unknown_ext: true) } - - [1, 2, 4, 8, 16].zip([0xd4, 0xd5, 0xd6, 0xd7, 0xd8]).each do |n,b| - it "msgpack fixext #{n} format" do - unpacker.feed([b, 1].pack('CC') + "a"*n).unpack.should == MessagePack::ExtensionValue.new(1, "a"*n) - unpacker.feed([b, -1].pack('CC') + "a"*n).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*n) - end - end - - it "msgpack ext 8 format" do - unpacker.feed([0xc7, 0, 1].pack('CCC')).unpack.should == MessagePack::ExtensionValue.new(1, "") - unpacker.feed([0xc7, 255, -1].pack('CCC') + "a"*255).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*255) - end - - it "msgpack ext 16 format" do - unpacker.feed([0xc8, 0, 1].pack('CnC')).unpack.should == MessagePack::ExtensionValue.new(1, "") - unpacker.feed([0xc8, 256, -1].pack('CnC') + "a"*256).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*256) - end - - it "msgpack ext 32 format" do - unpacker.feed([0xc9, 0, 1].pack('CNC')).unpack.should == MessagePack::ExtensionValue.new(1, "") - unpacker.feed([0xc9, 256, -1].pack('CNC') + "a"*256).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*256) - unpacker.feed([0xc9, 65536, -1].pack('CNC') + "a"*65536).unpack.should == MessagePack::ExtensionValue.new(-1, "a"*65536) - end - end - - class ValueOne - attr_reader :num - def initialize(num) - @num = num - end - def ==(obj) - self.num == obj.num - end - def num - @num - end - def to_msgpack_ext - @num.to_msgpack - end - def self.from_msgpack_ext(data) - self.new(MessagePack.unpack(data)) - end - end - - class ValueTwo - attr_reader :num_s - def initialize(num) - @num_s = num.to_s - end - def ==(obj) - self.num_s == obj.num_s - end - def num - @num_s.to_i - end - def to_msgpack_ext - @num_s.to_msgpack - end - def self.from_msgpack_ext(data) - self.new(MessagePack.unpack(data)) - end - end - - describe '#type_registered?' do - it 'receive Class or Integer, and return bool' do - expect(subject.type_registered?(0x00)).to be_falsy - expect(subject.type_registered?(0x01)).to be_falsy - expect(subject.type_registered?(::ValueOne)).to be_falsy - end - - it 'returns true if specified type or class is already registered' do - subject.register_type(0x30, ::ValueOne, :from_msgpack_ext) - subject.register_type(0x31, ::ValueTwo, :from_msgpack_ext) - - expect(subject.type_registered?(0x00)).to be_falsy - expect(subject.type_registered?(0x01)).to be_falsy - - expect(subject.type_registered?(0x30)).to be_truthy - expect(subject.type_registered?(0x31)).to be_truthy - expect(subject.type_registered?(::ValueOne)).to be_truthy - expect(subject.type_registered?(::ValueTwo)).to be_truthy - end - - it 'cannot detect unpack rule with block, not method' do - subject.register_type(0x40){|data| ValueOne.from_msgpack_ext(data) } - - expect(subject.type_registered?(0x40)).to be_truthy - expect(subject.type_registered?(ValueOne)).to be_falsy - end - end - - context 'with ext definitions' do - it 'get type and class mapping for packing' do - unpacker = MessagePack::Unpacker.new - unpacker.register_type(0x01){|data| ValueOne.from_msgpack_ext } - unpacker.register_type(0x02){|data| ValueTwo.from_msgpack_ext(data) } - - unpacker = MessagePack::Unpacker.new - unpacker.register_type(0x01, ValueOne, :from_msgpack_ext) - unpacker.register_type(0x02, ValueTwo, :from_msgpack_ext) - end - - it 'returns a Array of Hash which contains :type, :class and :unpacker' do - unpacker = MessagePack::Unpacker.new - unpacker.register_type(0x02, ValueTwo, :from_msgpack_ext) - unpacker.register_type(0x01, ValueOne, :from_msgpack_ext) - - list = unpacker.registered_types - - expect(list).to be_a(Array) - expect(list.size).to eq(2) - - one = list[0] - expect(one.keys.sort).to eq([:type, :class, :unpacker].sort) - expect(one[:type]).to eq(0x01) - expect(one[:class]).to eq(ValueOne) - expect(one[:unpacker]).to be_a(Proc) - - two = list[1] - expect(two.keys.sort).to eq([:type, :class, :unpacker].sort) - expect(two[:type]).to eq(0x02) - expect(two[:class]).to eq(ValueTwo) - expect(two[:unpacker]).to be_a(Proc) - end - - it 'returns a Array of Hash, which contains nil for class if block unpacker specified' do - unpacker = MessagePack::Unpacker.new - unpacker.register_type(0x01){|data| ValueOne.from_msgpack_ext } - unpacker.register_type(0x02, &ValueTwo.method(:from_msgpack_ext)) - - list = unpacker.registered_types - - expect(list).to be_a(Array) - expect(list.size).to eq(2) - - one = list[0] - expect(one.keys.sort).to eq([:type, :class, :unpacker].sort) - expect(one[:type]).to eq(0x01) - expect(one[:class]).to be_nil - expect(one[:unpacker]).to be_instance_of(Proc) - - two = list[1] - expect(two.keys.sort).to eq([:type, :class, :unpacker].sort) - expect(two[:type]).to eq(0x02) - expect(two[:class]).to be_nil - expect(two[:unpacker]).to be_instance_of(Proc) - end - - describe "registering an ext type for a module" do - subject { unpacker.feed("\xc7\x06\x00module").unpack } - - let(:unpacker) { MessagePack::Unpacker.new } - - before do - mod = Module.new do - def self.from_msgpack_ext(data) - "unpacked #{data}" - end - end - stub_const('Mod', mod) - end - - before { unpacker.register_type(0x00, Mod, :from_msgpack_ext) } - it { is_expected.to eq "unpacked module" } - end - end - - def flatten(struct, results = []) - case struct - when Array - struct.each { |v| flatten(v, results) } - when Hash - struct.each { |k, v| flatten(v, flatten(k, results)) } - else - results << struct - end - results - end - - subject do - described_class.new - end - - let :buffer1 do - MessagePack.pack(:foo => 'bar') - end - - let :buffer2 do - MessagePack.pack(:hello => {:world => [1, 2, 3]}) - end - - let :buffer3 do - MessagePack.pack(:x => 'y') - end - - describe '#read' do - context 'with a buffer' do - it 'reads objects' do - objects = [] - subject.feed(buffer1) - subject.feed(buffer2) - subject.feed(buffer3) - objects << subject.read - objects << subject.read - objects << subject.read - objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}] - end - - it 'reads map header' do - subject.feed({}.to_msgpack) - subject.read_map_header.should == 0 - end - - it 'reads array header' do - subject.feed([].to_msgpack) - subject.read_array_header.should == 0 - end - end - end - - describe '#each' do - context 'with a buffer' do - it 'yields each object in the buffer' do - objects = [] - subject.feed(buffer1) - subject.feed(buffer2) - subject.feed(buffer3) - subject.each do |obj| - objects << obj - end - objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}] - end - - it 'returns an enumerator when no block is given' do - subject.feed(buffer1) - subject.feed(buffer2) - subject.feed(buffer3) - enum = subject.each - enum.map { |obj| obj.keys.first }.should == %w[foo hello x] - end - end - - context 'with a stream passed to the constructor' do - it 'yields each object in the stream' do - objects = [] - unpacker = described_class.new(StringIO.new(buffer1 + buffer2 + buffer3)) - unpacker.each do |obj| - objects << obj - end - objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}] - end - end - - context 'with a stream and symbolize_keys passed to the constructor' do - it 'yields each object in the stream, with symbolized keys' do - objects = [] - unpacker = described_class.new(StringIO.new(buffer1 + buffer2 + buffer3), symbolize_keys: true) - unpacker.each do |obj| - objects << obj - end - objects.should == [{:foo => 'bar'}, {:hello => {:world => [1, 2, 3]}}, {:x => 'y'}] - end - end - end - - describe '#feed_each' do - it 'feeds the buffer then runs #each' do - objects = [] - subject.feed_each(buffer1 + buffer2 + buffer3) do |obj| - objects << obj - end - objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}] - end - - it 'handles chunked data' do - objects = [] - buffer = buffer1 + buffer2 + buffer3 - buffer.chars.each do |ch| - subject.feed_each(ch) do |obj| - objects << obj - end - end - objects.should == [{'foo' => 'bar'}, {'hello' => {'world' => [1, 2, 3]}}, {'x' => 'y'}] - end - end - - context 'regressions' do - it 'handles massive arrays (issue #2)' do - array = ['foo'] * 10_000 - MessagePack.unpack(MessagePack.pack(array)).size.should == 10_000 - end - - it 'preserves string encoding (issue #200)' do - string = 'a'.force_encoding(Encoding::UTF_8) - MessagePack.unpack(MessagePack.pack(string)).encoding.should == string.encoding - - string *= 256 - MessagePack.unpack(MessagePack.pack(string)).encoding.should == string.encoding - end - - it 'returns correct size for array16 (issue #127)' do - unpacker.feed("\xdc\x00\x01\x01") - unpacker.read_array_header.should == 1 - end - - it 'returns correct size for map16 (issue #127)' do - unpacker.feed("\xde\x00\x02\x01\x02\x03\x04") - unpacker.read_map_header.should == 2 - end - end - - context 'extensions' do - context 'symbolized keys' do - let :buffer do - MessagePack.pack({'hello' => 'world', 'nested' => ['object', {'structure' => true}]}) - end - - let :unpacker do - described_class.new(:symbolize_keys => true) - end - - it 'can symbolize keys when using #each' do - objs = [] - unpacker.feed(buffer) - unpacker.each do |obj| - objs << obj - end - objs.should == [{:hello => 'world', :nested => ['object', {:structure => true}]}] - end - - it 'can symbolize keys when using #feed_each' do - objs = [] - unpacker.feed_each(buffer) do |obj| - objs << obj - end - objs.should == [{:hello => 'world', :nested => ['object', {:structure => true}]}] - end - end - - context 'freeze' do - let :struct do - {'hello' => 'world', 'nested' => ['object', {'structure' => true}]} - end - - let :buffer do - MessagePack.pack(struct) - end - - let :unpacker do - described_class.new(:freeze => true) - end - - if (-"test").equal?(-"test") # RUBY_VERSION >= "2.5" - it 'dedups strings' do - interned_str = -"test" - roundtrip = MessagePack.unpack(MessagePack.pack(interned_str), freeze: true) - expect(roundtrip).to be interned_str - - interned_str = -"" - roundtrip = MessagePack.unpack(MessagePack.pack(interned_str), freeze: true) - expect(roundtrip).to be interned_str - end - end - - it 'can freeze objects when using .unpack' do - parsed_struct = MessagePack.unpack(buffer, freeze: true) - parsed_struct.should == struct - - parsed_struct.should be_frozen - parsed_struct['hello'].should be_frozen - parsed_struct['nested'].should be_frozen - parsed_struct['nested'][0].should be_frozen - parsed_struct['nested'][1].should be_frozen - - if string_deduplication? - parsed_struct.keys[0].should be_equal('hello'.freeze) - parsed_struct.keys[1].should be_equal('nested'.freeze) - parsed_struct.values[0].should be_equal('world'.freeze) - parsed_struct.values[1][0].should be_equal('object'.freeze) - parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze) - end - end - - it 'can freeze objects when using #each' do - objs = [] - unpacker.feed(buffer) - unpacker.each do |obj| - objs << obj - end - - parsed_struct = objs.first - parsed_struct.should == struct - - parsed_struct.should be_frozen - parsed_struct['hello'].should be_frozen - parsed_struct['nested'].should be_frozen - parsed_struct['nested'][0].should be_frozen - parsed_struct['nested'][1].should be_frozen - - if string_deduplication? - parsed_struct.keys[0].should be_equal('hello'.freeze) - parsed_struct.keys[1].should be_equal('nested'.freeze) - parsed_struct.values[0].should be_equal('world'.freeze) - parsed_struct.values[1][0].should be_equal('object'.freeze) - parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze) - end - end - - it 'can freeze objects when using #feed_each' do - objs = [] - unpacker.feed_each(buffer) do |obj| - objs << obj - end - - parsed_struct = objs.first - parsed_struct.should == struct - - parsed_struct.should be_frozen - parsed_struct['hello'].should be_frozen - parsed_struct['nested'].should be_frozen - parsed_struct['nested'][0].should be_frozen - parsed_struct['nested'][1].should be_frozen - - if string_deduplication? - parsed_struct.keys[0].should be_equal('hello'.freeze) - parsed_struct.keys[1].should be_equal('nested'.freeze) - parsed_struct.values[0].should be_equal('world'.freeze) - parsed_struct.values[1][0].should be_equal('object'.freeze) - parsed_struct.values[1][1].keys[0].should be_equal('structure'.freeze) - end - end - end - - context 'binary encoding', :encodings do - let :buffer do - MessagePack.pack({ - 'hello'.b => 'world'.b, - 'nested'.b => [ - 'object'.b, - {'structure'.b => true}, - ] - }) - end - - let :unpacker do - described_class.new() - end - - it 'decodes binary as ascii-8bit when using #feed' do - objs = [] - unpacker.feed(buffer) - unpacker.each do |obj| - objs << obj - end - strings = flatten(objs).grep(String) - strings.should == %w[hello world nested object structure] - strings.map(&:encoding).uniq.should == [Encoding::ASCII_8BIT] - end - - it 'decodes binary as ascii-8bit when using #feed_each' do - objs = [] - unpacker.feed_each(buffer) do |obj| - objs << obj - end - strings = flatten(objs).grep(String) - strings.should == %w[hello world nested object structure] - strings.map(&:encoding).uniq.should == [Encoding::ASCII_8BIT] - end - end - - context 'string encoding', :encodings do - let :buffer do - MessagePack.pack({'hello'.force_encoding(Encoding::UTF_8) => 'world'.force_encoding(Encoding::UTF_8), 'nested'.force_encoding(Encoding::UTF_8) => ['object'.force_encoding(Encoding::UTF_8), {'structure'.force_encoding(Encoding::UTF_8) => true}]}) - end - - let :unpacker do - described_class.new() - end - - it 'decodes string as utf-8 when using #feed' do - objs = [] - unpacker.feed(buffer) - unpacker.each do |obj| - objs << obj - end - strings = flatten(objs).grep(String) - strings.should == %w[hello world nested object structure] - strings.map(&:encoding).uniq.should == [Encoding::UTF_8] - end - - it 'decodes binary as ascii-8bit when using #feed_each' do - objs = [] - unpacker.feed_each(buffer) do |obj| - objs << obj - end - strings = flatten(objs).grep(String) - strings.should == %w[hello world nested object structure] - strings.map(&:encoding).uniq.should == [Encoding::UTF_8] - end - end - end - - it "doesn't allow #dup or #clone" do - expect(subject).to_not respond_to :dup - expect(subject).to_not respond_to :clone - end - - it "doesn't crash when marking an uninitialized buffer" do - if RUBY_PLATFORM == "java" - pending("THe java extension is missing Unpacker#buffer https://github.com/msgpack/msgpack-ruby/issues/315") - end - - stress = GC.stress - begin - GC.stress = true - - MessagePack::Unpacker.new.buffer - Object.new - ensure - GC.stress = stress - end - end - - if RUBY_PLATFORM != "java" - it "doesn't leak when a recursive unpacker raises" do - hash_with_indifferent_access = Class.new(Hash) - msgpack = MessagePack::Factory.new - msgpack.register_type( - 0x02, - hash_with_indifferent_access, - packer: ->(value, packer) do - packer.write(value.to_h) - end, - unpacker: ->(unpacker) { raise RuntimeError, "Ooops" }, - recursive: true - ) - - packer = msgpack.packer - data = [[[[[[[hash_with_indifferent_access.new]]]]]]] - payload = msgpack.dump(data) - - unpacker = msgpack.unpacker - 2.times do - unpacker.buffer.clear - unpacker.feed(payload) - expect { - unpacker.full_unpack - }.to raise_error(RuntimeError, "Ooops") - end - - memsize = ObjectSpace.memsize_of(unpacker) - - 10.times do - unpacker.buffer.clear - unpacker.feed(payload) - expect { - unpacker.full_unpack - }.to raise_error(RuntimeError, "Ooops") - end - - expect(memsize).to eq ObjectSpace.memsize_of(unpacker) - end - end -end diff --git a/top-level-namespace.html b/top-level-namespace.html new file mode 100644 index 00000000..b1633b00 --- /dev/null +++ b/top-level-namespace.html @@ -0,0 +1,112 @@ +<!DOCTYPE html> +<html> + <head> + <meta charset="utf-8"> +<meta name="viewport" content="width=device-width, initial-scale=1.0"> +<title> + Top Level Namespace + + — Documentation by YARD 0.9.37 + +</title> + + <link rel="stylesheet" href="css/style.css" type="text/css" /> + + <link rel="stylesheet" href="css/common.css" type="text/css" /> + +<script type="text/javascript"> + pathId = ""; + relpath = ''; +</script> + + + <script type="text/javascript" charset="utf-8" src="js/jquery.js"></script> + + <script type="text/javascript" charset="utf-8" src="js/app.js"></script> + + + </head> + <body> + <div class="nav_wrap"> + <iframe id="nav" src="class_list.html?1"></iframe> + <div id="resizer"></div> + </div> + + <div id="main" tabindex="-1"> + <div id="header"> + <div id="menu"> + + <a href="_index.html">Index</a> » + + + <span class="title">Top Level Namespace</span> + +</div> + + <div id="search"> + + <a class="full_list_link" id="class_list_link" + href="class_list.html"> + + <svg width="24" height="24"> + <rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect> + <rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect> + </svg> + </a> + +</div> + <div class="clear"></div> + </div> + + <div id="content"><h1>Top Level Namespace + + + +</h1> +<div class="box_info"> + + + + + + + + + + + +</div> + +<h2>Defined Under Namespace</h2> +<p class="children"> + + + <strong class="modules">Modules:</strong> <span class='object_link'><a href="MessagePack.html" title="MessagePack (module)">MessagePack</a></span> + + + + <strong class="classes">Classes:</strong> <span class='object_link'><a href="Array.html" title="Array (class)">Array</a></span>, <span class='object_link'><a href="Bignum.html" title="Bignum (class)">Bignum</a></span>, <span class='object_link'><a href="FalseClass.html" title="FalseClass (class)">FalseClass</a></span>, <span class='object_link'><a href="Fixnum.html" title="Fixnum (class)">Fixnum</a></span>, <span class='object_link'><a href="Float.html" title="Float (class)">Float</a></span>, <span class='object_link'><a href="Hash.html" title="Hash (class)">Hash</a></span>, <span class='object_link'><a href="NilClass.html" title="NilClass (class)">NilClass</a></span>, <span class='object_link'><a href="String.html" title="String (class)">String</a></span>, <span class='object_link'><a href="Symbol.html" title="Symbol (class)">Symbol</a></span>, <span class='object_link'><a href="TrueClass.html" title="TrueClass (class)">TrueClass</a></span> + + +</p> + + + + + + + + + +</div> + + <div id="footer"> + Generated on Thu Feb 6 09:27:11 2025 by + <a href="https://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a> + 0.9.37 (ruby-3.4.1). +</div> + + </div> + </body> +</html> \ No newline at end of file