packet.clj

Branches > main > 78981c6 > files / src / net / bowmap / packet.clj

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

; The protocol id, i.e. 0x00, 0x80, etc.
(s/def ::numeric-id pos-int?)
; The name of the packet id keyword, i.e. ::server/handshaking
(s/def ::id qualified-keyword?)

; Represents a 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
; 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
(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)))