forked from FundingCircle/jackdaw
-
Notifications
You must be signed in to change notification settings - Fork 0
/
fn_impl.clj
37 lines (33 loc) · 1.25 KB
/
fn_impl.clj
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
(ns jackdaw.serdes.fn-impl
"FIXME"
{:license "BSD 3-Clause License <https://github.com/FundingCircle/jackdaw/blob/master/LICENSE>"}
(:import [org.apache.kafka.common.serialization
Deserializer Serdes Serializer]))
(set! *warn-on-reflection* true)
;; Kafka requires serdes to load from their own classloader, which
;; requires AOT. We don't want to transitively AOT other libs such as
;; tools.reader.edn, or nippy, etc, so provide a dumb box that we can
;; AOT and then inject using clojure fns.
(defrecord FnSerializer [close configure serialize]
Serializer
(close [{close :close :as this}]
(when close
(close this)))
(configure [{configure :configure :as this} configs key?]
(when configure
(configure this configs key?)))
(serialize [{serialize :serialize :as this} topic data]
(assert serialize)
(when data
(serialize this topic data))))
(defrecord FnDeserializer [close configure deserialize]
Deserializer
(close [{close :close :as this}]
(when close
(close this)))
(configure [{configure :configure :as this} configs key?]
(when configure
(configure this configs key?)))
(deserialize [{deserialize :deserialize :as this} topic data]
(when data
(deserialize this topic data))))