Source

ocaml-bert / bert.ml

Diff from to

File bert.ml

       (* see http://www.erlang.org/doc/apps/erts/erl_ext_dist.html for details*)
     begin match (String.get local_bin 0) with
       | 'a' ->  (* SMALL_INTEGER_EXT *)
-	  Ok( Int(int_of_char (String.get local_bin 1)), Str.string_after local_bin 1)
+	  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 5);
+	  Ok( Int( make_int32 (String.sub local_bin 1 5)), Str.string_after local_bin 6);
       | '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); 
 	  None;
       | 'k' -> (* STRING_EXT *)
 	  let len = (int_of_char (String.get local_bin 1))*256 + (int_of_char (String.get local_bin 2)) in
-	    Ok( String( String.sub local_bin 3 (len+3) ), Str.string_after local_bin (len+3) );
+	    Ok( String( String.sub local_bin 3 len ), Str.string_after local_bin (len+3) );
       | 'l' -> (* LIST_EXT *)
 	  let len = make_int32 (String.sub local_bin 1 5) in
 	    decode_list len (Str.string_after local_bin 5) [];
       | 'n' -> (* SMALL_BIG_EXT *)
 	  let n = int_of_char (String.get local_bin 1) in
 	  let sign = int_of_char  (String.get local_bin 2) in
-	  let result = make_small_bigint (String.sub local_bin 3 (n+3)) n in
+	  let result = make_small_bigint (String.sub local_bin 3 n) n in
 	    if sign=0 then 
 	      Ok( Int(result), Str.string_after local_bin (n+3) )
 	    else if sign=1 then
       | 'o' -> (* LARGE_BIG_EXT *)
 	  let n = make_int32 local_bin in
 	  let sign = int_of_char  (String.get local_bin 5) in
-	  let result = make_small_bigint (String.sub local_bin 6 (n+6)) n in
+	  let result = make_small_bigint (String.sub local_bin 6 n) n in
 	    if sign=0 then 
 	      Ok( Int(result), Str.string_after local_bin (n+6) )
 	    else if sign=1 then
     end in
     begin match int_of_char (String.get bin 0) with
       | 131 -> (* magic number for BERT term; *)
-	  local_decode (String.sub bin 1 ((String.length bin)-1)); 
+	  local_decode (Str.string_after bin 1);
       | _ -> raise Unknown_type;
     end;;
 
 	  print_termlist ']' list; 
 	end;
       | String(str)->
+	  print_char '"';
 	  print_string str;
+	  print_char '"';
       | Binary(bin)-> begin
 	  print_binary bin ;
 	end;