Commits

Anonymous committed 332aa26

.

  • Participants
  • Parent commits d2b6e1a

Comments (0)

Files changed (1)

File dumbstreaming_it.ml

 
     type stream 'el;
     value empty_stream : stream 'el;
+    value chunk_of : 'el -> stream 'el;
 
     type err_msg = exn;
 
 ;
 
 
-type ntotal = int
+type ntotal = int64
  and npart = int
  and nbytes = int
 ;
   sig
     (* None of EOF *)
 
-    value read : (ntotal -> npart -> nbytes -> I.iteratee char 'i)
-              -> I.iteratee 'i 'a
-              -> I.iteratee char (option 'a)
+    value read :
+      (~ntotal:ntotal -> ~npart:npart -> ~nbytes:nbytes -> I.iteratee char 'i)
+      -> I.iteratee 'i 'a
+      -> I.iteratee char (option 'a)
     ;
 
 
     ;
 
     value read_the_char c =
+      let err txt = ds_error "read_char: %C expected, %s found" c in
       I.peek >>= fun
-      [ Some '\x20' -> I.drop 1
-      | Some c' -> ds_error "read_char: %C expected, %C found" c c'
-      | None -> ds_error "read_char: %C expected, eof found" c
+      [ Some c' ->
+          if c == c'
+          then
+            I.drop 1
+          else
+            err & sprintf "%C" c'
+      | None ->
+          err "eof"
       ]
     ;
 
       and read_x0A = read_the_char '\x0A'
     ;
 
-    value read_data ~get_piece_it ~combine_it packet_length lengths =
-      .
 
+    value read_data_lens ~get_piece_it ~combine_it ~ntotal lens =
+      loop ~combine_it ~npart:0
+      where rec loop ~combine_it ~npart =
+        match lens with
+        [ [] -> I.joinI (I.return combine_it)
+        | [piece_len :: lens] ->
+            let this_piece_it = get_piece_it
+              ~ntotal ~npart ~nbytes:piece_len in
+            I.joinI (I.take piece_len this_piece_it) >>= fun piece_res ->
 
-      (ignore get_piece_it ; ignore combine_it
-       ; ignore lengths ; ignore packet_length ; failwith "kvava")
+            .. скормить piece_res, идти дальше.
+
+            combine_it ..
+
+
+        ]
+    ;
+
+
+    value read_data ~get_piece_it ~combine_it packet_length lens =
+      let sum_lens = List.fold_left Int64.add 0L
+        (List.map Int64.of_int lens) in
+      if packet_length <> sum_lens
+      then ds_error
+        "total length (%Li) is not equal to sum of pieces' lengths (%Li)"
+          packet_length sum_lens
+      else
+        read_data_lens ~get_piece_it ~combine_it lens
     ;