diff --git a/epl-v10.html b/epl-v10.html
deleted file mode 100644
index 813c07d..0000000
--- a/epl-v10.html
+++ /dev/null
@@ -1,261 +0,0 @@
-
-
-
-
-
-
-Eclipse Public License - Version 1.0
-
-
-
-
-
-
-Eclipse Public License - v 1.0
-
-THE ACCOMPANYING PROGRAM IS PROVIDED UNDER THE TERMS OF THIS ECLIPSE
-PUBLIC LICENSE ("AGREEMENT"). ANY USE, REPRODUCTION OR
-DISTRIBUTION OF THE PROGRAM CONSTITUTES RECIPIENT'S ACCEPTANCE OF THIS
-AGREEMENT.
-
-1. DEFINITIONS
-
-"Contribution" means:
-
-a) in the case of the initial Contributor, the initial
-code and documentation distributed under this Agreement, and
-b) in the case of each subsequent Contributor:
-i) changes to the Program, and
-ii) additions to the Program;
-where such changes and/or additions to the Program
-originate from and are distributed by that particular Contributor. A
-Contribution 'originates' from a Contributor if it was added to the
-Program by such Contributor itself or anyone acting on such
-Contributor's behalf. Contributions do not include additions to the
-Program which: (i) are separate modules of software distributed in
-conjunction with the Program under their own license agreement, and (ii)
-are not derivative works of the Program.
-
-"Contributor" means any person or entity that distributes
-the Program.
-
-"Licensed Patents" mean patent claims licensable by a
-Contributor which are necessarily infringed by the use or sale of its
-Contribution alone or when combined with the Program.
-
-"Program" means the Contributions distributed in accordance
-with this Agreement.
-
-"Recipient" means anyone who receives the Program under
-this Agreement, including all Contributors.
-
-2. GRANT OF RIGHTS
-
-a) Subject to the terms of this Agreement, each
-Contributor hereby grants Recipient a non-exclusive, worldwide,
-royalty-free copyright license to reproduce, prepare derivative works
-of, publicly display, publicly perform, distribute and sublicense the
-Contribution of such Contributor, if any, and such derivative works, in
-source code and object code form.
-
-b) Subject to the terms of this Agreement, each
-Contributor hereby grants Recipient a non-exclusive, worldwide,
-royalty-free patent license under Licensed Patents to make, use, sell,
-offer to sell, import and otherwise transfer the Contribution of such
-Contributor, if any, in source code and object code form. This patent
-license shall apply to the combination of the Contribution and the
-Program if, at the time the Contribution is added by the Contributor,
-such addition of the Contribution causes such combination to be covered
-by the Licensed Patents. The patent license shall not apply to any other
-combinations which include the Contribution. No hardware per se is
-licensed hereunder.
-
-c) Recipient understands that although each Contributor
-grants the licenses to its Contributions set forth herein, no assurances
-are provided by any Contributor that the Program does not infringe the
-patent or other intellectual property rights of any other entity. Each
-Contributor disclaims any liability to Recipient for claims brought by
-any other entity based on infringement of intellectual property rights
-or otherwise. As a condition to exercising the rights and licenses
-granted hereunder, each Recipient hereby assumes sole responsibility to
-secure any other intellectual property rights needed, if any. For
-example, if a third party patent license is required to allow Recipient
-to distribute the Program, it is Recipient's responsibility to acquire
-that license before distributing the Program.
-
-d) Each Contributor represents that to its knowledge it
-has sufficient copyright rights in its Contribution, if any, to grant
-the copyright license set forth in this Agreement.
-
-3. REQUIREMENTS
-
-A Contributor may choose to distribute the Program in object code
-form under its own license agreement, provided that:
-
-a) it complies with the terms and conditions of this
-Agreement; and
-
-b) its license agreement:
-
-i) effectively disclaims on behalf of all Contributors
-all warranties and conditions, express and implied, including warranties
-or conditions of title and non-infringement, and implied warranties or
-conditions of merchantability and fitness for a particular purpose;
-
-ii) effectively excludes on behalf of all Contributors
-all liability for damages, including direct, indirect, special,
-incidental and consequential damages, such as lost profits;
-
-iii) states that any provisions which differ from this
-Agreement are offered by that Contributor alone and not by any other
-party; and
-
-iv) states that source code for the Program is available
-from such Contributor, and informs licensees how to obtain it in a
-reasonable manner on or through a medium customarily used for software
-exchange.
-
-When the Program is made available in source code form:
-
-a) it must be made available under this Agreement; and
-
-b) a copy of this Agreement must be included with each
-copy of the Program.
-
-Contributors may not remove or alter any copyright notices contained
-within the Program.
-
-Each Contributor must identify itself as the originator of its
-Contribution, if any, in a manner that reasonably allows subsequent
-Recipients to identify the originator of the Contribution.
-
-4. COMMERCIAL DISTRIBUTION
-
-Commercial distributors of software may accept certain
-responsibilities with respect to end users, business partners and the
-like. While this license is intended to facilitate the commercial use of
-the Program, the Contributor who includes the Program in a commercial
-product offering should do so in a manner which does not create
-potential liability for other Contributors. Therefore, if a Contributor
-includes the Program in a commercial product offering, such Contributor
-("Commercial Contributor") hereby agrees to defend and
-indemnify every other Contributor ("Indemnified Contributor")
-against any losses, damages and costs (collectively "Losses")
-arising from claims, lawsuits and other legal actions brought by a third
-party against the Indemnified Contributor to the extent caused by the
-acts or omissions of such Commercial Contributor in connection with its
-distribution of the Program in a commercial product offering. The
-obligations in this section do not apply to any claims or Losses
-relating to any actual or alleged intellectual property infringement. In
-order to qualify, an Indemnified Contributor must: a) promptly notify
-the Commercial Contributor in writing of such claim, and b) allow the
-Commercial Contributor to control, and cooperate with the Commercial
-Contributor in, the defense and any related settlement negotiations. The
-Indemnified Contributor may participate in any such claim at its own
-expense.
-
-For example, a Contributor might include the Program in a commercial
-product offering, Product X. That Contributor is then a Commercial
-Contributor. If that Commercial Contributor then makes performance
-claims, or offers warranties related to Product X, those performance
-claims and warranties are such Commercial Contributor's responsibility
-alone. Under this section, the Commercial Contributor would have to
-defend claims against the other Contributors related to those
-performance claims and warranties, and if a court requires any other
-Contributor to pay any damages as a result, the Commercial Contributor
-must pay those damages.
-
-5. NO WARRANTY
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, THE PROGRAM IS
-PROVIDED 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. Each Recipient is solely
-responsible for determining the appropriateness of using and
-distributing the Program and assumes all risks associated with its
-exercise of rights under this Agreement , including but not limited to
-the risks and costs of program errors, compliance with applicable laws,
-damage to or loss of data, programs or equipment, and unavailability or
-interruption of operations.
-
-6. DISCLAIMER OF LIABILITY
-
-EXCEPT AS EXPRESSLY SET FORTH IN THIS AGREEMENT, NEITHER RECIPIENT
-NOR ANY CONTRIBUTORS SHALL HAVE ANY LIABILITY FOR ANY DIRECT, INDIRECT,
-INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING
-WITHOUT LIMITATION LOST PROFITS), HOWEVER CAUSED AND ON ANY THEORY OF
-LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
-NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OR
-DISTRIBUTION OF THE PROGRAM OR THE EXERCISE OF ANY RIGHTS GRANTED
-HEREUNDER, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
-
-7. GENERAL
-
-If any provision of this Agreement is invalid or unenforceable under
-applicable law, it shall not affect the validity or enforceability of
-the remainder of the terms of this Agreement, and without further action
-by the parties hereto, such provision shall be reformed to the minimum
-extent necessary to make such provision valid and enforceable.
-
-If Recipient institutes patent litigation against any entity
-(including a cross-claim or counterclaim in a lawsuit) alleging that the
-Program itself (excluding combinations of the Program with other
-software or hardware) infringes such Recipient's patent(s), then such
-Recipient's rights granted under Section 2(b) shall terminate as of the
-date such litigation is filed.
-
-All Recipient's rights under this Agreement shall terminate if it
-fails to comply with any of the material terms or conditions of this
-Agreement and does not cure such failure in a reasonable period of time
-after becoming aware of such noncompliance. If all Recipient's rights
-under this Agreement terminate, Recipient agrees to cease use and
-distribution of the Program as soon as reasonably practicable. However,
-Recipient's obligations under this Agreement and any licenses granted by
-Recipient relating to the Program shall continue and survive.
-
-Everyone is permitted to copy and distribute copies of this
-Agreement, but in order to avoid inconsistency the Agreement is
-copyrighted and may only be modified in the following manner. The
-Agreement Steward reserves the right to publish new versions (including
-revisions) of this Agreement from time to time. No one other than the
-Agreement Steward has the right to modify this Agreement. The Eclipse
-Foundation is the initial Agreement Steward. The Eclipse Foundation may
-assign the responsibility to serve as the Agreement Steward to a
-suitable separate entity. Each new version of the Agreement will be
-given a distinguishing version number. The Program (including
-Contributions) may always be distributed subject to the version of the
-Agreement under which it was received. In addition, after a new version
-of the Agreement is published, Contributor may elect to distribute the
-Program (including its Contributions) under the new version. Except as
-expressly stated in Sections 2(a) and 2(b) above, Recipient receives no
-rights or licenses to the intellectual property of any Contributor under
-this Agreement, whether expressly, by implication, estoppel or
-otherwise. All rights in the Program not expressly granted under this
-Agreement are reserved.
-
-This Agreement is governed by the laws of the State of New York and
-the intellectual property laws of the United States of America. No party
-to this Agreement will bring a legal action under this Agreement more
-than one year after the cause of action arose. Each party waives its
-rights to a jury trial in any resulting litigation.
-
-
-
-
diff --git a/project.clj b/project.clj
index 20e5d45..850ad69 100644
--- a/project.clj
+++ b/project.clj
@@ -1,35 +1,51 @@
-(defproject com.taoensso/nippy "2.6.0-alpha3"
+(defproject com.taoensso/nippy "2.6.0-beta1"
+ :author "Peter Taoussanis "
:description "Clojure serialization library"
:url "https://github.com/ptaoussanis/nippy"
:license {:name "Eclipse Public License"
- :url "http://www.eclipse.org/legal/epl-v10.html"}
- :dependencies [[org.clojure/clojure "1.4.0"]
- [org.clojure/tools.reader "0.8.3"]
- [org.iq80.snappy/snappy "0.3"]
- [org.tukaani/xz "1.4"]]
- :profiles {:1.4 {:dependencies [[org.clojure/clojure "1.4.0"]]}
- :1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
- :1.6 {:dependencies [[org.clojure/clojure "1.6.0-beta1"]]}
- :dev {:dependencies []}
- :test {:jvm-opts ["-Xms1024m" ; Initial heap size
- "-Xmx2048m" ; Max heap size
- ]
- :dependencies [[expectations "1.4.56"]
- [org.xerial.snappy/snappy-java "1.1.1-M1"]
- [reiddraper/simple-check "0.5.6"]
- [org.clojure/data.fressian "0.2.0"]]}
- :bench {:dependencies [] :jvm-opts ^:replace ["-server"]}}
- :aliases {"test-all" ["with-profile" "+test,+1.4:+test,+1.5:+test,+1.6" "expectations"]
- "test-auto" ["with-profile" "+test" "autoexpect"]
- "start-dev" ["with-profile" "+dev,+test,+bench" "repl" ":headless"]
- "start-bench" ["trampoline" "start-dev"]
- "codox" ["with-profile" "+test" "doc"]}
- :plugins [[lein-expectations "0.0.8"]
- [lein-autoexpect "1.2.1"]
- [lein-ancient "0.5.4"]
- [codox "0.6.7"]]
- :min-lein-version "2.0.0"
- :global-vars {*warn-on-reflection* true}
+ :url "http://www.eclipse.org/legal/epl-v10.html"
+ :distribution :repo
+ :comments "Same as Clojure"}
+ :min-lein-version "2.3.3"
+ :global-vars {*warn-on-reflection* true
+ *assert* true}
+ :dependencies
+ [[org.clojure/clojure "1.4.0"]
+ [org.clojure/tools.reader "0.8.3"]
+ [org.iq80.snappy/snappy "0.3"]
+ [org.tukaani/xz "1.4"]
+ [com.taoensso/encore "0.8.0"]]
+
+ :test-paths ["test" "src"]
+ :profiles
+ {:build {:hooks ^:replace []} ; Workaround to avoid :dev hooks during deploy
+ :1.5 {:dependencies [[org.clojure/clojure "1.5.1"]]}
+ :1.6 {:dependencies [[org.clojure/clojure "1.6.0-beta1"]]}
+ :test {:jvm-opts ["-Xms1024m" "-Xmx2048m"]
+ :dependencies [[expectations "1.4.56"]
+ [reiddraper/simple-check "0.5.6"]
+ [org.xerial.snappy/snappy-java "1.1.1-M1"]
+ [org.clojure/data.fressian "0.2.0"]]
+ :plugins [[lein-expectations "0.0.8"]
+ [lein-autoexpect "1.2.2"]]}
+ :dev
+ [:1.6 :test
+ {:jvm-opts ^:replace ["-server" "-Xms1024m" "-Xmx2048m"]
+ :hooks []
+ :dependencies []
+ :plugins []}]}
+
+ :plugins [[lein-ancient "0.5.4"]
+ [codox "0.6.7"]]
+
+ ;; :codox {:sources ["target/classes"]} ; For use with cljx
+ :aliases
+ {"test-all" ["with-profile" "+test:+1.5,+test:+1.6,+test" "expectations"]
+ "test-auto" ["with-profile" "+test" "autoexpect"]
+ "start-dev" ["with-profile" "+dev" "repl" ":headless"]
+ "codox" ["with-profile" "+test" "doc"]
+ "deploy-lib" ["with-profile" "+dev,+build" "do" "deploy" "clojars," "install"]}
+
:repositories
{"sonatype"
{:url "http://oss.sonatype.org/content/repositories/releases"
diff --git a/src/taoensso/nippy.clj b/src/taoensso/nippy.clj
index 0bcdceb..eb0059c 100644
--- a/src/taoensso/nippy.clj
+++ b/src/taoensso/nippy.clj
@@ -3,6 +3,7 @@
from Deep-Freeze."
{:author "Peter Taoussanis"}
(:require [clojure.tools.reader.edn :as edn]
+ [taoensso.encore :as encore]
[taoensso.nippy
(utils :as utils)
(compression :as compression :refer (snappy-compressor))
@@ -302,8 +303,8 @@
(defn- wrap-header [data-ba metadata]
(if-let [meta-id (head-meta-id (assoc metadata :version head-version))]
- (let [head-ba (utils/ba-concat head-sig (byte-array [meta-id]))]
- (utils/ba-concat head-ba data-ba))
+ (let [head-ba (encore/ba-concat head-sig (byte-array [meta-id]))]
+ (encore/ba-concat head-ba data-ba))
(throw (Exception. (str "Unrecognized header metadata: " metadata)))))
(comment (wrap-header (.getBytes "foo") {:compressed? true
@@ -356,10 +357,10 @@
`(long (BigInteger. (read-bytes ~in :small))))
(defmacro ^:private read-coll [in coll]
- `(let [in# ~in] (utils/repeatedly-into ~coll (.readInt in#) (thaw-from-in in#))))
+ `(let [in# ~in] (encore/repeatedly-into* ~coll (.readInt in#) (thaw-from-in in#))))
(defmacro ^:private read-kvs [in coll]
- `(let [in# ~in] (utils/repeatedly-into ~coll (/ (.readInt in#) 2)
+ `(let [in# ~in] (encore/repeatedly-into* ~coll (/ (.readInt in#) 2)
[(thaw-from-in in#) (thaw-from-in in#)])))
(declare ^:private custom-readers)
@@ -371,7 +372,7 @@
(when-debug-mode
(println (format "DEBUG - thawing type-id: %s" type-id)))
- (utils/case-eval type-id
+ (encore/case-eval type-id
id-reader
(let [edn (read-utf8 in)]
@@ -446,7 +447,7 @@
;;; DEPRECATED
id-old-reader (edn/read-string (.readUTF in))
id-old-string (.readUTF in)
- id-old-map (apply hash-map (utils/repeatedly-into []
+ id-old-map (apply hash-map (encore/repeatedly-into* []
(* 2 (.readInt in)) (thaw-from-in in)))
id-old-keyword (keyword (.readUTF in))
@@ -472,9 +473,9 @@
(thaw-from-in data-input))
(defn- try-parse-header [ba]
- (when-let [[head-ba data-ba] (utils/ba-split ba 4)]
- (let [[head-sig* [meta-id]] (utils/ba-split head-ba 3)]
- (when (utils/ba= head-sig* head-sig) ; Appears to be well-formed
+ (when-let [[head-ba data-ba] (encore/ba-split ba 4)]
+ (let [[head-sig* [meta-id]] (encore/ba-split head-ba 3)]
+ (when (encore/ba= head-sig* head-sig) ; Appears to be well-formed
[data-ba (head-meta meta-id {:unrecognized-meta? true})]))))
(defn thaw
@@ -699,16 +700,16 @@
;;;; Tools
-(utils/defalias freezeable? utils/freezable?)
+(encore/defalias freezeable? utils/freezable?)
(defn inspect-ba "Alpha - subject to change."
[ba & [thaw-opts]]
- (if-not (utils/bytes? ba) :not-ba
- (let [[first2bytes nextbytes] (utils/ba-split ba 2)
+ (if-not (encore/bytes? ba) :not-ba
+ (let [[first2bytes nextbytes] (encore/ba-split ba 2)
known-wrapper
(cond
- (utils/ba= first2bytes (.getBytes "\u0000<" "UTF8")) :carmine/bin
- (utils/ba= first2bytes (.getBytes "\u0000>" "UTF8")) :carmine/clj)
+ (encore/ba= first2bytes (.getBytes "\u0000<" "UTF8")) :carmine/bin
+ (encore/ba= first2bytes (.getBytes "\u0000>" "UTF8")) :carmine/clj)
unwrapped-ba (if known-wrapper nextbytes ba)
[data-ba nippy-header] (or (try-parse-header unwrapped-ba)
diff --git a/src/taoensso/nippy/benchmarks.clj b/src/taoensso/nippy/benchmarks.clj
index f21750f..03daf53 100644
--- a/src/taoensso/nippy/benchmarks.clj
+++ b/src/taoensso/nippy/benchmarks.clj
@@ -2,9 +2,9 @@
{:author "Peter Taoussanis"}
(:require [clojure.tools.reader.edn :as edn]
[clojure.data.fressian :as fressian]
+ [taoensso.encore :as encore]
[taoensso.nippy :as nippy :refer (freeze thaw)]
- [taoensso.nippy.compression :as compression]
- [taoensso.nippy.utils :as utils]))
+ [taoensso.nippy.compression :as compression]))
(def data nippy/stress-data-benchable)
@@ -21,7 +21,7 @@
(comment (fressian-thaw (fressian-freeze data)))
-(defmacro bench* [& body] `(utils/bench 10000 {:warmup-laps 20000} ~@body))
+(defmacro bench* [& body] `(encore/bench 10000 {:warmup-laps 20000} ~@body))
(defn bench1 [freezer thawer & [sizer]]
(let [data-frozen (freezer data)
time-freeze (bench* (freezer data))
diff --git a/src/taoensso/nippy/compression.clj b/src/taoensso/nippy/compression.clj
index 0a88531..3cc5f87 100644
--- a/src/taoensso/nippy/compression.clj
+++ b/src/taoensso/nippy/compression.clj
@@ -1,7 +1,6 @@
(ns taoensso.nippy.compression
"Alpha - subject to change."
{:author "Peter Taoussanis"}
- (:require [taoensso.nippy.utils :as utils])
(:import [java.io ByteArrayInputStream ByteArrayOutputStream DataInputStream
DataOutputStream]))
diff --git a/src/taoensso/nippy/encryption.clj b/src/taoensso/nippy/encryption.clj
index 0a056c4..5516783 100644
--- a/src/taoensso/nippy/encryption.clj
+++ b/src/taoensso/nippy/encryption.clj
@@ -3,7 +3,7 @@
Simple no-nonsense crypto with reasonable defaults. Because your Clojure data
deserves some privacy."
{:author "Peter Taoussanis"}
- (:require [taoensso.nippy.utils :as utils]))
+ (:require [taoensso.encore :as encore]))
;;;; Interface
@@ -32,7 +32,7 @@
(PBKDF2, bcrypt, scrypt, etc.). Decent security with multiple rounds."
[salt-ba ^String pwd]
(loop [^bytes ba (let [pwd-ba (.getBytes pwd "UTF-8")]
- (if salt-ba (utils/ba-concat salt-ba pwd-ba) pwd-ba))
+ (if salt-ba (encore/ba-concat salt-ba pwd-ba) pwd-ba))
n (* (int Short/MAX_VALUE) (if salt-ba 5 64))]
(if-not (zero? n)
(recur (.digest sha512-md ba) (dec n))
@@ -70,22 +70,22 @@
salt? (= type :salted)
iv-ba (rand-bytes aes128-block-size)
salt-ba (when salt? (rand-bytes salt-size))
- prefix-ba (if-not salt? iv-ba (utils/ba-concat iv-ba salt-ba))
- key (utils/memoized (when-not salt? (:key-cache this))
+ prefix-ba (if-not salt? iv-ba (encore/ba-concat iv-ba salt-ba))
+ key (encore/memoized (when-not salt? (:key-cache this))
sha512-key salt-ba pwd)
iv (javax.crypto.spec.IvParameterSpec. iv-ba)]
(.init aes128-cipher javax.crypto.Cipher/ENCRYPT_MODE
^javax.crypto.spec.SecretKeySpec key iv)
- (utils/ba-concat prefix-ba (.doFinal aes128-cipher data-ba))))
+ (encore/ba-concat prefix-ba (.doFinal aes128-cipher data-ba))))
(decrypt [this typed-pwd ba]
(let [[type pwd] (destructure-typed-pwd typed-pwd)
salt? (= type :salted)
prefix-size (+ aes128-block-size (if salt? salt-size 0))
- [prefix-ba data-ba] (utils/ba-split ba prefix-size)
+ [prefix-ba data-ba] (encore/ba-split ba prefix-size)
[iv-ba salt-ba] (if-not salt? [prefix-ba nil]
- (utils/ba-split prefix-ba aes128-block-size))
- key (utils/memoized (when-not salt? (:key-cache this))
+ (encore/ba-split prefix-ba aes128-block-size))
+ key (encore/memoized (when-not salt? (:key-cache this))
sha512-key salt-ba pwd)
iv (javax.crypto.spec.IvParameterSpec. iv-ba)]
(.init aes128-cipher javax.crypto.Cipher/DECRYPT_MODE
diff --git a/src/taoensso/nippy/tools.clj b/src/taoensso/nippy/tools.clj
index 58d1456..a6f7516 100644
--- a/src/taoensso/nippy/tools.clj
+++ b/src/taoensso/nippy/tools.clj
@@ -3,8 +3,7 @@
Utilities for third-party tools that want to add fully-user-configurable Nippy
support. Used by Carmine and Faraday."
{:author "Peter Taoussanis"}
- (:require [taoensso.nippy :as nippy]
- [taoensso.nippy.utils :as utils]))
+ (:require [taoensso.nippy :as nippy]))
(defrecord WrappedForFreezing [value opts])
(defn wrapped-for-freezing? [x] (instance? WrappedForFreezing x))
diff --git a/src/taoensso/nippy/utils.clj b/src/taoensso/nippy/utils.clj
index 84b152e..4ed2138 100644
--- a/src/taoensso/nippy/utils.clj
+++ b/src/taoensso/nippy/utils.clj
@@ -1,114 +1,10 @@
(ns taoensso.nippy.utils
{:author "Peter Taoussanis"}
- (:require [clojure.string :as str]
+ (:require [clojure.string :as str]
[clojure.tools.reader.edn :as edn])
(:import [java.io ByteArrayInputStream ByteArrayOutputStream Serializable
ObjectOutputStream ObjectInputStream]))
-(defmacro defalias
- "Defines an alias for a var, preserving metadata. Adapted from
- clojure.contrib/def.clj, Ref. http://goo.gl/xpjeH"
- [name target & [doc]]
- `(let [^clojure.lang.Var v# (var ~target)]
- (alter-meta! (def ~name (.getRawRoot v#))
- #(merge % (apply dissoc (meta v#) [:column :line :file :test :name])
- (when-let [doc# ~doc] {:doc doc#})))
- (var ~name)))
-
-(defmacro case-eval
- "Like `case` but evaluates test constants for their compile-time value."
- [e & clauses]
- (let [;; Don't evaluate default expression!
- default (when (odd? (count clauses)) (last clauses))
- clauses (if default (butlast clauses) clauses)]
- `(case ~e
- ~@(map-indexed (fn [i# form#] (if (even? i#) (eval form#) form#))
- clauses)
- ~(when default default))))
-
-(defmacro repeatedly-into
- "Like `repeatedly` but faster and `conj`s items into given collection."
- [coll n & body]
- `(let [coll# ~coll
- n# ~n]
- (if (instance? clojure.lang.IEditableCollection coll#)
- (loop [v# (transient coll#) idx# 0]
- (if (>= idx# n#)
- (persistent! v#)
- (recur (conj! v# ~@body)
- (inc idx#))))
- (loop [v# coll#
- idx# 0]
- (if (>= idx# n#)
- v#
- (recur (conj v# ~@body)
- (inc idx#)))))))
-
-(defmacro time-ns "Returns number of nanoseconds it takes to execute body."
- [& body] `(let [t0# (System/nanoTime)] ~@body (- (System/nanoTime) t0#)))
-
-(defmacro bench
- "Repeatedly executes body and returns time taken to complete execution."
- [nlaps {:keys [nlaps-warmup nthreads as-ns?]
- :or {nlaps-warmup 0
- nthreads 1}} & body]
- `(let [nlaps# ~nlaps
- nlaps-warmup# ~nlaps-warmup
- nthreads# ~nthreads]
- (try (dotimes [_# nlaps-warmup#] ~@body)
- (let [nanosecs#
- (if (= nthreads# 1)
- (time-ns (dotimes [_# nlaps#] ~@body))
- (let [nlaps-per-thread# (int (/ nlaps# nthreads#))]
- (time-ns
- (->> (fn [] (future (dotimes [_# nlaps-per-thread#] ~@body)))
- (repeatedly nthreads#)
- (doall)
- (map deref)
- (dorun)))))]
- (if ~as-ns? nanosecs# (Math/round (/ nanosecs# 1000000.0))))
- (catch Exception e# (format "DNF: %s" (.getMessage e#))))))
-
-(defn memoized
- "Like `(partial memoize* {})` but takes an explicit cache atom (possibly nil)
- and immediately applies memoized f to given arguments."
- [cache f & args]
- (if-not cache
- (apply f args)
- (if-let [dv (@cache args)]
- @dv
- (locking cache ; For thread racing
- (if-let [dv (@cache args)] ; Retry after lock acquisition!
- @dv
- (let [dv (delay (apply f args))]
- (swap! cache assoc args dv)
- @dv))))))
-
-(comment (memoized nil +)
- (memoized nil + 5 12))
-
-(def ^:const bytes-class (Class/forName "[B"))
-(defn bytes? [x] (instance? bytes-class x))
-(defn ba= [^bytes x ^bytes y] (java.util.Arrays/equals x y))
-
-(defn ba-concat ^bytes [^bytes ba1 ^bytes ba2]
- (let [s1 (alength ba1)
- s2 (alength ba2)
- out (byte-array (+ s1 s2))]
- (System/arraycopy ba1 0 out 0 s1)
- (System/arraycopy ba2 0 out s1 s2)
- out))
-
-(defn ba-split [^bytes ba ^Integer idx]
- (let [s (alength ba)]
- (when (> s idx)
- [(java.util.Arrays/copyOf ba idx)
- (java.util.Arrays/copyOfRange ba idx s)])))
-
-(comment (String. (ba-concat (.getBytes "foo") (.getBytes "bar")))
- (let [[x y] (ba-split (.getBytes "foobar") 5)]
- [(String. x) (String. y)]))
-
;;;; Fallback type tests
;; Unfortunately the only reliable way we can tell if something's
;; really serializable/readable is to actually try a full roundtrip.
@@ -224,4 +120,6 @@
(freezable? (.getBytes "foo"))
(freezable? (java.util.Date.) {:allow-clojure-reader? true})
(freezable? (Exception. "_") {:allow-clojure-reader? true})
- (freezable? (Exception. "_") {:allow-java-serializable? true}))
+ (freezable? (Exception. "_") {:allow-java-serializable? true})
+ (freezable? (atom {}) {:allow-clojure-reader? true
+ :allow-java-serializable? true}))
diff --git a/test/taoensso/nippy/tests/main.clj b/test/taoensso/nippy/tests/main.clj
index 01f823a..ae79828 100644
--- a/test/taoensso/nippy/tests/main.clj
+++ b/test/taoensso/nippy/tests/main.clj
@@ -7,6 +7,8 @@
[taoensso.nippy.compression :as compression]
[taoensso.nippy.benchmarks :as benchmarks]))
+(comment (test/run-tests '[taoensso.nippy.tests.main]))
+
(def test-data nippy/stress-data-comparable)
(defn- before-run {:expectations-options :before-run} [])
(defn- after-run {:expectations-options :after-run} [])