This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2022-02-06
Channels
- # beginners (49)
- # calva (12)
- # cider (5)
- # cljdoc (4)
- # clojure (51)
- # clojure-dev (1)
- # clojure-europe (16)
- # clojurescript (56)
- # conjure (2)
- # copenhagen-clojurians (1)
- # core-async (4)
- # data-science (4)
- # docker (1)
- # emacs (4)
- # gratitude (1)
- # malli (2)
- # meander (2)
- # missionary (7)
- # off-topic (23)
- # pedestal (3)
- # polylith (6)
- # shadow-cljs (28)
- # spacemacs (1)
- # sql (9)
- # transit (8)
What is serialization without i/o?
The io parts are interfaces with many implementations so what are you planning to do?
Kafka will do the I/O. Kafka gives you hooks for how you want to transform (serialize/deserialize) before/after it does I/O. So, here is example of how I create a CBOR serdes for Kafka, note that I use encode and decode functions, that is what I am thinking I want/need from Transit...
(ns cktc.cbor
(:require
[clj-cbor.core :as cbor]
[jackdaw.serdes.fn :as jsfn]
)
(:import org.apache.kafka.common.serialization.Serde
org.apache.kafka.common.serialization.Serdes)
(:gen-class
:implements [org.apache.kafka.common.serialization.Serde]
:prefix "EdnCborSerde-"
:name cktc.cbor.EdnCborSerde))
(set! *warn-on-reflection* true)
(defn cbor-serializer []
(jsfn/new-serializer
{:serialize (fn [_ _ data]
(cbor/encode data))}))
(defn cbor-deserializer
[]
(jsfn/new-deserializer
{:deserialize
(fn [_ _ data]
(clojure.walk/keywordize-keys (cbor/decode data)))}))
(defn cbor-serde
"Implements an EDN SerDes (Serializer/Deserializer)
using cbor.
(RFC 8949 Concise Binary Object Representation)
"
[]
(Serdes/serdeFrom (cbor-serializer) (cbor-deserializer)))
(def EdnCborSerde-configure
(constantly nil))
(defn EdnCborSerde-serializer
[& _]
(cbor-serializer))
(defn EdnCborSerde-deserializer
[& _ ]
(cbor-deserializer))
;; gen-class with AOT for the cbor_serdes.clj:
;; clj -e "(compile 'slc.cbor-serdes)"
;; make sure classes (default *compile-path*) is mkdir-ed and on classpath (e.g. deps.edn :paths ["src" "resources" "classes"]
;; restart repl with (:require ... [slc.cbor-serdes]) and (:import (slc.cbor_serdes EdnCborSerde)) (if compilation went well the import should work)
Done they just have to return byte arrays? How complicated is it to serialize to byte array or read from a byte array in transit?
The arities of the clj-cbor
encode
and decode
fns are interesting/instructive....
https://github.com/greglook/clj-cbor#clj-cbor
I suspect there is a way to do it because the two are separated conceptually in transits very design but you will probably need to rely on private interfaces