Skip to content

Commit b1f779f

Browse files
authored
Merge pull request #41 from oslabs-beta/nestedMessages
Nested messages
2 parents cc99252 + 4b914e0 commit b1f779f

File tree

2 files changed

+133
-26
lines changed

2 files changed

+133
-26
lines changed

src/client/components/composer/NewRequest/GRPCAutoInputForm.jsx

Lines changed: 33 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class GRPCAutoInputForm extends Component {
1414
this.setService = this.setService.bind(this);
1515
this.setRequest = this.setRequest.bind(this);
1616
}
17-
// event handler on the arrow button that allows you to open/close the section
17+
// event handler on the arrow button that allows you to open/close the section
1818
toggleShow() {
1919
this.setState({
2020
show: !this.state.show
@@ -80,9 +80,9 @@ class GRPCAutoInputForm extends Component {
8080
let streamingType;
8181
let packageName;
8282
/*
83-
for each service obj in the services array, if its name matches the current selected service option then:
83+
for each service obj in the services array, if its name matches the current selected service option then:
8484
- save the package name
85-
- iterate through the rpcs and if its name matches the current selected request then save its streaming type
85+
- iterate through the rpcs and if its name matches the current selected request then save its streaming type
8686
*/
8787
for (const service of services) {
8888
if (service.name === selectedService ) {
@@ -106,7 +106,7 @@ class GRPCAutoInputForm extends Component {
106106
let req;
107107
let results = [];
108108
let query = '';
109-
/*
109+
/*
110110
for each service obj in the services array, if its name matches the current selected service option then:
111111
- iterate through the rpcs and if its name matches the current selected request then save the name of req/rpc
112112
- iterate through the messages and if its name matches the saved req/rpc name,
@@ -120,15 +120,41 @@ class GRPCAutoInputForm extends Component {
120120
}
121121
}
122122
for (const message of service.messages) {
123+
// console.log('message: ', message);
123124
if (message.name === req ) {
124125
for (const key in message.def) {
126+
// if message type is a nested message (message.def.nested === true)
127+
// message.def = key: {dependent: dependent.message.def}
128+
// console.log('message.def.nested: ', message.def[key].nested);
129+
// console.log('key: ', key);
130+
if (message.def[key].nested) {
131+
for (const submess of service.messages) {
132+
// console.log('submess: ', submess);
133+
// console.log('submess.name: ', submess.name);
134+
// console.log('message.def[key].dependent: ', message.def[key].dependent);
135+
if (submess.name === message.def[key].dependent ) {
136+
// define obj for the submessage definition
137+
let tempObj = {};
138+
for (const subKey in submess.def) {
139+
tempObj[subKey] = submess.def[subKey].type.slice(5).toLowerCase()
140+
}
141+
// console.log('tempObj: ', tempObj);
142+
results.push(`"${key}":${JSON.stringify(tempObj)}`)
143+
break;
144+
}
145+
// break;
146+
}//after
147+
} else {
148+
// console.log('message.def: ', message.def);
125149
results.push(`"${key}": "${message.def[key].type.slice(5).toLowerCase()}"`)
126150
}
127-
break;
128151
}
129-
}
152+
break;
130153
}
131154
}
155+
}
156+
}
157+
132158
const streamsArr = this.props.newRequestStreams.streamsArr;
133159
const streamContent = this.props.newRequestStreams.streamContent;
134160
// query for messages with single key:value pair
@@ -143,7 +169,7 @@ class GRPCAutoInputForm extends Component {
143169
}
144170
query = query.slice(1).trim();
145171
}
146-
// set query in streamsArr
172+
// set query in streamsArr
147173
if (streamsArr[0] !== '') {
148174
streamsArr[0].query = `{
149175
${query}
Lines changed: 100 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,111 @@
1+
// Copyright 2015 gRPC authors.
2+
//
3+
// Licensed under the Apache License, Version 2.0 (the "License");
4+
// you may not use this file except in compliance with the License.
5+
// You may obtain a copy of the License at
6+
//
7+
// http://www.apache.org/licenses/LICENSE-2.0
8+
//
9+
// Unless required by applicable law or agreed to in writing, software
10+
// distributed under the License is distributed on an "AS IS" BASIS,
11+
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12+
// See the License for the specific language governing permissions and
13+
// limitations under the License.
14+
115
syntax = "proto3";
216

3-
package helloworld;
17+
option java_multiple_files = true;
18+
option java_package = "io.grpc.examples.routeguide";
19+
option java_outer_classname = "RouteGuideProto";
20+
option objc_class_prefix = "RTG";
21+
22+
package routeguide;
23+
24+
// Interface exported by the server.
25+
service RouteGuide {
26+
// A simple RPC.
27+
//
28+
// Obtains the feature at a given position.
29+
//
30+
// A feature with an empty name is returned if there's no feature at the given
31+
// position.
32+
rpc GetFeature(Point) returns (Feature) {}
33+
34+
// A server-to-client streaming RPC.
35+
//
36+
// Obtains the Features available within the given Rectangle. Results are
37+
// streamed rather than returned at once (e.g. in a response message with a
38+
// repeated field), as the rectangle may cover a large area and contain a
39+
// huge number of features.
40+
rpc ListFeatures(Rectangle) returns (stream Feature) {}
441

5-
// The greeting service definition.
6-
service Greeter {
7-
// Sends a greeting
8-
rpc SayHello (HelloRequest) returns (HelloReply) {}
9-
rpc SayHelloCS (stream HelloRequest) returns (HelloReply) {}
10-
rpc SayHellos (HelloRequest) returns (stream HelloReply) {}
11-
rpc SayHelloBidi (stream HelloRequest) returns (stream HelloReply) {}
42+
// A client-to-server streaming RPC.
43+
//
44+
// Accepts a stream of Points on a route being traversed, returning a
45+
// RouteSummary when traversal is completed.
46+
rpc RecordRoute(stream Point) returns (RouteSummary) {}
47+
48+
// A Bidirectional streaming RPC.
49+
//
50+
// Accepts a stream of RouteNotes sent while a route is being traversed,
51+
// while receiving other RouteNotes (e.g. from other users).
52+
rpc RouteChat(stream RouteNote) returns (stream RouteNote) {}
1253
}
1354

14-
// The request message containing the user's name.
15-
message HelloRequest {
16-
string name = 1;
55+
// Points are represented as latitude-longitude pairs in the E7 representation
56+
// (degrees multiplied by 10**7 and rounded to the nearest integer).
57+
// Latitudes should be in the range +/- 90 degrees and longitude should be in
58+
// the range +/- 180 degrees (inclusive).
59+
message Point {
60+
int32 latitude = 1;
61+
int32 longitude = 2;
62+
}
63+
64+
// A latitude-longitude rectangle, represented as two diagonally opposite
65+
// points "lo" and "hi".
66+
message Rectangle {
67+
// One corner of the rectangle.
68+
Point lo = 1;
69+
70+
// The other corner of the rectangle.
71+
Point hi = 2;
1772
}
1873

19-
// The response message containing the greetings
20-
message HelloReply {
21-
string message = 1;
74+
// A feature names something at a given point.
75+
//
76+
// If a feature could not be named, the name is empty.
77+
message Feature {
78+
// The name of the feature.
79+
string name = 1;
80+
81+
// The point where the feature is detected.
82+
Point location = 2;
2283
}
2384

24-
// The request message containing the user's name.
25-
message HelloHowOldRequest {
26-
int32 age = 1;
85+
// A RouteNote is a message sent while at a given point.
86+
message RouteNote {
87+
// The location from which the message is sent.
88+
Point location = 1;
89+
90+
// The message to be sent.
91+
string message = 2;
2792
}
28-
message HelloAge {
29-
int32 age = 1;
93+
94+
// A RouteSummary is received in response to a RecordRoute rpc.
95+
//
96+
// It contains the number of individual points received, the number of
97+
// detected features, and the total distance covered as the cumulative sum of
98+
// the distance between each point.
99+
message RouteSummary {
100+
// The number of points received.
101+
int32 point_count = 1;
102+
103+
// The number of known features passed while traversing the route.
104+
int32 feature_count = 2;
105+
106+
// The distance covered in metres.
107+
int32 distance = 3;
108+
109+
// The duration of the traversal in seconds.
110+
int32 elapsed_time = 4;
30111
}

0 commit comments

Comments
 (0)