Nice, overtone <http://github.com/rosejn/overtone> also looks really
interesting :)

On Thu, Feb 18, 2010 at 11:59 AM, Jeff Rose <ros...@gmail.com> wrote:

> Just a quick announcement for a small library recently extracted from
> Project Overtone.  It lets you specify binary formats and then
> serialize to and from clojure data structures.  This was created to
> read and write SuperCollider synthesizer definition files, but it
> could be used for other binary file formats also.
>
> You can check it out on github here:
>
> http://github.com/rosejn/byte-spec
>
> or you can use it in your project.clj and let lein pull it from
> clojars using this identifier:
>
> [byte-spec "0.1"]
>
> Here is a snip from the tests to give you a sense for how it works:
>
> (defspec rhythm-spec
>         :name :string
>         :length :int16
>         :n-triggers :int32
>         :triggers [:int8])
>
> (defspec melody-spec
>         :name :string
>         :n-notes :int32
>         :notes  [:int16])
>
> (defspec song-spec
>         :name   :string
>         :bpm    :int8
>         :rhythm rhythm-spec
>         :melody melody-spec)
>
> (defn bytes-and-back [spec obj]
>  (spec-read-bytes spec (spec-write-bytes spec obj)))
>
> (deftest nested-spec-test []
>  (let [r (spec rhythm-spec "test rhythm" 100 (short 5) [1 2 3 4 5])
>        m (spec melody-spec "test melody" (int 12) [2 3 4 54 23 43 98
> 23 98 54 87 23])
>        s (spec song-spec "test song" 234 r m)
>        s2 (bytes-and-back song-spec s)
>        m2 (:melody s2)
>        r2 (:rhythm s2)]
>    (is (= 5 (:n-triggers r2)))
>    (is (= 12 (:n-notes m2)))
>    (is (= r2))
>    (is (= m2))
>    (is (= s s))))
>
> Let me know if you have any questions.
>
> Cheers,
> Jeff Rose
>
> --
> You received this message because you are subscribed to the Google
> Groups "Clojure" group.
> To post to this group, send email to clojure@googlegroups.com
> Note that posts from new members are moderated - please be patient with
> your first post.
> To unsubscribe from this group, send email to
> clojure+unsubscr...@googlegroups.com<clojure%2bunsubscr...@googlegroups.com>
> For more options, visit this group at
> http://groups.google.com/group/clojure?hl=en

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to clojure@googlegroups.com
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
clojure+unsubscr...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en

Reply via email to