Source

ocaml-bert / bert.ml

Diff from to
 let decode_binary bin = 
   let rec decode_tuple len binary list = 
     if len = 0 then
-      Ok(List(list), binary)
+      Ok(Tuple(list), binary)
     else 
       begin match local_decode binary with
 	| Ok(t, remain) ->  decode_tuple (len-1) remain (t::list);
       | 'a' ->  (* SMALL_INTEGER_EXT *)
 	  Ok( Int(int_of_char (String.get local_bin 1)), Str.string_after local_bin 2)
       | 'b' ->  (* INTEGER_EXT *)
-	  Ok( Int( make_int32 (String.sub local_bin 1 5)), Str.string_after local_bin 6);
+	  Ok( Int( make_int32 (String.sub local_bin 1 5)), Str.string_after local_bin 5);
       | 'c' -> (* FLOAT_EXT *)
 	  let v = Scanf.sscanf (String.sub local_bin 1 32) "%f" (fun x->x) in
 	    Ok( Float( v ), Str.string_after local_bin 32); 
       | 'd' -> (* ATOM_EXT *)
 	  let len = (int_of_char (String.get local_bin 1))*256 + (int_of_char (String.get local_bin 2)) in
+	    print_char (String.get local_bin 0);
+	    print_endline (Str.string_after local_bin 2);
+	    print_int len;
 	    Ok( Atom( String.sub local_bin 3 len ), Str.string_after local_bin (len+3) );
       | 'e' -> (* REFERENCE_EXT *)
 	  raise Not_supported;
       print_endline ""
   in
     print_ 0;;
-