/[mldonkey]/mldonkey/src/networks/bittorrent/bencode.ml
ViewVC logotype

Diff of /mldonkey/src/networks/bittorrent/bencode.ml

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.2 by simon_mld, Thu Apr 24 12:45:46 2003 UTC revision 1.3 by spiralvoice, Sun Aug 7 12:57:22 2005 UTC
# Line 57  open Printf2 Line 57  open Printf2
57   }   }
58   ;   ;
59    }    }
60      
61  *)  *)
62  type value =  type value =
63    String of string    String of string
# Line 91  let decode s = Line 91  let decode s =
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)
# Line 117  let decode s = Line 117  let decode s =
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 =
# Line 140  let print b = Line 140  let print b =
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

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.3

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26