Anonymous avatar Anonymous committed 672d395

list and tuple decoding done; TODO: binary

Comments (0)

Files changed (2)

    throws exceptions: Not_supported | Unknown_type
    when more binaries  *)
 let decode_binary bin = 
+
+  (* decoding tuple, traverses the list twice: first when parsing 
+     (and pushes each term to stack list), second when reversing *)
   let rec decode_tuple len binary list = 
-    if len = 0 then
-      Ok(Tuple(list), binary)
-    else 
+    if len=0 then Ok(Tuple(List.rev list), binary)
+    else
       begin match local_decode binary with
-	| Ok(t, remain) ->  decode_tuple (len-1) remain (t::list);
+	| Ok(term, remain) -> 
+	    decode_tuple (len-1) remain (term::list);
 	| other -> other;
       end 
+
+  (* decoding list, traverses the list twice: first when parsing 
+     (and pushes each term to stack list), second when reversing *)
   and decode_list len binary list = 
-    if len = 0 then
-      begin match local_decode binary with
-	| Ok(Nil, remain) -> 
-	    Ok(List(list), remain);
-	| Ok(term, remain)->
-	    Ok(List( term::list ), remain );
-	| other -> other;
-      end
-    else 
-      begin match local_decode binary with
-	| Ok(t, remain) ->  decode_list (len-1) remain (t::list);
-	| other -> other;
-      end
+    begin match local_decode binary with
+      | Ok(Nil, remain) when len=0 -> 
+	  Ok(List(List.rev list), remain);
+      | Ok(term, remain) when len=0 ->
+	  Ok(List(List.rev (term::list)), remain );
+      | Ok(term, remain) -> 
+	  decode_list (len-1) remain (term::list);
+      | other -> other;
+    end
+
   and local_decode local_bin = 
       (* 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 *)
+	  Printf.printf "%d\n" (int_of_char (String.get 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( 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;
+manipulator.
+{term_writer_hogehoge, 1, 2}.
 234.
 1324567890.
 234.345.
 1.45e-5.
-manipulator.
-{tuple_test, 23, 354}.
 "hogehoge".
 "214354yurthgfdwy6][[\]'g".
 ["hogehoge", manipulator, 235].
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.