8172c84

Branches > namespace-reorganization > 8172c84 > files / src / net / bowmap / network

Add spec docstrings!

Grahp, 2026-05-31

Commit: 8172c847d97a36d35e5b38f8e92c976d9004eb5b
Parent: c1ef72f

3 changed files:

src/dev/grahp/spec.clj modified (view file)

@@ -1,4 +1,5 @@ (ns dev.grahp.spec+  (:refer-clojure :exclude [def])   (:require    [clojure.alpha.spec :as s]    [dev.grahp.error :refer [raise]]))@@ -7,3 +8,9 @@   (if (s/valid? spec x)     (s/conform spec x)     (raise "Failed to conform value to spec!" {:spec spec :x x})))++(defmacro def+  "Same as clojure.alpha.spec/def but allows for a docstring seriously how does spec def not have a docstring???"+  {:clj-kondo/lint-as 'clojure.spec.alpha/def}+  ([name spec] `(s/def ~name ~spec))+  ([name _docstring spec] `(s/def ~name ~spec)))

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

@@ -1,23 +1,13 @@ (ns net.bowmap.network.message   (:require-   [clojure.alpha.spec :as s]))+   [clojure.alpha.spec :as s]+   [dev.grahp.spec :as ss])) -; TODO update comments they are old+(ss/def ::id+  "The id of a message. See the serverbound and clientbound packet definitions for the names."+  qualified-keyword?) -(s/def ::id qualified-keyword?)-; Represents a deserialized Minecraft protocol packet-; See net.bowmap.packets.client and net.bowmap.packets.server for those.-; In serialized form, uncompressed packets have the following structure:-; - A length varint (see net.bowmap.packet.types)-; - A numeric id varint (::numeric-id)-; - The rest of the packet data, which depends on the ID (and connection state)-; Each protocol connection state (see net.bowmap.client.state) has its own set-;  of numeric ids for clientbound and serverbound packets, so there isn't a-;  direct function of numeric ids to '::id's, or vice versa.-; See 'net.bowmap.packet.client/packet-ids' and 'net.bowmap.packet.server/packet-ids'.-; Packet maps will also contain other fields as defined in the 'packets' var of the above namespaces-(s/def ::message (s/schema [::id]))--; This could actually check the id and fields to see if it's valid if there's any point in that-(defn message? [x]-  (boolean (find x ::id)))+(ss/def ::message+  "Represents a logical message map (object) from client to/from server.+   'Packet' is used to refer to a serialized message"+  (s/schema [::id]))

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

@@ -1,7 +1,11 @@ (ns net.bowmap.network.packet-  (:require [clojure.alpha.spec :as s]))+  (:require+   [dev.grahp.spec :as ss])) -; The protocol id of a packet, i.e. 0x00, 0x80, etc.-; Numeric ids are not unique across connection states (see ::net.bowmap.client.state/state)-; TODO rename to ::id-(s/def ::id pos-int?)+; The serialized form of a message, called a packet by everyone else :p+; See https://minecraft.wiki/w/Java_Edition_protocol/Packets++(ss/def ::id+  "Protocol id of a packet, i.e. 0x00, 0x80, etc.+   Numeric ids are NOT unique across connection states! See the wiki"+  pos-int?)