packss
pack/unpack shared-structure
What is this
This is to support to serialize/deserialize module.
Install
Usage
(require '[packss.core :as packss])
(require '[clojure.edn :as edn])
(def ss (let [a (atom 1)]
(list a a)))
ss => (#<Atom@1bc865a: 1> #<Atom@1bc865a: 1>)
(reset! (first ss) 2)
ss => (#<Atom@1bc865a: 2> #<Atom@1bc865a: 2>)
(def serialized (pr-str (packss/pack ss)))
(def deserialized (packss/unpack (edn/read-string serialized)))
deserialized => (#<Atom@11a6cc4: 2> #<Atom@11a6cc4: 2>)
(reset! (first deserialized) 3)
deserialized => (#<Atom@11a6cc4: 3> #<Atom@11a6cc4: 3>)
Can to do
-
Can treat shared-structure (including cyclic-structure without lazy-seq)
- See srfi-38 for what is shared-structure.
-
Can
packto Clojure's map, set, list, vector, seq, coll, defrecord, atom, ref, and Java's array -
Can
packany your objects if you setmapper,unmapper, andreplacer -
Can filter/scan all objects in structure
Cannot to do
-
Cannot genuine serialization
-
Cannot
packinfinity (or cyclic) lazy-seq- Because, below expr is false.
(let [r (repeat :a)] (identical? r (rest r)))
- Because, below expr is false.
Glossary
-
pack/unpack-
packconvert from a structure to serializable vector. -
unpackis vice versa.
-
-
mapping(mapper) /unmapping(unmapper) /replacing!(replacer)-
mappingconvert from one object in structure to serializable data. -
unmappingis vice versa. -
replacing!support tounmapping. It changes object's values with side-effect at afterunmapping. It should need to reconstruct shared structure.
-
-
idx(index)-
packgenerate a vector. All entities are numbered.
-
-
ext(user-ext)-
pack/unpack's optional arg, additional defines forpack/unpack.
-
-
scanner-
pack's optional arg, check/substitute individual object.
-
FAQ
-
I want to
packinstances of unsupported classes.- Use
make-packss-table. Seetest/packss/core_test.clj. - If you want to
packclass include clojure object recursively, you shall useobj->idxandidx->obj. Seebuilt-in-packss-tableinsrc/packss/core.clj.
- Use
-
packdon't check unserializable object! It's useless!- You may use
scanner. It can check/substitute unsafe object. Seetest/packss/core_test.cljandsrc/packss/core.clj. Unsafe objects are remained and never checked by default !!!
- You may use
ChangeLog
-
1.1.0 (2014-04-08)
- Implement to store
mtyperecursively
- Implement to store
-
1.0.1 (2014-04-05)
- Fix
unpackarray of boolean, byte, short, char - Sync protocol-version from project-version
- Improve for cache effiency
- Fix
-
1.0.0 (2014-03-25)
- Fix
packable?incorrectness - Rename
packable-classestobase-packable-classes
- Fix
-
0.3.0 (2014-03-24)
- Fix over-sharing bug
- See
shared-structure-determine-testintest/packss/core_test.clj, this test didn't pass in past.
- See
- Fix over-sharing bug
-
0.2.0 (2014-03-12)
- Discriminate
listandvectorfromseqstrictly
- Discriminate
-
0.1.0 (2014-03-08)
- Initial release
License
Copyright c 2014 ayamada
Distributed under the Eclipse Public License version 1.0
