Commit b0b0446d authored by Benoit Barbot's avatar Benoit Barbot
Browse files

fix serialization

parent d5987b9b
Pipeline #979 passed with stage
in 31 seconds
......@@ -33,8 +33,8 @@ let buff_int b i =
let j = ref ((abs i) mod (1 lsl (5*r))) in
let r2 = ref (r*5) in
while !r2 > 0 do
print_string ((string_of_int !r2)^":");
print_endline (string_of_int !j);
(*print_string ((string_of_int !r2)^":");
print_endline (string_of_int !j);*)
r2:= !r2-5;
add_char b (b64_of_ui ((if !r2>0 then 32 else 0) + (!j lsr !r2)));
j:= !j mod (1 lsl !r2);
......@@ -125,13 +125,12 @@ let buff_string b str =
pos := !pos+3
done
let string_buff b pin =
let p,n = int_buff b pin in
let pos = ref p in
let pos2 = ref 0 in
let str = Bytes.create ((n/4)*3) in
while !pos < n+(pin+3) do
while !pos < n+p do
let v1 = ui_of_b64 b.[!pos] in
let v2 = ui_of_b64 b.[!pos+1] in
Bytes.set str !pos2 @@ char_of_int (v1*4 + v2/16);
......@@ -152,12 +151,15 @@ let string_buff b pin =
!pos,Bytes.sub_string str 0 !pos2;;
(*
let t = Buffer.create 10 in
buff_int t (-5156);
(*let t = Buffer.create 1000 in
buff_int t (-5024);
buff_string t "Mandsflsdh sdlhkfsd sd h % ^& # ";
string_buff (Bytes.to_string @@ Buffer.to_bytes t) 3 ;;*)
let str = Bytes.to_string @@ Buffer.to_bytes t in
print_endline str;
let p,i = int_buff str 0 in
print_endline (string_of_int i);
print_endline (string_of_int p);
string_buff str p*)
let buff_list b f l =
List.iter (fun x -> Buffer.add_char b 'l'; f b x) l
......@@ -188,8 +190,8 @@ let buff_attribute b = function
let attribute_buff b pos = match b.[pos] with
'c' -> let p,s = string_buff b (pos+1) in
p,(`Color s)
| 'P' -> let f1 = float_buff b (pos+1)
and f2 = float_buff b (pos+4) in (pos+7),`ControlPoint (f1,f2)
| 'P' -> let p1,f1 = float_buff b (pos+1) in
let p2,f2 = float_buff b p1 in p2,`ControlPoint (f1,f2)
| 'S' -> let p,s = string_buff b (pos+1) in
p,(`String s)
| 'd' -> let p,s = list_buff b string_buff (pos+1) in
......
......@@ -228,14 +228,14 @@ module GraphEditor (G: GRAPH ) = struct
let pos = ref 3 in
let map = Hashtbl.create 10 in
let i =ref 0 in
while !pos+8 <= length && str.[!pos] = 'N' do
while !pos+4 <= length && str.[!pos] = 'N' do
let node_type = ui_of_b64 str.[!pos+1] in
let f1 = float_buff str (!pos+2) in
let f2 = float_buff str (!pos+5) in
let p1,f1 = float_buff str (!pos+2) in
let p2,f2 = float_buff str p1 in
let node = G.new_node graph node_type (f1,f2) in
Hashtbl.add map !i node;
incr i;
pos := !pos+8;
pos := p2;
let npos,attrl = list_buff str read_attribute !pos in
let _,cattr = G.get_node_attribute graph node in
let nattrl = G.get_new_node_attribute graph node in
......@@ -258,9 +258,11 @@ module GraphEditor (G: GRAPH ) = struct
pos := npos
done;
while !pos+7 <= length && str.[!pos] = 'A' do
let n1 = Hashtbl.find map (int_buff str (!pos+1)) in
let n2 = Hashtbl.find map (int_buff str (!pos+4)) in
pos := !pos+7;
let p1,nid1 = int_buff str (!pos+1) in
let p2,nid2 = int_buff str p1 in
let n1 = Hashtbl.find map nid1 in
let n2 = Hashtbl.find map nid2 in
pos := p2;
let npos,attrl = list_buff str read_attribute !pos in
pos := npos;
match G.new_arc graph n1 n2 with
......@@ -315,7 +317,7 @@ module GraphEditor (G: GRAPH ) = struct
download string_value "graph.gex" "data:application/xml") ]
[pcdata "Get GEX"];*)
button ~a:[a_onclick (fun _ -> layout_graph s; draw s (0.0,0.0))] [pcdata "Layout Graph"];
Raw.a ~a:[a_href "tikzeditor.html?q=GEXNAgKKgImlTgAMY29udGVudA==SgAEQQ==lTgAMQXR0cmlidXRlSgAIZHJhdw==NAgRMgImlTgAMY29udGVudA==SgAEQg==lTgAMQXR0cmlidXRlSgAIZHJhdw==AgAAgABlTgAMQXR0cmlidXRlSgAIZHJhdw==lTgAMQXR0cmlidXRlSgAELT4="] [pcdata "Direct Link"]
Raw.a ~a:[a_href "tikzeditor.html?q=GEXNAm6Yh+QlTMY29udGVudA==SEYQ==lTMQXR0cmlidXRlSIZHJhdw==NAr3Al7QlTMY29udGVudA==SEYg==lTMQXR0cmlidXRlSIZHJhdw==AABlTMQXR0cmlidXRlSIZHJhdw==lTMQXR0cmlidXRlSELT4="] [pcdata "Direct Link"]
]]
......@@ -325,7 +327,6 @@ module GraphEditor (G: GRAPH ) = struct
let saveload = Eliom_content.Html.To_dom.of_div saveload_elt in
let slider = Eliom_content.Html.To_dom.of_input slider_elt in
let ctx = canvas##(getContext (Dom_html._2d_)) in
let query = getURL "q" in
ctx##.lineCap := Js.string "round";
ctx##.font := Js.string "15px Arial";
let s = {zoom=1.5;
......@@ -336,10 +337,12 @@ module GraphEditor (G: GRAPH ) = struct
ctx;
attribute_list
} in
try (match query with Some str -> if String.sub str 0 3 = "GEX"
then s.graph<-parse_exchange_string str
| None -> ())
with _ -> ();
(try (match getURL "q" with
| Some str ->
if String.sub str 0 3 = "GEX"
then s.graph<-parse_exchange_string str
| None -> ())
with _ -> ());
slider##.value := Js.string @@ string_of_float @@ (s.zoom -. 0.2 ) *. 50. ;
slider##.oninput := Dom.handler (fun _ ->
s.zoom <- 0.2 +. (float_of_string @@ Js.to_string slider##.value) /. 50.0;
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment