This repository has been archived by the owner on Jan 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 206
/
state_entry_key_decoder.clj
64 lines (59 loc) · 1.88 KB
/
state_entry_key_decoder.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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
(ns onyx.state.serializers.state-entry-key-decoder
(:import [org.agrona.concurrent UnsafeBuffer]))
(defprotocol PDecoder
(get-idx [this])
(get-group-id [this])
(get-time [this])
(get-offset [this])
(wrap-impl [this bs])
(length [this]))
(deftype GroupedEntryDecoder [^UnsafeBuffer buffer offset]
PDecoder
(get-idx [this]
(.getShort buffer offset))
(get-group-id [this]
(let [bs (byte-array 8)]
(.getBytes buffer (unchecked-add-int offset 2) bs)
bs))
(get-time [this]
(.getLong buffer (unchecked-add-int offset 10) java.nio.ByteOrder/BIG_ENDIAN))
(get-offset [this]
(.getLong buffer (unchecked-add-int offset 18) java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs)))
(deftype UngroupedEntryDecoder [^UnsafeBuffer buffer offset]
PDecoder
(get-idx [this]
(.getShort buffer offset))
(get-group-id [this]
nil)
(get-time [this]
(.getLong buffer (unchecked-add-int offset 2) java.nio.ByteOrder/BIG_ENDIAN))
(get-offset [this]
(.getLong buffer (unchecked-add-int offset 10) java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs)))
(deftype GroupedGlobalEntryDecoder [^UnsafeBuffer buffer offset]
PDecoder
(get-idx [this]
(.getShort buffer offset))
(get-group-id [this]
(let [bs (byte-array 8)]
(.getBytes buffer (unchecked-add-int offset 2) bs)
bs))
(get-time [this] 0)
(get-offset [this]
(.getLong buffer (unchecked-add-int offset 10) java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs)))
(deftype UngroupedGlobalEntryDecoder [^UnsafeBuffer buffer offset]
PDecoder
(get-idx [this]
(.getShort buffer offset))
(get-group-id [this]
nil)
(get-time [this] 0)
(get-offset [this]
(.getLong buffer (unchecked-add-int offset 2) java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs)))