 (ns longshi.fressian.utils
   "Utility data and functions for byte arrays")
 
-(deftype StringWriter [code-pipe string-buffer]
+(deftype
+  ^{:doc
+    "Object for grouping string writing methods and data together
+
+    code-pipe ([int]) - Pre allocated buffer for holding character codes
+    string-buffer ([bytes]) - Pre allocated buffer holding the converted character codes"}
+  StringWriter [code-pipe string-buffer]
+
   Object
   (string-to-codes [_ s start-pos end-pos]
+    "Converts a string into an array of character codes
+
+    s (string) - String to convert to character codes
+    start-pos (int) - The starting position to start reading from the string
+    end-pos (int) - The position to stop reading from the string"
     (loop [i 0 str-pos start-pos]
       (when (< str-pos end-pos)
         (do

        i)))

  (chars-to-str [_ string-buffer chars-length]
    (loop [i 0]
      (when (< i chars-length)
        (do
          (.append string-buffer (.fromCharCode js/String (aget read-codes i)))
          (recur (inc i))))))

  (get-buffer [_] buffer)

  (read-utf8-chars [sr string-buffer offset length]
    (let [str-length (.bytes-to-codes sr offset length)]
      (.chars-to-str sr string-buffer str-length))))

(defn make-string-reader []
  (StringReader. (js/Uint8Array. 65536) (make-array 21846)))

(def ^{:doc "Marker for the endianess of bytestreams"}

          (recur (inc i) (inc str-pos))))))

 (write-str-bytes [_ str-length buf-length]
   "Writes out character codes to bytes

    str-length (int) - The length of the portion of the string we are reading
    buf-length (int) - The length of the buffer we are writing to"
   (loop [i 0 buf-pos 0]
     (let [code (aget code-pipe i)
           byte-size (cond (<= code 0x007f) 1 (> code 0x07ff) 3 :else 2)]
