Skip to content

Instantly share code, notes, and snippets.

@pepijndevos
Created January 1, 2011 20:47
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save pepijndevos/761997 to your computer and use it in GitHub Desktop.
Save pepijndevos/761997 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
{:bytes tbytes, :string tstring, :list tlist, :compound tcompound}
t t))
(defcodec tlist (header tag
(memoize #(compile-frame [(name %) (repeated (get-tag %))]))
(comp symbol first)))
(defcodec tcompound (repeated
(header tag
(memoize #(compile-frame [(name %) tstring (get-tag %)]))
(comp symbol first))
:prefix :none
: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