forked from petercable/grpc_requests
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #23 from wesky93/viridianforge/retrieve-fields
Viridianforge/retrieve fields
- Loading branch information
Showing
22 changed files
with
456 additions
and
25 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
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,50 @@ | ||
from grpc_requests.client import Client | ||
|
||
""" | ||
helloworld_reflection | ||
An example of how grpc_requests works against a reflection enabled grpc server. | ||
In order for this example to work, the example helloworld server must be | ||
running. | ||
""" | ||
|
||
host = 'localhost' | ||
port = '50051' | ||
endpoint = f"{host}:{port}" | ||
|
||
client = Client.get_by_endpoint(endpoint) | ||
|
||
service = 'client_tester.ClientTester' | ||
|
||
# Unary-Unary Example | ||
|
||
unary_unary_method = 'TestUnaryUnary' | ||
unary_unary_request = {} | ||
|
||
response = client.unary_unary(service, unary_unary_method, unary_unary_request) | ||
print(response) | ||
|
||
# Unary-Stream Example | ||
|
||
unary_stream_method = 'TestUnaryStream' | ||
unary_stream_request = {} | ||
|
||
responses = client.unary_stream(service, unary_stream_method, unary_stream_request) | ||
print(responses) | ||
|
||
# Stream-Unary Example | ||
|
||
stream_unary_method = 'TestStreamUnary' | ||
stream_unary_request = [{}, {}, {}] | ||
|
||
response = client.stream_unary(service, stream_unary_method, stream_unary_request) | ||
print(response) | ||
|
||
# Stream-Stream Example | ||
|
||
stream_stream_method = 'TestStreamStream' | ||
stream_stream_request = [{}, {}, {}] | ||
|
||
responses = client.stream_stream(service, stream_stream_method, stream_stream_request) | ||
print(responses) |
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
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 |
---|---|---|
@@ -1,7 +1,41 @@ | ||
from pathlib import Path | ||
from google.protobuf.descriptor import MethodDescriptor | ||
|
||
# String descriptions of protobuf field types | ||
FIELD_TYPES = [ | ||
'DOUBLE', | ||
'FLOAT', | ||
'INT64', | ||
'UINT64', | ||
'INT32', | ||
'FIXED64', | ||
'FIXED32', | ||
'BOOL', | ||
'STRING', | ||
'GROUP', | ||
'MESSAGE', | ||
'BYTES', | ||
'UINT32', | ||
'ENUM', | ||
'SFIXED32', | ||
'SFIXED64', | ||
'SINT32', | ||
'SINT64' | ||
] | ||
|
||
def load_data(_path): | ||
with open(Path(_path).expanduser(), 'rb') as f: | ||
data = f.read() | ||
return data | ||
|
||
def describe_request(method_descriptor: MethodDescriptor) -> dict: | ||
""" | ||
Provide a dictionary that describes the fields of a Method request | ||
with a string description of their types. | ||
:param method_descriptor: MethodDescriptor | ||
:return: dict - a mapping of field names to their types | ||
""" | ||
description = {} | ||
for field in method_descriptor.input_type.fields: | ||
description[field.name] = FIELD_TYPES[field.type-1] | ||
return description |
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
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
File renamed without changes.
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,24 @@ | ||
syntax = "proto3"; | ||
|
||
package client_tester; | ||
|
||
service ClientTester { | ||
rpc TestUnaryUnary (TestRequest) returns (TestResponse) {} | ||
rpc TestUnaryStream (TestRequest) returns (stream TestResponse) {} | ||
rpc TestStreamUnary (stream TestRequest) returns (TestResponse) {} | ||
rpc TestStreamStream (stream TestRequest) returns (stream TestResponse) {} | ||
} | ||
|
||
message TestRequest { | ||
int32 factor = 1; | ||
repeated float readings = 2; | ||
uint64 uuid = 3; | ||
bool sample_flag = 4; | ||
string request_name = 5; | ||
repeated bytes extra_data = 6; | ||
} | ||
|
||
message TestResponse { | ||
double average = 1; | ||
string feedback = 2; | ||
} |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
Oops, something went wrong.