How to use the protobufjs.load function in protobufjs

To help you get started, we’ve selected a few protobufjs examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xanthous-tech / grpc-graphql-schema / lib / protobuf.js View on Github external
return __awaiter(this, void 0, void 0, function* () {
        const protoDefinition = yield protobuf.load(protoFile);
        const protoDefinitionObject = yield protoDefinition.toJSON();
        const packagePaths = packageName.split('.');
        for (let i = 0; i < packagePaths.length; i += 2) {
            packagePaths.splice(i, 0, 'nested');
        }
        return _.get(protoDefinitionObject, packagePaths.join('.'));
    });
}
github MatthieuLemoine / push-receiver / src / client.js View on Github external
static async init() {
    if (proto) {
      return;
    }
    proto = await load(path.resolve(__dirname, 'mcs.proto'));
  }
github wyvernlang / wyvern / backend / proto_example / src / main.js View on Github external
const protobuf = require("protobufjs");

const fs = require("fs");

protobuf.load("../bytecode.proto", function(err, root) {
    if (err) throw err;
    const Bytecode = root.lookupType('Bytecode');

    const bytecodeData = {
        version: {magic: 42, major: 0, minor: 1},
        path: "com.example",
        imports: [],
        modules: [{
            path: "HelloWorld",
            valueModule: {
                type: {
                    simpleType: root.lookupEnum("Type.SimpleType").values.Top
                },
                expression: {
                    literal: {
                        stringLiteral: "Hello, world!"
github sebmos / node-eufy-api / src / device-light-bulb.ts View on Github external
let newColors: RgbColors | undefined;
		if (options.colors !== undefined) {
			if (!this.supportsColors()) {
				throw new Error('Changing colors is not supported by this device');
			}

			newColors = {
				red: Math.round(this.parseValueAsNumber('red color', options.colors.red, 255)),
				green: Math.round(this.parseValueAsNumber('green color', options.colors.green, 255)),
				blue: Math.round(this.parseValueAsNumber('blue color', options.colors.blue, 255))
			};

			log.verbose('LightBulb.setState', 'Colors:', JSON.stringify(newColors));
		}

		const proto = await protobuf.load(`${__dirname}/lakeside.proto`);
		let message: Message = {
			sequence: await this.getSequence(),
			code: this.code
		};

		let packetType: protobuf.Type;
		if (isWhiteLightBulb(this.model)) {
			log.verbose('LightBulb.setState', 'Treat as white light bulb (T1012Packet)');

			packetType = proto.lookupType('lakeside.T1012Packet');
			message.bulbinfo = {
				type: 0,
				packet: {
					unknown1: 100,
					bulbset: {
						command: 7
github ericbets / danby / danby.js View on Github external
async function main() {
	if (typeof(argv.cfg)!=='undefined') {
		cfgData = toml.parse(fs.readFileSync(argv.cfg,'utf8'));
		var servers = [];
		Object.keys(cfgData["server"]).forEach((name) => {
			servers.push(cfgData["server"][name]);	
		});

		for (let item of servers) {
			if (item.service) {
				let root = await protobuf.load(item.proto);
				const apiData = api(root,item.service, wsProto);
				var generatedApi = apiData["output"];
				var methodNames = apiData["methods"];
				var proto = grpc.load(item.proto);
				var stub=null; 
				eval("stub = proto." + item.pkg);
				var service = { cfg:item, api:generatedApi,methods:methodNames,remote:stub, grpc:item.grpc};
				services[item.service] = service;
				apiText+=generatedApi;
			}
		}
	}

	app.use(require('helmet')());

	if (typeof(argv.webroot)=='undefined')
github sebmos / node-eufy-api / src / device-light-bulb.ts View on Github external
private async getState(): Promise {
		log.verbose('LightBulb.getState', 'Loading current device state');

		const proto = await protobuf.load(`${__dirname}/lakeside.proto`);

		const packetType = proto.lookupType('lakeside.T1012Packet');
		const packet = packetType.encode({
			sequence: await this.getSequence(),
			code: this.code,
			bulbInfo: {
				type: 1
			}
		}).finish();

		log.verbose('LightBulb.getState', 'Sending request to device');

		return await this.sendPacketWithResponse(packet);
	}
github MatthieuLemoine / push-receiver / proxy / index.js View on Github external
function loadProtoFile() {
  return protobuf.load(
    path.join(__dirname, '..', 'src', 'client', 'mcs.proto')
  );
}
github MatthieuLemoine / push-receiver / src / gcm / index.js View on Github external
async function loadProtoFile() {
  if (root) {
    return;
  }
  root = await protobuf.load(path.join(__dirname, 'checkin.proto'));
  return root;
}
github MatthieuLemoine / push-receiver / src / client / index.js View on Github external
function loadProtoFile() {
  return protobuf.load(path.join(__dirname, 'mcs.proto'));
}