packet.clj

Branches > client-handling-rewrite > 66ebfc3 > files / src / net / bowmap / packet.clj

(ns net.bowmap.packet
  (:require [clojure.alpha.spec :as s]))

; 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 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 ::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
(defn packet? [x]
  (some? (::id x)))