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_encoder.clj
75 lines (70 loc) · 2.5 KB
/
state_entry_key_encoder.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
65
66
67
68
69
70
71
72
73
74
75
(ns onyx.state.serializers.state-entry-key-encoder
(:import [org.agrona.concurrent UnsafeBuffer]))
(defprotocol PEncoder
(set-state-idx [this idx])
(set-group [this group])
(set-time [this time])
(set-offset [this offset-value])
(get-bytes [this])
(wrap-impl [this bs])
(length [this]))
(deftype GroupedEntryEncoder [^UnsafeBuffer buffer offset]
PEncoder
(set-state-idx [this idx]
(.putShort buffer offset idx))
(set-group [this group-id]
(.putBytes buffer (unchecked-add-int offset 2) group-id))
(set-time [this t]
(.putLong buffer (unchecked-add-int offset 10) (long t) java.nio.ByteOrder/BIG_ENDIAN))
(set-offset [this offset-value]
(.putLong buffer (unchecked-add-int offset 18) offset-value java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs))
(get-bytes [this]
(let [ret-bs (byte-array 26)]
(.getBytes buffer offset ^bytes ret-bs)
ret-bs)))
(deftype UngroupedEntryEncoder [^UnsafeBuffer buffer offset]
PEncoder
(set-state-idx [this idx]
(.putShort buffer offset idx))
(set-group [this group-id])
(set-time [this t]
(.putLong buffer (unchecked-add-int offset 2) ^long t java.nio.ByteOrder/BIG_ENDIAN))
(set-offset [this offset-value]
(.putLong buffer (unchecked-add-int offset 10) offset-value java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs))
(get-bytes [this]
(let [ret-bs (byte-array 18)]
(.getBytes buffer offset ^bytes ret-bs)
ret-bs)))
(deftype UngroupedGlobalEntryEncoder [^UnsafeBuffer buffer offset]
PEncoder
(set-state-idx [this idx]
(.putShort buffer offset idx))
(set-group [this group-id])
(set-time [this t])
(set-offset [this offset-value]
(.putLong buffer (unchecked-add-int offset 2) offset-value java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs))
(get-bytes [this]
(let [ret-bs (byte-array 10)]
(.getBytes buffer offset ^bytes ret-bs)
ret-bs)))
(deftype GroupedGlobalEntryEncoder [^UnsafeBuffer buffer offset]
PEncoder
(set-state-idx [this idx]
(.putShort buffer offset idx))
(set-group [this group-id]
(.putBytes buffer (unchecked-add-int offset 2) group-id))
(set-time [this t])
(set-offset [this offset-value]
(.putLong buffer (unchecked-add-int offset 10) offset-value java.nio.ByteOrder/BIG_ENDIAN))
(wrap-impl [this bs]
(.wrap buffer ^bytes bs))
(get-bytes [this]
(let [ret-bs (byte-array 18)]
(.getBytes buffer offset ^bytes ret-bs)
ret-bs)))