Skip to content

Commit

Permalink
README
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesdbrock committed Dec 3, 2024
1 parent 610ef79 commit 2008cc9
Showing 1 changed file with 21 additions and 13 deletions.
34 changes: 21 additions & 13 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -68,36 +68,33 @@ To compile PureScript .purs files from .proto files, run for example:
We can test out code generation immediately by
generating `.purs` files for any of Google’s built-in “well-known types” in the
[`google.protobuf`](https://protobuf.dev/reference/protobuf/google.protobuf/) package namespace. Try the command
```console
```shell
protoc --purescript_out=. google/protobuf/any.proto
```
or
```console
```shell
protoc --purescript_out=. google/protobuf/timestamp.proto
```

To see
[all of the `.proto` definitions](https://github.com/protocolbuffers/protobuf/tree/main/src/google/protobuf)
included with the Nix PureScript Protobuf installation including
the “well-known types,”
```console
```shell
ls $(nix path-info .#protobuf)/src/google/protobuf/*.proto
```
If you don't want to use Nix,
1. install the PureScript toolchain and `protoc`.
2. Build the [PureScript plugin for `protoc`](plugin/).
3. Run `protoc` with the path to the PureScript plugin executable, like for example
```console
```shell
protoc --plugin=bin/protoc-gen-purescript --purescript_out=. google/protobuf/timestamp.proto
```
## Writing programs with the generated code
The code generator will use the `package` import statement in the `.proto` file
and the base `.proto` file name as the PureScript module name for that file.

A message in a `shapes.proto` descriptor file declared as
Suppose we have a `Rectangle` message declared in a `shapes.proto` descriptor file:
```
syntax = "proto3";
Expand All @@ -109,8 +106,19 @@ message Rectangle {
}
```
will export these four names from module `Interproc.Shapes` in a
generated `shapes.Interproc.purs` file.
We run
```shell
protoc --purescript_out=. shapes.proto
```
which will generate a file `shapes.Interproc.purs`.
The code generator will use the `package` import statement in the `.proto` file
and the base `.proto` file name as the PureScript module name for that file.
The generated `shapes.Interproc.purs` file
will export these four names from module `Interproc.Shapes`.
1. A message data type.
Expand Down Expand Up @@ -258,12 +266,12 @@ programs which use code generated by __protobuf__. Refer to these
for further examples of how to use the generated code.
1. The `protoc`
[compiler plugin](https://github.com/xc-jp/purescript-protobuf/blob/master/plugin/src/Main.purs).
[compiler plugin](https://github.com/rowtype-yoga/purescript-protobuf/blob/master/plugin/src/Main.purs).
The code generator imports generated code. This program writes itself.
2. The
[unit test suite](https://github.com/xc-jp/purescript-protobuf/blob/master/library/test/Main.purs)
[unit test suite](https://github.com/rowtype-yoga/purescript-protobuf/blob/master/plugin/test/Test/Main.purs).
3. The Google
[conformance test program](https://github.com/xc-jp/purescript-protobuf/blob/master/conformance/src/Main.purs)
[conformance test program](https://github.com/xc-jp/purescript-protobuf/blob/master/conformance/src/Main.purs).
The [Protobuf Decoder Explainer](http://jamesdbrock.github.io/protobuf-decoder-explainer/) shows an
example of how to use this library to parse binary Protobuf when we don’t
Expand Down

0 comments on commit 2008cc9

Please sign in to comment.