I am currently working on writing a library for use with LIFX light bulbs over their UDP API. I have written the code for creating the packet headers, but I'm unsure whether it is the most idiomatic approach, as I am new to Clojure. Please tell me what you think about the following code.
(ns lifx-lib.packet.header
(:require [clj-struct.core :as struct]))
(def protocol-num 1024)
(def header-size 36)
(defn- frame-header
[size tagged source]
(struct/pack
"<2HI"
size
(bit-or protocol-num 0x1000 (if tagged 0x3000 0x0000))
source))
(defn- address-header
[address resp ack sequence]
(struct/pack
"<2Q"
address
(bit-or
(if resp (bit-shift-left 1 48) 0)
(if ack (bit-shift-left 1 49) 0)
(bit-shift-left sequence 56))))
(defn- protocol-header
[type]
(struct/pack "<Q2H" 0 type 0))
(defn create-header
[params]
(let [
size (:size params 0)
tagged (:tagged params true)
source (:source params 0)
address (:address params 0)
resp (:resp params false)
ack (:ack params false)
type (:type params 0)
sequence (:sequence params 0)]
(into []
(concat
(frame-header size tagged source)
(address-header address resp ack sequence)
(protocol-header type)))))