Commits

UENISHI Kota  committed e927205

String decoding

  • Participants
  • Parent commits 61118ed

Comments (0)

Files changed (1)

     else v
   in make_int32_ bin 0 0;;
 
+let make_int8 r1 r2 = 
+  (int_of_char r1) * 16 + (int_of_char r2);;
 
 (* binary -> (decoded tuple, remain), (more, Length), (error, Reason)
    throws exceptions: Not_supported | Unknown_type
    when more binaries  *)
 let decode_binary bin = 
-  let local_decode local_bin = 
+  let rec local_decode local_bin = 
     let length = String.length local_bin in 
       (* see http://www.erlang.org/doc/apps/erts/erl_ext_dist.html for details*)
       begin match (String.get local_bin 0) with
 	| 'j' -> (* NIL_EXT *)
 	    None;
 	| 'k' -> (* STRING_EXT *)
-	    raise Not_supported;
-(*	    Ok( String( String *)
+	    let len = make_int8 (String.get local_bin 1) (String.get local_bin 2) in
+	    Ok( String( String.sub local_bin 3 (len+3) ),
+		String.sub local_bin (len+3) (length-len-3) );
 	| 'l' -> (* LIST_EXT *)
+(*	    let len = make_int32 (String.sub local_bin 1 4) in *)
 	    raise Unknown_type;
 	| 'm' -> (* BINARY_EXT *)
 	    raise Unknown_type;