Skip to content

Instantly share code, notes, and snippets.

@navono navono/protobufjs
Created Jun 21, 2019

Embed
What would you like to do?
Load proto(with third party proto files) with protobufjs
const root = new protobuf.Root();
root.resolvePath = function(origin, target) {
if (origin.length === 0) {
return target;
}
if (target.startsWith('are')) {
const protoPath = path.resolve(__dirname, '../', target)
console.log('path: ', protoPath);
return protoPath;
}
const protoPath = path.resolve(__dirname, '../third_party', target)
console.log('path: ', protoPath);
return protoPath;
};
root.load(path.resolve(__dirname, "../are/api/service/realtimedata/v1alpha/realtime.proto"), function(err, root) {
if (err)
throw err;
const RealtimeDataService = root.lookupType("are.service.realtimedata.v1alpha.RealtimeDataService");
const service = RealtimeDataService.create(rpcImpl, false, false);
service.readTag({}, )
// Exemplary payload
const payload = { name: "AwesomeString" };
// Verify the payload if necessary (i.e. when possibly incomplete or invalid)
const errMsg = OpenServiceRequest.verify(payload);
if (errMsg) {
throw Error(errMsg);
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.