912f7fc

Branches > refactor/use-spec-1 > 912f7fc > files

Always coerce message schemas

Grahp, 2026-07-08

Commit: 912f7fcc68f1fa2e43ce5a0b5ddc03088f35065e
Parent: 8e66792

3 changed files:

src/net/bowmap/network/message/client.clj modified (view file)

@@ -6,10 +6,10 @@    [net.bowmap.network.packet :as pk]    [net.bowmap.network.packet.types :as t]    [net.bowmap.network.packet.write :as write-    :refer [bit-mask-> boolean-> byte-> chunk-data-> context-optional->+    :refer [bit-mask-> boolean-> byte-> chunk-data-> coerce context-optional->             double-> enum-> float-> identifier-> int-> json-> length-prefixed             light-data-> list-> long-> nbt-> optional-> or-> position->-            string-> table-> ubyte-> uuid-> varint->]]+            string-> ubyte-> uuid-> varint->]]    [net.bowmap.network.registry :as reg]    [net.bowmap.network.state :as state]    [net.bowmap.server.gamemode :as gamemode])@@ -34,7 +34,7 @@   "Builds a map of message ids to message writers."   [registry]   (reduce (fn [acc [packet-id table]]-            (assoc acc packet-id (table-> table)))+            (assoc acc packet-id (coerce table)))           {} registry))  (s/fdef build-packets

src/net/bowmap/network/message/server.clj modified (view file)

@@ -5,25 +5,19 @@    [dev.grahp.error :refer [adorn raise]]    [net.bowmap.network.message :as msg]    [net.bowmap.network.packet :as pk]-   [net.bowmap.network.packet.read :refer [->bit-mask ->byte ->double ->enum-                                           ->float ->identifier ->int ->list-                                           ->long ->optional ->position-                                           ->short ->string ->table ->ubyte-                                           ->uuid ->varint]]+   [net.bowmap.network.packet.read+    :refer [->bit-mask ->byte ->double ->enum ->float ->identifier ->int+            ->list ->long ->optional ->position ->short ->string ->ubyte+            ->uuid ->varint coerce]]    [net.bowmap.network.state :as state])   (:import    [io.netty.buffer ByteBuf])) -(defn tablify [schema]-  (if (vector? schema)-    (->table schema)-    schema))- ; TODO docstring, rename? (defn build-message-readers [registry]   (reduce (fn [acc [packet-id table]]             (assoc acc packet-id-                   (let [reader (tablify table)]+                   (let [reader (coerce table)]                      (fn [buf]                        (assoc (reader buf)                               ::msg/id packet-id)))))

src/net/bowmap/network/packet/read.clj modified (view file)

@@ -84,6 +84,13 @@                        "Error while reading message table field" {:table table :field field :codec codec}))               {} table)))) +(defn coerce+  "If reader is an actual reader, returns it. If reader is a vector, turnes it into a table reader."+  [reader]+  (if (vector? reader)+    (->table reader)+    reader))+ ; TODO what happens when a bad value is read in (defn ->bit-mask [reader mask]   (let [mask (t/mapize-vector-or-something mask)]