-
-
Notifications
You must be signed in to change notification settings - Fork 195
5 Packers
Sente uses a pluggable "packer" to control the format used for all client<->server communications.
The following packers are available out-the-box:
| Format | Packer | Type | Comments |
|---|---|---|---|
| edn | Link | Text | Mature, default |
| Transit | Link | Text (JSON) | Mature |
| MessagePack | Link | Binary | New high-speed implementation |
| gzip | Link | Text+Binary | Wraps any other packer |
Custom packers can also be easily written by implementing the relevant protocol.
To use a packer you'll import it and provide it as an option to both your Sente server and client, e.g.:
;; Server (clj)
(def my-sente-server
(let [packer (taoensso.sente.packers.msgpack/get-packer)]
(sente/make-channel-socket-server! ... {:packer packer ...})))
;; Client (cljs)
(def my-sente-client
(let [packer (taoensso.sente.packers.msgpack/get-packer)]
(sente/make-channel-socket-client! ... {:packer packer ...})))To add gzip you'll wrap the underlying packer:
;; Server (clj)
(def my-sente-server
(let [mp-packer (taoensso.sente.packers.msgpack/get-packer)
gz-packer (taoensso.sente.packers.gzip/wrap-packer mp-packer {:binary? true})]
(sente/make-channel-socket-server! ... {:packer gz-packer ...})))
;; Client (cljs)
(def my-sente-client
(let [mp-packer (taoensso.sente.packers.msgpack/get-packer)
gz-packer (taoensso.sente.packers.gzip/wrap-packer mp-packer {:binary? true})]
(sente/make-channel-socket-client! ... {:packer gz-packer ...})))A few things to consider include:
- Packer speed and output size
- Extra dependencies
- Browser support and support for Clojure's data types
You can see the relevant packer docs for info re: (2) and (3).
Re: (1) very broadly:
- For speed: MessagePack ~ Transit >> edn
- For small size: MessagePack > Transit >> edn
Adding gzip will decrease speed in exchange for smaller size (often a good tradeoff).
There's some benchmarks in the unit tests which you can tweak and run in your own environment. With the defaults (smaller bars are better):
Sente's Reference example also allows you to easily switch between different packers for testing, etc.