32821d4
Branches > main > 32821d4 > files
Make all codecs always functions, rather than sometimes tables
Commit: 32821d4cff690eef96a23cf8f4a111369ab6fa10
Parent: 9a893c4
3 changed files:
src/net/bowmap/server/protocol/clientbound_packets.clj view file
@@ -181,4 +181,6 @@ ::show-dialog-play nil]}) (def phase->id->numeric-id (update-vals clientbound-packets #(zipmap (take-nth 2 %) (range))))-(def phase->id->schema (update-vals clientbound-packets #(some-vals (apply hash-map %))))+(def phase->id->writer (update-vals clientbound-packets #(-> (apply hash-map %)+ some-vals+ (update-vals to-writer))))src/net/bowmap/server/protocol/codec.clj view file
@@ -17,13 +17,10 @@ Throws when the packet cannot be encoded." [{::phase/keys! [phase]} {::packet/keys! [id] :as packet}] (let [numeric-id (req! (clientbound/phase->id->numeric-id phase) id)- schema (req! (clientbound/phase->id->schema phase) id)- payload-writer (if (and numeric-id schema)- (writers/to-writer schema)- (throw (ex-info "No such packet with that id!" {:phase phase :numeric-id numeric-id})))]+ writer (req! (clientbound/phase->id->writer phase) id)] (-> (frame) (writers/varint> numeric-id)- (payload-writer packet))))+ (writer packet)))) (defn decode-frame "Decodes a packet from a frame.@@ -31,7 +28,6 @@ [{:keys! [::phase/phase]} frame] (let [numeric-id (readers/varint< frame) id (req! (serverbound/phase->numeric-id->id phase) numeric-id)- schema (req! (serverbound/phase->id->schemas phase) id)- payload-reader (readers/to-reader schema)]- (assoc (payload-reader frame)+ reader (req! (serverbound/phase->id->reader phase) id)]+ (assoc (reader frame) ::packet/id id)))src/net/bowmap/server/protocol/serverbound_packets.clj view file
@@ -103,4 +103,5 @@ ::custom-click-action []]}) (def phase->numeric-id->id (update-vals serverbound-packets #(zipmap (range) (take-nth 2 %))))-(def phase->id->schemas (update-vals serverbound-packets #(apply hash-map %)))+(def phase->id->reader (update-vals serverbound-packets #(-> (apply hash-map %)+ (update-vals to-reader))))