grpc-inspect
gRPC Protocol Buffer utility module that generates a descriptor object representing a friendlier descriptor object with utility methods for protocol buffer inspection.
Installation
npm install grpc-inspect
Overview
helloworld.proto
syntax = "proto3";
option java_multiple_files = true;
option java_package = "io.grpc.examples.helloworld";
option java_outer_classname = "HelloWorldProto";
option objc_class_prefix = "HLW";
package helloworld;
service Greeter {
// Sends a greeting
rpc SayHello (HelloRequest) returns (HelloReply) {}
}
message HelloRequest {
string name = 1;
}
message HelloReply {
string message = 1;
}
Sample usage:
const gi = const grpc = const pbpath = pathconst proto = grpcconst d = consoledird
Returned utility descriptor:
namespaces: helloworld: name: 'helloworld' messages: HelloRequest: name: 'HelloRequest' fields: name: 'name' type: 'string' id: 1 required: false repeated: false map: false defaultValue: '' HelloReply: name: 'HelloReply' fields: name: 'message' type: 'string' id: 1 required: false repeated: false map: false defaultValue: '' services: Greeter: name: 'Greeter' package: 'helloworld' methods: name: 'SayHello' requestStream: false responseStream: false requestName: 'HelloRequest' responseName: 'HelloReply' file: '/Users/me/protos/helloworld.proto' options: java_multiple_files: true java_package: 'io.grpc.examples.helloworld' java_outer_classname: 'HelloWorldProto' objc_class_prefix: 'HLW'
NOTE If no package name is specified in the protocol buffer definition an empty ''
string is used for the package / namespace name.
API Reference
Object
descriptor : Protocol Buffer utility descriptor represents friendlier descriptor object with utility methods for protocol buffer inspection.
Kind: global class
Access: public
- descriptor :
Object
- .namespaceNames() ⇒
Array
- .serviceNames(namespace) ⇒
Array
- .service(service) ⇒
Object
- .methodNames(service) ⇒
Array
- .methods(service) ⇒
Array
- .proto() ⇒
Object
- .client(serviceName) ⇒
Object
- .namespaceNames() ⇒
Array
descriptor.namespaceNames() ⇒ Returns an array of namespace names within the protocol buffer definition
Kind: static method of descriptor
Returns: Array
- array of names
Example
const grpcinspect = const grpc = const pbpath = pathconst proto = grpcconst d = console // ['routeguide']
Array
descriptor.serviceNames(namespace) ⇒ Returns an array of service names
Kind: static method of descriptor
Returns: Array
- array of names
Param | Type | Description |
---|---|---|
namespace | String |
Optional name of namespace to get services. If not present returns service names of all services within the definition. |
Example
const grpcinspect = const grpc = const pbpath = pathconst proto = grpcconst d = const grpcinspectproto console // ['RouteGuide']
Object
descriptor.service(service) ⇒ Returns the utility descriptor for the service given a servie name. Assumes there are no duplicate service names within the definition.
Kind: static method of descriptor
Returns: Object
- service utility descriptor
Param | Type | Description |
---|---|---|
service | String |
name of the service |
Example
const grpcinspect = const grpc = const pbpath = pathconst proto = grpcconst d = consoledird
Array
descriptor.methodNames(service) ⇒ Returns an array of method names for a service
Kind: static method of descriptor
Returns: Array
- array of names
Param | Type | Description |
---|---|---|
service | String |
name of the service |
Example
const grpcinspect = const grpc = const pbpath = pathconst proto = grpcconst d = console // [ 'GetFeature', 'ListFeatures', 'RecordRoute', 'RouteChat' ]
Array
descriptor.methods(service) ⇒ Returns an array the utility descriptors for the methods of a service. Assumes there are no duplicate service names within the definition.
Kind: static method of descriptor
Returns: Array
- array of method utility descriptors
Param | Type | Description |
---|---|---|
service | String |
name of the service |
Example
const grpcinspect = const grpc = const pbpath = pathconst proto = grpcconst d = consoledird
Object
descriptor.proto() ⇒ Returns the internal proto object
Kind: static method of descriptor
Returns: Object
- the internal proto object
Example
const grpcinspect = const grpc = const pbpath = pathconst proto = grpcconst d = consoledird
Object
descriptor.client(serviceName) ⇒ Gets the gRPC service / client object / function
Kind: static method of descriptor
Returns: Object
- the Client object
Param | Type | Description |
---|---|---|
serviceName | serviceName |
The service name. Can and should include package. |
Example
const grpcinspect = const grpc = const pbpath = pathconst proto = grpcconst d = consoledirdconsoledird
Object
grpcinspect(input) ⇒ Returns protocol buffer utility descriptor. Takes a loaded grpc / protocol buffer object and returns a friendlier descriptor object
Kind: global function
Returns: Object
- the utility descriptor
Param | Type | Description |
---|---|---|
input | Object |
loaded proto object |
Example
const gi = const grpc = const pbpath = pathconst proto = grpcconst d = consoledird
License
Apache 2.0