-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add example on howe to use proto2 extensions
- Loading branch information
1 parent
4f03eb6
commit 9fa9fbb
Showing
4 changed files
with
72 additions
and
20 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,16 @@ | ||
(executable | ||
(name test) | ||
(libraries ocaml-protoc-plugin ocaml-protoc-plugin.google_types unix) | ||
) | ||
|
||
(rule | ||
(targets extensions.ml) | ||
(deps | ||
(:proto extensions.proto)) | ||
(action | ||
(run protoc -I . "--ocaml_out=:." %{proto}))) | ||
|
||
(alias | ||
(name runtest) | ||
(deps test.exe) | ||
) |
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,10 @@ | ||
syntax = "proto2"; | ||
message Foo { | ||
required uint32 i = 1; | ||
extensions 100 to 200; | ||
|
||
} | ||
extend Foo { | ||
optional uint32 bar = 128; | ||
optional string baz = 129; | ||
} |
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,20 @@ | ||
open Extensions | ||
|
||
(* Set extensions *) | ||
let _ = | ||
let foo = Foo.{ i = 31; extensions' = Ocaml_protoc_plugin.Extensions.default } in | ||
let foo_with_bar = Bar.set foo (Some 42) in | ||
let foo_with_baz = Baz.set foo (Some "Test String") in | ||
let foo_with_bar_baz = Baz.set foo_with_bar (Some "Test String") in | ||
|
||
(* Get extensions *) | ||
let open Ocaml_protoc_plugin.Result in | ||
Bar.get foo_with_bar >>= fun bar -> | ||
Baz.get foo_with_baz >>= fun baz -> | ||
assert (bar = Some 42); | ||
assert (baz = Some "Test String"); | ||
Bar.get foo_with_bar_baz >>= fun bar' -> | ||
Baz.get foo_with_bar_baz >>= fun baz' -> | ||
assert (bar' = Some 42); | ||
assert (baz' = Some "Test String"); | ||
return () |