32cb01c

Bowmap · bowmap.git · Tickets

Branches > main > 32cb01c > files

Add identifier to protocol.types

Grahp, 2026-09-29

Commit: 32cb01c6d03f42d0aaba487f073c2fa9412bd23a
Parent: 0123d38

2 changed files:

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

@@ -1 +1,6 @@-(ns net.bowmap.server.protocol.schema)+(ns net.bowmap.server.protocol.schema+  (:require+   [clojure.spec.alpha :as s]+   [net.bowmap.server.protocol.types :refer [identifier?]]))++(s/def ::identifier identifier?)

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

@@ -1,3 +1,33 @@-(ns net.bowmap.server.protocol.types)+(ns net.bowmap.server.protocol.types+  (:require+   [clojure.string :as str]))  (def max-varint-size 5)++(defn identifier?+  "Returns whether 'x' is a valid protocol identifier.+   Identifiers are namespace qualified keywords with the syntax+   ':namespace/foo:bar:baz', where colons separate directories.+   While unqualified identifiers default to the 'minecraft' namespace in+   the protocol, these must be qualifeid as ':minecraft/name'."+  [x]+  (and (qualified-keyword? x)+       (re-matches #"[a-z0-9.\-_]+" (namespace x))+       (re-matches #"[a-z0-9.\-_:]+" (name x))))++(defn identifier-segments+  "Returns a map of [:namespace :name], the encoded segments of 'identifer'.+   Throws if 'identifier' is not a valid identifier."+  [identifier]+  (if (identifier? identifier)+    {:namespace (namespace identifier)+     :name (str/replace (name identifier) #":" "/")}+    (throw (ex-info "Cannot encode that value as an identifier."+                    {:value identifier}))))++(defn encode-identifier+  "Encodes 'identifer' as a protocol identifier string.+   Throws if 'identifier' is not valid identifier."+  [identifier]+  (let [{:keys! [namespace name]} (identifier-segments identifier)]+    (str namespace ":" name)))