Anonymous avatar Anonymous committed 56ab6f1

documetation

Comments (0)

Files changed (2)

-* OCaml-bert
+.. -*- restructuredtext -*-
 
-version 0.0.2
+=====================
+README for OCaml-bert
+=====================
 
-see http://www.bert-rpc.org for BERT.
-see http://caml.inria.fr/ocaml/ for OCaml
+- version 0.0.2
+- see http://www.bert-rpc.org for BERT.
+- Licensed under dual-license: LGPL with linking exception, or EPL
 
-* Licensed under dual-license: LGPL with linking exception, or EPL
-
-* Version
-
-* Installation
+Installation
+============
  TBF
 
-* Prequieistes
+Prequiesites
+-------------
 
-erlang, ocaml, omake
+install erlang_, ocaml_, omake_
 
-* Instruction
+.. _erlang: http://www.erlang.org/
 
-$ omake
-$ escript termwriter.erl   .. translates termwriter.eterm -> termwriter.bert
-$ ./termreader termwriter.bert
+.. _ocaml: http://caml.inria.fr/ocaml/
+
+.. _omake: http://omake.hoge.com/
+
+Instructions
+------------
+
+  $ omake
+  $ escript termwriter.erl   .. translates termwriter.eterm -> termwriter.bert
+  $ ./termreader termwriter.bert
+
 and compare the result with termwriter.eterm!!
 
-* Roadmap (TODO)
-  stdin/stdout program demo
-  TCP server demo
+Roadmap (TODO)
+===============
 
-* Serialization/Deserialization support
+- stdin/stdout program demo
+- direct usage of network I/O module
+- TCP server demo
+  
+
+Serialization/Deserialization support
+======================================
 
 erlang terms - support in ocaml
-  integer  o- ok in ocaml
-  float    o- ok in ocaml
+  integer  o- integer in ocaml
+  float    o- float   in ocaml
   atom     o- just a string in ocaml
   list     o- list with polymorphic variant ... maybe supported.
   tuple    o- tuple. maybe supported. difficult problem of types.
   binary   o- just an string, maybe
   port     x- not supported
 
-
-* interface
-  ocaml       erlang
-  integer <-> integer
-  bignum  <-> integer
-  float   <-> flost
-  string  <-> atom
-  ..... 
-  ...
-
 see http://www.erlang.org/doc/apps/erts/erl_ext_dist.html
 for erlang binary term format.
 
-* Files
+Files
+========
  bert.ml        - the very BERT implementation
  tests_bert.ml  - basic test code
  termreader.ml  - simple test code
   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 *)
-	  Ok( Int(int_of_char (String.get local_bin 1)), Str.string_after local_bin 2)
+	  if String.length local_bin > 1 then
+	    Ok( Int(int_of_char (String.get local_bin 1)), Str.string_after local_bin 2)
+	  else
+	    More(2);
       | 'b' ->  (* INTEGER_EXT *)
-	  Ok( Int( make_int32 (String.sub local_bin 1 5)), Str.string_after local_bin 5);
+	  if String.length local_bin > 4 then
+	    Ok( Int( make_int32 (String.sub local_bin 1 5)), Str.string_after local_bin 5)
+	  else 
+	    More(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); 
+	  if String.length local_bin > 31 then	  
+	    let v = Scanf.sscanf (String.sub local_bin 1 32) "%f" (fun x->x) in
+	      Ok( Float( v ), Str.string_after local_bin 32); 
+	  else 
+	    More(32);
+
       | 'd' -> (* ATOM_EXT *)
 	  let len = (int_of_char (String.get local_bin 1))*256 + (int_of_char (String.get local_bin 2)) in
-	    Ok( Atom( String.sub local_bin 3 len ), Str.string_after local_bin (len+3) );
+	    if String.length local_bin > (len+2) then	  
+	      Ok( Atom( String.sub local_bin 3 len ), Str.string_after local_bin (len+3) )
+	    else
+	      More(len+3);
+
       | 'e' -> (* REFERENCE_EXT *)
 	  raise Not_supported;
       | 'f' -> (* PORT_EXT *)
 	  raise Not_supported;
       | 'g' -> (* PID_EXT *)
 	  raise Not_supported;
+
       | 'h' -> (* SMALL_TUPLE_EXT *)
 	  let len = int_of_char (String.get local_bin 1) in
 	    decode_tuple len (Str.string_after local_bin 2) []; (* is it OK to use list? *)
       | 'i' -> (* LARGE_TUPLE_EXT *)
 	  let len = make_int32 (String.sub local_bin 1 5) in
 	    decode_tuple len (Str.string_after local_bin 5) []; (* is it OK to use list? *)
+
       | 'j' -> (* NIL_EXT *)
 	  Ok( Nil, Str.string_after local_bin 1);
+
       | '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 ), Str.string_after local_bin (len+3) );
+	    if String.length local_bin > (len+2) then
+	      Ok( String( String.sub local_bin 3 len ), Str.string_after local_bin (len+3) )
+	    else
+	      More(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) [];
-	  (*raise Not_supported; *)
+
       | 'm' -> (* BINARY_EXT *)
 	  let len = make_int32 (String.sub local_bin 1 5) in
-	  let remain = Str.string_after local_bin 5 in (* TODO: you'd better use Str.split *)
-	    Ok( Binary( Str.string_before remain len ),  Str.string_after remain len );
+	    if String.length local_bin > (4+len) then
+	      let remain = Str.string_after local_bin 5 in (* TODO: you'd better use Str.split *)
+		Ok( Binary( Str.string_before remain len ),  Str.string_after remain len )
+	    else
+	      More(5+len);
+
       | '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) n in
-	    if sign=0 then 
-	      Ok( Int(result), Str.string_after local_bin (n+3) )
-	    else if sign=1 then
-	      Ok( Int(-result), Str.string_after local_bin (n+3) )
-	    else 
-	      raise Unknown_type;
+	    if String.length local_bin > (n+2) then
+	      let sign = int_of_char  (String.get local_bin 2) 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
+		  Ok( Int(-result), Str.string_after local_bin (n+3) )
+		else 
+		  raise Unknown_type
+	    else
+	      More(n+3);
+
       | '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) n in
-	    if sign=0 then 
-	      Ok( Int(result), Str.string_after local_bin (n+6) )
-	    else if sign=1 then
-	      Ok( Int(-result), Str.string_after local_bin (n+6) )
-	    else 
-	      raise Unknown_type;
+	    if String.length local_bin > (n+5) then
+	      let sign = int_of_char  (String.get local_bin 5) 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
+		  Ok( Int(-result), Str.string_after local_bin (n+6) )
+		else 
+		  raise Unknown_type
+	    else
+	      More(n+6);
+
       | 'p' -> (* NEW_REFERENCE_EXT *)
 	  raise Not_supported;
       | 'q' -> (* SMALL_ATOM_EXT *)
-	  let len = int_of_char (String.get local_bin 1) in   
-	    Ok( Atom( String.sub local_bin 2 len ), Str.string_after local_bin (len+2) );
+	  let len = int_of_char (String.get local_bin 1) in
+	    if String.length local_bin > (len+1) then
+	      Ok( Atom( String.sub local_bin 2 len ), Str.string_after local_bin (len+2) )
+	    else
+	      More( len+2 );
+
       | 'r' -> (* FUN_EXT *)
 	  raise Not_supported;	    
       | 's' -> (* NEW_FUN_EXT *)
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.