-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
add an example extracted from a bench
- Loading branch information
Showing
3 changed files
with
112 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
|
||
syntax = "proto3"; | ||
|
||
message Person { | ||
string name = 1; | ||
sint64 age = 2; | ||
} | ||
|
||
message Store { | ||
string address = 1; | ||
repeated Person employees = 2; | ||
repeated Person clients = 3; | ||
} | ||
|
||
message Company { | ||
string name = 1; | ||
repeated Store stores = 2; | ||
repeated Company subsidiaries = 3; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
open Orgchart | ||
|
||
let spf = Printf.sprintf | ||
|
||
(* company, with [n] stores and [2^depth] subsidiaries *) | ||
let rec mk_company ~n ~depth : company = | ||
{ | ||
name = "bigcorp"; | ||
subsidiaries = | ||
(if depth = 0 then | ||
[] | ||
else ( | ||
let c = mk_company ~n ~depth:(depth - 1) in | ||
[ c; c ] | ||
)); | ||
stores = | ||
List.init n (fun i -> | ||
{ | ||
address = spf "%d foobar street" i; | ||
clients = | ||
List.init 2 (fun j -> | ||
{ | ||
name = spf "client_%d_%d" i j; | ||
age = Int64.of_int ((j mod 30) + 15); | ||
}); | ||
employees = | ||
List.init 2 (fun j -> | ||
{ | ||
name = spf "employee_%d_%d" i j; | ||
age = Int64.of_int ((j mod 30) + 18); | ||
}); | ||
}); | ||
} | ||
|
||
let test ~n ~depth () : unit = | ||
let c = mk_company ~n ~depth in | ||
let enc = Pbrt.Encoder.create () in | ||
encode_pb_company c enc; | ||
let str = Pbrt.Encoder.to_string enc in | ||
let c2 = | ||
let dec = Pbrt.Decoder.of_string str in | ||
decode_pb_company dec | ||
in | ||
|
||
if c <> c2 then ( | ||
Format.eprintf "c=%a@." pp_company c; | ||
Format.eprintf "dec(enc(c))=%a@." pp_company c2; | ||
failwith @@ spf "failed for n=%d, depth=%d" n depth | ||
) | ||
(* else Printf.eprintf "ok for n=%d, depth=%d\n%!" n depth *) | ||
|
||
let () = | ||
List.iter | ||
(fun (n, depth) -> test ~n ~depth ()) | ||
[ | ||
1, 1; | ||
1, 1; | ||
1, 4; | ||
1, 6; | ||
1, 10; | ||
2, 1; | ||
2, 4; | ||
2, 6; | ||
2, 10; | ||
5, 1; | ||
5, 4; | ||
5, 6; | ||
10, 1; | ||
10, 2; | ||
10, 3; | ||
10, 4; | ||
20, 1; | ||
50, 1; | ||
20, 3; | ||
20, 4; | ||
50, 1; | ||
50, 3; | ||
50, 4; | ||
100, 1; | ||
100, 3; | ||
] |