clojurewerkz / buffy

Buffy The ByteBuffer Slayer, Clojure library for working with binary data.
194 stars 13 forks source link

Document: partial deserialization (read and deserialise parts of a byte buffer) #19

Closed tendant closed 10 years ago

tendant commented 10 years ago

The partial deserialization is mentioned in README. Is there any document or reference for this feature? Thanks.

michaelklishin commented 10 years ago

@ifesdjeen can you please comment on this?

ifesdjeen commented 10 years ago

Maybe the wording is not precise enough: you can read out parts of payload without deserializing an entire one, like here:

(let [s    (spec :int-field (int32-type)
                 :string-field (string-type 10))
      buf  (compose-buffer s)]

  (set-field buf :int-field 101)
  ;; Here we deserialize just an int field, without reading out the rest
  (get-field buf :int-field)

  (set-field buf :string-field "stringie")
  ;; Here we deserialize just a string field, without reading out the rest
  (get-field buf :string-field)
  )