Skip to content

Commit

Permalink
refactor: use protobufjs library to load proto file (#55)
Browse files Browse the repository at this point in the history
  • Loading branch information
kjin authored and stephenplusplus committed Apr 25, 2018
1 parent fe09381 commit 567e1f3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions packages/google-cloud-vision/src/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const fs = require('fs');
const is = require('is');
const path = require('path');
const promisify = require('@google-cloud/common').util.promisify;
const protobuf = require('protobufjs');

const gax = require('google-gax');

Expand Down Expand Up @@ -243,16 +244,19 @@ module.exports = apiVersion => {
});
});

// Get a list of features available on the API. Although we could iterate over
// them and create single-feature methods for each dynamically, for
// documentation purpose, we manually list all the single-feature methods
// below.
const features = gax
.grpc()
.loadProto(
path.join(__dirname, '..', 'protos'),
let protoFilesRoot = new gax.grpc.GoogleProtoFilesRoot();
protoFilesRoot = protobuf.loadSync(
path.join(
__dirname,
'..',
'protos',
`google/cloud/vision/${apiVersion}/image_annotator.proto`
).google.cloud.vision[apiVersion].Feature.Type.values;
),
protoFilesRoot
);
const features = protoFilesRoot.lookup(
`google.cloud.vision.${apiVersion}.Feature.Type`
).values;

/**
* Annotate a single image with face detection.
Expand Down

0 comments on commit 567e1f3

Please sign in to comment.