0.5.4 • Published 6 years ago
@ln-zap/proto-loader v0.5.4
gRPC Protobuf Loader
A utility package for loading .proto files for use with gRPC, using the latest Protobuf.js package.
Please refer to protobuf.js' documentation
to understands its features and limitations.
Installation
npm install @grpc/proto-loaderUsage
const protoLoader = require('@grpc/proto-loader');
const grpcLibrary = require('grpc');
// OR
const grpcLibrary = require('@grpc/grpc-js');
protoLoader.load(protoFileName, options).then(packageDefinition => {
  const packageObject = grpcLibrary.loadPackageDefinition(packageDefinition);
});
// OR
const packageDefinition = protoLoader.loadSync(protoFileName, options);
const packageObject = grpcLibrary.loadPackageDefinition(packageDefinition);The options parameter is an object that can have the following optional properties:
| Field name | Valid values | Description | 
|---|---|---|
| keepCase | trueorfalse | Preserve field names. The default is to change them to camel case. | 
| longs | StringorNumber | The type to use to represent longvalues. Defaults to aLongobject type. | 
| enums | String | The type to use to represent enumvalues. Defaults to the numeric value. | 
| bytes | ArrayorString | The type to use to represent bytesvalues. Defaults toBuffer. | 
| defaults | trueorfalse | Set default values on output objects. Defaults to false. | 
| arrays | trueorfalse | Set empty arrays for missing array values even if defaultsisfalseDefaults tofalse. | 
| objects | trueorfalse | Set empty objects for missing object values even if defaultsisfalseDefaults tofalse. | 
| oneofs | trueorfalse | Set virtual oneof properties to the present field's name. Defaults to false. | 
| includeDirs | An array of strings | A list of search paths for imported .protofiles. | 
The following options object closely approximates the existing behavior of grpc.load:
const options = {
  keepCase: true,
  longs: String,
  enums: String,
  defaults: true,
  oneofs: true
}