6f2bf2a

Branches > client-handling-rewrite > 6f2bf2a > files / src / net / bowmap / network

Move packet framer to packet namespace

Grahp, 2026-07-08

Commit: 6f2bf2a100d9e57cb54be00bb1856913c781fb8b
Parent: 912f7fc

3 changed files:

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

@@ -1,11 +1,31 @@ (ns net.bowmap.network.packet   (:require-   [dev.grahp.spec :as S]) +   [dev.grahp.spec :as S]+   [net.bowmap.network.packet.read :as read])    (:import-   [io.netty.buffer ByteBuf]))+   [io.netty.buffer ByteBuf Unpooled]))  ; The serialized form of a message, called a packet by everyone else :p ; See https://minecraft.wiki/w/Java_Edition_protocol/Packets  ; TODO rename to a frame, packet is still an overloaded term (S/def ::packet #(instance? ByteBuf %))++(defn packet-framer-xf+  "Transducer that frames bytes from incoming byte arrays and outputs ByteBufs of+   framed serialized serverbound packets."+  [rf]+  (let [buf (Unpooled/buffer)]+    (fn+      ([] (rf))+      ([res] (rf res))+      ([res input]+       (ByteBuf/.writeBytes buf input)+       (loop [res res]+         (if (read/can-read-packet? buf)+           (let [len (read/->varint buf)+                 res' (rf res (ByteBuf/.copy (ByteBuf/.readRetainedSlice buf len)))]+             (ByteBuf/.discardReadBytes buf)+             (recur res'))+           res))))))+

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

@@ -1,24 +0,0 @@-(ns net.bowmap.network.packet.frame-  (:require-   [net.bowmap.network.packet.read :as read])-  (:import-   [io.netty.buffer ByteBuf Unpooled]))--(defn packet-framer-xf-  "Transducer that frames bytes from incoming byte arrays and outputs ByteBufs of-   framed serialized serverbound packets."-  [rf]-  (let [buf (Unpooled/buffer)]-    (fn-      ([] (rf))-      ([res] (rf res))-      ([res input]-       (ByteBuf/.writeBytes buf input)-       (loop [res res]-         (if (read/can-read-packet? buf)-           (let [len (read/->varint buf)-                 res' (rf res (ByteBuf/.copy (ByteBuf/.readRetainedSlice buf len)))]-             (ByteBuf/.discardReadBytes buf)-             (recur res'))-           res))))))-

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

@@ -3,13 +3,13 @@    [aleph.tcp :as tcp]    [clojure.core.async :refer [chan put!]]    [manifold.stream :as s]-   [net.bowmap.network.packet.frame :as frame])+   [net.bowmap.network.packet :as pk])   (:import    [io.netty.bootstrap ServerBootstrap]    [io.netty.channel ChannelOption]))  (defn- handle-client [client-chan stream info]-  (let [packets-in (chan 1 frame/packet-framer-xf)+  (let [packets-in (chan 1 pk/packet-framer-xf)         packets-out (chan)]     (s/connect stream packets-in)     (s/connect packets-out stream)