smee / binary

Clojure API for binary format I/O using java's stream apis
74 stars 10 forks source link

Trailing bytes with repeated :separator-using strings #3

Closed zsau closed 10 years ago

zsau commented 10 years ago

I'm not sure if this is intended behavior or not:

(let [str-seq (repeated (string "UTF-8" :separator 0))
      in (java.io.ByteArrayInputStream. (.getBytes "abc\u0000def\u0000ghi" "UTF-8"))]
  [(decode str-seq in) (.read in)])
; [["abc" "def"] -1]

Should the parser be consuming the trailing bytes ("ghi") in this case? If so, is there a way for my code to access those bytes?

smee commented 10 years ago

I think this is a special case for a more general problem: How should decode behave if the binary data is not parseable (too little data, wrong data)?

In the case of this ticket we could argue that separated values may not have a final trailing separator. I added this in the last commit b8ae7b2bda59de341153d18e976b8b54568a19bf. Does this work for you?

zsau commented 10 years ago

Yeah, that's perfect. Thanks!