clojurewerkz / buffy

Buffy The ByteBuffer Slayer, Clojure library for working with binary data.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

UUID encoder

AeroNotix opened this issue · comments

Hi,

I've been working on adding a UUID type, but it doesn't seem to properly encode the value into a byte-array.

The code:

(deftype UUIDType7 []
  BuffyType
  (size [_] 16)

  (read [by buffer idx]
    (let [msb (.getLong buffer idx)
          lsb (.getLong buffer (+ idx 8))]
      (java.util.UUID. lsb msb)))

  (rewind-write [bt buffer value]
    (.writeLong buffer (.getMostSignificantBits value))
    (.writeLong buffer (.getLeastSignificantBits value)))

  (write [bt buffer idx value]
    (.setLong buffer idx       (.getMostSignificantBits value))
    (.setLong buffer (+ 8 idx) (.getLeastSignificantBits value))
    )

  Object
  (toString [_]
    "UUIDType"))

Turns out I was trying to write binary data with spit. Probably not a good idea.

(As an aside, providing the implementation of UUIDType is good, do you want it in a PR?)

@AeroNotix that already looks cool, if you submit a PR, your name will be preserved in history :)

Also, a (simple) test would be really nice, if you've got some time for it.

alright. I wrote this for some $DAY_JOB stuff but when I get a chance I'll send it across + test.

Thanks.

Yes, please do include some tests. Buffy is popular enough by now to get serious about how we maintain it.

Merged.

@AeroNotix thanks!
I think pull requests are good, since there will always be attribution to you. Not that everyone has to care about it. But still, you authored the code, so deserve that credit.

Thanks guys!