Skip to content

Commit c7b7909

Browse files
committed
Add example
1 parent b164a8f commit c7b7909

File tree

4 files changed

+101
-0
lines changed

4 files changed

+101
-0
lines changed

example/README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Prototool-docker Example
2+
========================
3+
4+
Run `./build.sh` to generate Go and Java code from `proto/telemetry.proto`

example/build.sh

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#!/usr/bin/env bash
2+
3+
USER="$(id -u):$(id -g)"
4+
5+
rm -rf go java
6+
docker run --rm --user $USER -i -t -v $(pwd):/in charithe/prototool-docker all

example/proto/telemetry.proto

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
syntax = "proto3";
2+
3+
package charithe.telemetry.v1;
4+
5+
option go_package = "v1pb";
6+
option java_multiple_files = true;
7+
option java_outer_classname = "TelemetryProto";
8+
option java_package = "io.github.charithe.telemetry.v1";
9+
10+
import "google/protobuf/timestamp.proto";
11+
import "validate/validate.proto";
12+
13+
service Telemetry {
14+
// Record receives and persists telemetry data from remote devices
15+
rpc Record(RecordRequest) returns (RecordResponse);
16+
}
17+
18+
message RecordRequest {
19+
TelemetryData data = 1;
20+
}
21+
22+
message RecordResponse {}
23+
24+
message TelemetryData {
25+
// device_id must start with 'device' and be between 12 and 24 characters in length
26+
string device_id = 1 [
27+
(validate.rules).string = {
28+
prefix: "device-"
29+
min_len: 12
30+
max_len: 24
31+
}
32+
];
33+
// ip_address must be a valida IP adddress
34+
string ip_address = 2 [(validate.rules).string.ip = true];
35+
// software_version must be between 100 and 200
36+
uint32 software_version = 3 [
37+
(validate.rules).uint32 = {
38+
gte: 100
39+
lt: 200
40+
}
41+
];
42+
// temperature must be between -60 and 190.5
43+
float temperature = 4 [
44+
(validate.rules).float = {
45+
gte: -60.0
46+
lte: 190.5
47+
}
48+
];
49+
// log_entries must contain at least one entry
50+
repeated LogEntry log_entries = 5 [(validate.rules).repeated.min_items = 1];
51+
}
52+
53+
message LogEntry {
54+
// timestamp must be after 2018-01-01
55+
google.protobuf.Timestamp timestamp = 1 [(validate.rules).timestamp.gte.seconds = 1514764800];
56+
// component must be at least 5 characters long
57+
string component = 2 [(validate.rules).string.min_len = 5];
58+
// state must be at least 10 bytes long
59+
bytes state = 3 [(validate.rules).bytes.min_len = 10];
60+
}

example/prototool.yaml

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
protoc:
2+
version: 3.6.1
3+
includes:
4+
- /include
5+
6+
lint:
7+
rules:
8+
remove:
9+
- FILE_OPTIONS_EQUAL_JAVA_PACKAGE_COM_PREFIX
10+
11+
generate:
12+
go_options:
13+
import_path: github.com/charithe/telemetry
14+
15+
plugins:
16+
- name: gogofast
17+
type: gogo
18+
path: /bin/protoc-gen-gogofast
19+
flags: plugins=grpc
20+
output: ./go/pkg/gen
21+
- name: validate
22+
path: /bin/protoc-gen-validate
23+
flags: lang=go
24+
output: ./go/pkg/gen
25+
- name: java
26+
output: ./java/src/main/java
27+
- name: grpc-java
28+
path: /bin/protoc-gen-grpc-java
29+
output: ./java/src/main/java
30+
31+

0 commit comments

Comments
 (0)