c3bf28a
Branches > main > c3bf28a > files
Add then> writer
Commit: c3bf28ab405b40738954d07d4fa105c42e21e409
Parent: 9c9cb1f
1 changed file:
src/net/bowmap/server/protocol/writers.clj view file
@@ -72,6 +72,14 @@ (catch Exception e (throw (ex-info "Failed to call writer with applied function" {:f f :writer writer} e)))))) +(defn then>+ "Returns a writer that writes (f x) to the buffer, then (g x)."+ [f g]+ (fn [buf x]+ (-> buf+ (f x)+ (g x))))+ (def ubyte> byte>) (def short> (integer> 2)) (def ushort> short>)@@ -110,10 +118,8 @@ "Returns a writer that writes every value in a coll via 'writer', preceded the varint length of the list." [writer]- (let [array-writer (array> writer)]- (fn [buf xs]- (-> (varint> buf (count xs))- (array-writer xs)))))+ (then> (apply> count varint>)+ (array> writer))) (def bytes> (list> byte>)) @@ -161,7 +167,8 @@ (long> (UUID/.getLeastSignificantBits uuid)))) (defn context-optional>- "Returns a writer that only writes a value via 'writer' if the value is non-nil."+ "Returns a writer that only writes a value via 'writer' if the value is non-nil.+ Unlike optional>, is not prefixed with a boolean. Reading is dependent on context." [writer] (fn [buf x] (if (some? x)@@ -172,10 +179,7 @@ "Returns a writer that prefixes the value with a boolean indicating whether it is present, and only writes the value via 'writer' if the value is non-nil." [writer]- (let [writer (context-optional> writer)]- (fn [buf x]- (boolean> buf (some? x))- (writer buf x))))+ (context-optional> (then> boolean> writer))) (def game-profile> (table> [::p/uuid uuid> ::p/username (string> 16)