57 |
} |
} |
58 |
; |
; |
59 |
} |
} |
60 |
|
|
61 |
*) |
*) |
62 |
type value = |
type value = |
63 |
String of string |
String of string |
91 |
let end_pos = iter_i s (pos+1) len in |
let end_pos = iter_i s (pos+1) len in |
92 |
(Int (Int64.of_string (String.sub s (pos+1) (end_pos-pos-1)))), |
(Int (Int64.of_string (String.sub s (pos+1) (end_pos-pos-1)))), |
93 |
(end_pos+1) |
(end_pos+1) |
94 |
| 'l' -> |
| 'l' -> |
95 |
let rec iter s pos len list = |
let rec iter s pos len list = |
96 |
if pos = len then assert false; |
if pos = len then assert false; |
97 |
match s.[pos] with |
match s.[pos] with |
98 |
| 'e' -> List (List.rev list), (pos+1) |
| 'e' -> List (List.rev list), (pos+1) |
99 |
| _ -> |
| _ -> |
100 |
let v, pos = decode s pos len in |
let v, pos = decode s pos len in |
101 |
iter s pos len (v :: list) |
iter s pos len (v :: list) |
102 |
in |
in |
103 |
iter s (pos+1) len [] |
iter s (pos+1) len [] |
104 |
| 'd' -> |
| 'd' -> |
105 |
|
|
106 |
let rec iter s pos len list = |
let rec iter s pos len list = |
107 |
if pos = len then assert false; |
if pos = len then assert false; |
108 |
match s.[pos] with |
match s.[pos] with |
109 |
| 'e' -> Dictionary (List.rev list), (pos+1) |
| 'e' -> Dictionary (List.rev list), (pos+1) |
110 |
| _ -> |
| _ -> |
111 |
let key, pos = decode s pos len in |
let key, pos = decode s pos len in |
112 |
let v, pos = decode s pos len in |
let v, pos = decode s pos len in |
113 |
iter s pos len ((key,v) :: list) |
iter s pos len ((key,v) :: list) |
117 |
in |
in |
118 |
let (v,pos) = decode s 0 len in |
let (v,pos) = decode s 0 len in |
119 |
v |
v |
120 |
|
|
121 |
let encode v = |
let encode v = |
122 |
let buf = Buffer.create 100 in |
let buf = Buffer.create 100 in |
123 |
let rec encode v = |
let rec encode v = |
140 |
let buf = Buffer.create 100 in |
let buf = Buffer.create 100 in |
141 |
let rec print v = |
let rec print v = |
142 |
match v with |
match v with |
143 |
| String s -> |
| String s -> |
144 |
if String.length s > 200 then |
if String.length s > 200 then |
145 |
Printf.bprintf buf " \"%s...\"" (String.escaped (String.sub s 0 200)) |
Printf.bprintf buf " \"%s...\"" (String.escaped (String.sub s 0 200)) |
146 |
else |
else |