d4fb123
Branches > refactor/use-spec-1 > d4fb123 > files / src / net / bowmap
Reorder writer varersrersasdf
Commit: d4fb123da6eb96ab9a2b27f437df34e623e0b560
Parent: cf28fd5
1 changed file:
src/net/bowmap/packet/write.clj view file
@@ -52,20 +52,6 @@ (raise "Error while encoding packet field" {:field field :value (get m field)} e)))) buf codec-fields)) -(declare writers)--;; I think this should have :required/:optional/:prefixed-optional,-;; and have it that non-optional fields are implicity :required and thus nil checked-(defn writer- "Returns a function of a Bytebuf and a value and encodes/writes 't' to the buf, as defined by 'writers'.- Throws if no such type exists."- [t]- (if (vector? t)- (let [[t & args] t]- (apply (writer t) args))- (or (writers t)- (raise (str "No such type! " (name t)) {:type t}))))- (defn write-boolean! [buf x] (if x (ByteBuf/.writeByte buf 1)@@ -80,6 +66,10 @@ (write-boolean! buf x) (write-context-optional! buf codec x)) +(defn write-enum! [buf codec m x]+ (codec buf (m x)))++ ;;; NBT (defn write-modified-utf8! [buf s]@@ -167,7 +157,7 @@ :compound write-nbt-compound!}) (def nbt-ids {:byte 1- :boolean 1+ :boolean 1 ; Booleans are just bytes 0/1 :short 2 :int 3 :long 4@@ -179,8 +169,19 @@ ;; End NBT lol -(defn write-enum! [buf codec m x]- (codec buf (m x)))+(declare writers)++;; I think this should have :required/:optional/:prefixed-optional,+;; and have it that non-optional fields are implicity :required and thus nil checked+(defn writer+ "Returns a function of a Bytebuf and a value and encodes/writes 't' to the buf, as defined by 'writers'.+ Throws if no such type exists."+ [t]+ (if (vector? t)+ (let [[t & args] t]+ (apply (writer t) args))+ (or (writers t)+ (raise (str "No such type! " (name t)) {:type t})))) (def writers "Map of type names to functions.