Skip to content

Commit cab9648

Browse files
committed
[mod] Remove legacy pack format stuff
1 parent 63b2044 commit cab9648

2 files changed

Lines changed: 8 additions & 75 deletions

File tree

src/taoensso/sente.cljc

Lines changed: 7 additions & 70 deletions
Original file line numberDiff line numberDiff line change
@@ -206,94 +206,31 @@
206206
;; * Client<->server payloads are arbitrary Clojure vals (cb replies or events).
207207
;; * Payloads are packed for client<->server transit.
208208

209-
(defn- parse-packed
210-
"Returns [<packed> <?format>]. Used to support some minimal backwards
211-
compatibility between v2 `pack` and v1 `unpack`."
212-
;; TODO Remove this in a future ~breaking release
213-
[packed]
214-
(if (string? packed)
215-
(cond
216-
(enc/str-starts-with? packed "+") [(subs packed 1) :v1/wrapped]
217-
(enc/str-starts-with? packed "-") [(subs packed 1) :v1/unwrapped]
218-
:else [ packed :v2/unwrapped])
219-
[packed :v2/unwrapped]))
220-
221-
(comment (parse-packed "+[[\"foo\"] \"uuid\"]"))
222-
223209
(defn- unpack "packed->[clj ?cb-uuid]"
224210
[packer packed]
225-
(let [[packed ?format] (parse-packed packed)
226-
unpacked ; [clj ?cb-uuid]
211+
(let [[clj ?cb-uuid]
227212
(try
228213
(interfaces/unpack packer packed)
229214
(catch #?(:clj Throwable :cljs :default) t
230215
(timbre/errorf t "Failed to unpack: %s" packed)
231216
[[:chsk/bad-package packed] nil]))
232217

233-
[clj ?cb-uuid]
234-
(case ?format
235-
:v1/wrapped unpacked
236-
:v1/unwrapped [unpacked nil]
237-
:v2/unwrapped unpacked)
238-
239218
?cb-uuid (if (= 0 ?cb-uuid) :ajax-cb ?cb-uuid)]
240219

241220
[clj ?cb-uuid]))
242221

243-
(def ^:dynamic *write-legacy-pack-format?*
244-
"Advanced option, most users can ignore this var. Only necessary
245-
for those that want to use Sente < v1.18 with a non-standard
246-
IPacker that deals with non-string payloads.
247-
248-
Details:
249-
Sente uses a private message format as an implementation detail
250-
for client<->server comms.
251-
252-
As part of [#398], this format is being updated to support
253-
non-string (e.g. binary) payloads.
254-
255-
Unfortunately updating the format is non-trivial because:
256-
1. Both the client & server need to support the same format.
257-
2. Clients are often served as cached cl/js.
258-
259-
To help ease migration, the new pack format is being rolled out
260-
in stages:
261-
262-
Sente <= v1.16: reads v1 format only
263-
writes v1 format only
264-
265-
Sente v1.17: reads v1 and v2 formats
266-
writes v1 and v2 formats (v1 default)
267-
268-
Sente v1.18: reads v1 and v2 formats
269-
writes v1 and v2 formats (v2 default) <- Currently here
270-
271-
Sente >= v1.19: reads v2 format only
272-
writes v2 format only
273-
274-
This var controls which format to use for writing.
275-
Override default with `alter-var-root` or `binding`."
276-
277-
false)
278-
279222
(defn- pack "[clj ?cb-uuid]->packed"
280223
([packer clj ] (pack packer clj nil))
281224
([packer clj ?cb-uuid]
282-
(let [?cb-uuid (if (= ?cb-uuid :ajax-cb) 0 ?cb-uuid)
283-
packed
284-
(interfaces/pack packer
285-
(if-some [cb-uuid ?cb-uuid]
286-
[clj cb-uuid]
287-
[clj ]))]
288-
289-
(if *write-legacy-pack-format?*
290-
(str "+" (have string? packed))
291-
(do packed)))))
225+
(let [?cb-uuid (if (= ?cb-uuid :ajax-cb) 0 ?cb-uuid)]
226+
(interfaces/pack packer
227+
(if-some [cb-uuid ?cb-uuid]
228+
[clj cb-uuid]
229+
[clj ])))))
292230

293231
(comment
294232
(unpack default-edn-packer
295-
(binding [*write-legacy-pack-format?* true]
296-
(pack default-edn-packer [:foo]))))
233+
(pack default-edn-packer [:foo])))
297234

298235
(deftype EdnPacker []
299236
interfaces/IPacker

src/taoensso/sente/interfaces.cljc

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,6 @@
5454

5555
(defprotocol IPacker
5656
"Extension pt. for client<->server comms data un/packers:
57-
arbitrary Clojure data <-> serialized payloads.
58-
59-
NB if dealing with non-string payloads, see also
60-
`taoensso.sente/*write-legacy-pack-format?*`."
61-
57+
arbitrary Clojure data <-> serialized payloads."
6258
(pack [_ x])
6359
(unpack [_ x]))

0 commit comments

Comments
 (0)