4768247

Branches > refactor/use-spec-1 > 4768247 > files / src / net / bowmap

Add keepalive packet and docstrings

Grahp, 2026-03-04

Commit: 4768247080a296f0f357ad770ecd51246b9694d7
Parent: 78981c6

2 changed files:

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

@@ -1,22 +1,25 @@ (ns net.bowmap.packet   (:require [clojure.alpha.spec :as s])) -; The protocol id, i.e. 0x00, 0x80, etc.+; 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) (s/def ::numeric-id pos-int?) ; The name of the packet id keyword, i.e. ::server/handshaking+; ::ids are also not unique across connections states, as a few packets are repeated across+; states, such as disconnect and keepalive (s/def ::id qualified-keyword?) -; Represents a Minecraft protocol packet-; See net.bowmap.packets.client and net.bowmap.packets.server for those+; 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+; - 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.-; See 'net.bowmap.packet.client/packet-ids' and 'net.bowmap.packet.server/packet-ids' though-; Packet maps will also contain other fields as defined in 'packets' of the above namespaces+;  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 ::packet (s/schema [::id]))  ; This could actually check the id and fields to see if it's valid if there's any point in that

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

@@ -79,6 +79,7 @@      ::registry-data [:registry-id :identifier                       :entries [:list [:table [:id :identifier                                                :data [:optional :nbt]]]]]+     ::keep-alive [:id :long]      ::finish-config []}))  (defn numeric-id [state id]@@ -89,10 +90,13 @@  ;; Maybe this should just be a function of the packet :p (defn encode-packet-  "Encodes packet 'pk' into a ByteBuf of the packet bytes.+  "Encodes packet 'pk' into a (new) ByteBuf of the packet bytes.    Like decoding, encoding a packet also requires the connection state, as     packet ids are not unique across connection state, so there isn't a-    direct mapping of packet ids to numeric ids. This could be changed, of course."+    direct mapping of packet ids to numeric ids.+   There are several packets (disconnect, keep alive) that are logically the+    same across connection states, and so can be handled and sent without+    needing to switch on the connection state."   [pk state]   {:pre [(pk/packet? pk)]}   (let [id (assert! (numeric-id state (::pk/id pk)))