Skip to content

Instantly share code, notes, and snippets.

@ztellman
Forked from pepijndevos/nbt.clj
Created January 1, 2011 21:42
Show Gist options
  • Save ztellman/762031 to your computer and use it in GitHub Desktop.
Save ztellman/762031 to your computer and use it in GitHub Desktop.
(ns test
(:use [gloss core io]))
(defcodec tag (enum :byte :end :byte :int16 :int32 :int64 :float32 :float64 :bytes :string :list :compound))
(defcodec tstring (finite-frame :int16 (string :utf-8)))
(defcodec tbytes (repeated :byte))
(declare tcompound)
(declare tlist)
(defn get-tag [t]
(get
{:string tstring, :list tlist, :compound tcompound}
t t))
(defcodec tlist (header tag
(memoize (compile-frame (vector (name %) (repeated (get-tag %)))))
(comp symbol first)))
(defcodec tcompound (repeated
(header tag
(memoize (compile-frame (vector (name %) tstring (get-tag %))))
(comp symbol first))
:delimiters ["\0"]))
(defcodec nbt [tag tstring tcompound])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment