| 1234567891011121314151617 |
- <!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><!--[if IE]><meta http-equiv="X-UA-Compatible" content="IE=edge"><![endif]--><meta name="viewport" content="width=device-width, initial-scale=1.0"><meta name="generator" content="Asciidoctor 1.5.4"><title>Compression</title><link rel="stylesheet" href="./asciidoctor.css">
- <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.5.0/css/font-awesome.min.css">
- <link rel="stylesheet" href="./coderay-asciidoctor.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.css"></head><body class="article toc2 toc-left"><div id="header"><div id="toolbar"><a href="https://github.com/jMonkeyEngine/wiki/edit/master/src/docs/asciidoc/spidermonkey/tutorial/compression.adoc"><i class="fa fa-pencil-square" aria-hidden="true"></i></a><a href="https://github.com/jMonkeyEngine/wiki/new/master/src/docs/asciidoc/spidermonkey/tutorial/"><i class="fa fa-plus-square" aria-hidden="true"></i></a><input dir="auto" style="position: relative; vertical-align: top;" spellcheck="false" autocomplete="off" class="searchbox__input aa-input" id="doc-search" name="search" placeholder="Search in the doc" required="required" type="search"></div><h1>Compression</h1><div class="details"><span class="author" id="author"></span><br><span id="revnumber">version ,</span> <span id="revdate">2016/03/17 20:48</span></div><div id="toc" class="toc2"><div id="toctitle">Table of Contents</div><ul class="sectlevel1"><li><a href="#writing-your-own">Writing your own</a></li></ul></div></div><div id="content"><div id="preamble"><div class="sectionbody"><div class="admonitionblock warning"><table><tr><td class="icon"><i class="fa icon-warning" title="Warning"></i></td><td class="content"><div class="paragraph"><p>This article covers a deprecated <abbr title="Application Programming Interface">API</abbr>! See <a href="../../jme3/advanced/networking.html">networking</a> for current documentation.</p></div></td></tr></table></div>
- <div class="paragraph"><p>Now this is going to be a real simply tutorial but still I wanted this in a separate article. Why you may ask? Simply because it’s a feature that requires some explanation, since it has some caveats that I’ll discuss. Also, I’ll cover writing your own compression message.</p></div>
- <div class="paragraph"><p>First off - there are two compression types in SpiderMonkey, they are GZip and Zip. Could’ve added more, but didn’t want to have a dependency for just a compression method. Both are used by wrapping your message in the appropriate compression message:</p></div>
- <div class="listingblock"><div class="content"><pre class="CodeRay highlight"><code data-lang="java">MyMessage msg = <span class="keyword">new</span> MyMessage();
- client.send(<span class="keyword">new</span> GZIPCompressedMessage(msg));
- <span class="comment">// or</span>
- client.send(<span class="keyword">new</span> ZIPCompressedMessage(msg));</code></pre></div></div>
- <div class="paragraph"><p>Really simple, but ZIP requires some explanation. The ZIPCompressedMessage class also has two extra methods; setLevel(int) and getLevel(). These methods are for setting the compression level, where 1 is best compression but slowest, and where 9 is weakest compression but fastest. Please note that 9 is <strong>not</strong> the so called 'store' ZIP method, which simply stores file in the ZIP, instead of compressing it. This 'store' feature is not in SpiderMonkey since otherwise it would not have been called compression.</p></div></div></div>
- <div class="sect1"><h2 id="writing-your-own">Writing your own</h2><div class="sectionbody"><div class="paragraph"><p>Now of course I’d love to see more compression methods in SpiderMonkey, so I’ll discuss how to write your own. Let’s just take GZIPCompressedMessage as example, since that one is the most straightforward. What I’ve done, is I’ve just created a GZIPCompressedMessage which extends CompressedMessage. It does not contain any extra messages, so the GZIPCompressedMessage class is practically 'empty'. The magic happens at the serializer, which is called the GZIPSerializer (you can read about writing your own serializer <a href="../../spidermonkey/tutorial/serializing.html">here</a>). Then I just registered the GZIPSerializer to GZIPCompressedMessage and presto - you’re done. Don’t forget that in the Serializer you need to use writeClassAndObject first and then compress that data, and for read you’d need to use readClassAndObject after you’ve uncompressed (inflated) the message. For this to be clear, it may be useful to read <a href="http://code.google.com/p/jmonkeyengine/source/browse/trunk/engine/src/networking/com/jme3/network/serializing/serializers/GZIPSerializer.java">the GZIPSerializer class</a>.</p></div>
- <div class="paragraph"><p>That’s that! Next tutorial we’re going to discuss how to use the Service system.</p></div></div></div></div><div id="footer"><div id="footer-text">Version <br>Last updated 2019-12-15 23:15:33 +00:00</div></div><script type="text/javascript" src="https://cdn.jsdelivr.net/docsearch.js/2/docsearch.min.js"></script><script>docsearch({
- apiKey: 'a736b6d93de805e26ec2f49b55013fbd',
- indexName: 'jmonkeyengine',
- inputSelector: '#doc-search',
- debug: false // Set debug to true if you want to inspect the dropdown
- });</script></body></html>
|