How to use the protobufjs.Root 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 hyperledger / composer-tools / packages / composer-protobuf / lib / protobufconverter.js View on Github external
static convert(protoFile, outputDir) {
        console.log('Parsing: ' + protoFile);

        const root = new protobuf.Root();
        root.loadSync(protoFile);
        //console.log(JSON.stringify(root));
        const writer = new FileWriter(outputDir);
        const outputFile = path.parse(protoFile).name + '.cto';
        writer.openFile(outputFile);
        const ns = ProtobufConverter.convertItem(writer, root, 0);
        writer.writeBeforeLine(0, 'namespace ' + ns.substring(1)); // discard the leading .
        writer.closeFile();
        console.log('Generated: ' + outputFile);
        return outputDir + '/' + outputFile;
    }
github Rampage1xx / EXPRESS-GraphQL-SQL-Redux-Example / Backend / database / Redis.ts View on Github external
import * as bluebird from 'bluebird';
import * as protobuf from 'protobufjs';
import * as redis from 'redis';
import { TProtoBuffer } from '../types/database.types';

bluebird.promisifyAll((redis as any).RedisClient.prototype);
bluebird.promisifyAll((redis as any).Multi.prototype);

const root = new protobuf.Root();

export const redisClient: any = redis.createClient({
    host          : 'redis',
    port          : 6379,
    return_buffers: true,
});

redisClient.flushdbAsync().then(done => console.log('**** REDIS FLUSHED ****'));

// SERIALIZING REDIS DATA //
export const ImagesArrayProtoBuffer: TProtoBuffer = ({ argument, encode, decode }) =>
{

    return root.load('./database/Images.proto', { keepCase: true })
               .then(ProtoFile =>
               {
github GroaJS / groa / lib / loader.js View on Github external
const prepareRoot = async function() {

	const root = new ProtoBuf.Root();

	// Support google extension
	let _resolve = root.resolvePath;
	root.resolvePath = (origin, target) => {

		if (target.search('google') === 0) {
			return path.join(__dirname, '..', 'node_modules/google-proto-files', target);
		}

		return _resolve(origin, target);
	};

	return root;
}
github pioneers / PieCentral / dawn / fake-runtime / FakeRuntime.js View on Github external
/*
 * Fake Runtime is not handled by webpack like most of the other JS code but instead
 * will be run "as is" as a child-process of the rest of the application.
 * See DebugMenu.js for handling FakeRuntime within Dawn
 */

/* eslint-disable camelcase */

const dgram = require('dgram');
const net = require('net');
const protobuf = require('protobufjs');

const DawnData = (new protobuf.Root()).loadSync('../ansible-protos/ansible.proto', { keepCase: true }).lookupType('DawnData');
const RuntimeData = (new protobuf.Root()).loadSync('../ansible-protos/runtime.proto', { keepCase: true }).lookupType('RuntimeData');
const Notification = (new protobuf.Root()).loadSync('../ansible-protos/notification.proto', { keepCase: true }).lookupType('Notification');

const TCPPORT = 1234;
const SENDPORT = 1235;
const LISTENPORT = 1236;
const MSGINTERVAL = 1000; // in ms

const randomFloat = (min, max) => (((max - min) * Math.random()) + min);
const sensor = (device_type, device_name, param_value, uid) => ({
  device_type,
  device_name,
  param_value,
  uid,
});
const param = (param, type, value) => ({ // eslint-disable-line no-shadow
  param,
  float_value: type === 'float' ? value : undefined,
github auth0 / auth0-instrumentation / lib / tracer.js View on Github external
const path = require('path');
const protobuf = require('protobufjs');

const requestHelper = require('./trace_request');
const middleware = require('./tracer_middleware');
const tracing = require('opentracing');
const tracerFactory = require('./tracer_factory');
const constants = require('./constants');
const os = require('os');
const tracerUtils = require('./tracer_utils');
const opentracing = require('opentracing');

const protoRoot = new protobuf.Root();
protoRoot.loadSync(path.join(__dirname, 'trace_context.proto'));
const SpanContext = protoRoot.lookupType('auth0.instrumentation.SpanContext');

const Tags = Object.assign({
  AUTH0_TENANT: constants.TAG_AUTH0_TENANT,
  AUTH0_ENVIRONMENT: constants.TAG_AUTH0_ENVIRONMENT,
  AUTH0_REGION: constants.TAG_AUTH0_REGION,
  AUTH0_CHANNEL: constants.TAG_AUTH0_CHANNEL,
  AUTH0_HOSTNAME: constants.TAG_AUTH0_HOSTNAME,
  AUTH0_PURPOSE: constants.TAG_AUTH0_PURPOSE,
  AUTH0_REQUEST_ID: constants.TAG_AUTH0_REQUEST_ID,
  AUTH0_WORKER_QUEUE: constants.TAG_AUTH0_WORKER_QUEUE,
  AUTH0_WORKER_STRATEGY: constants.TAG_AUTH0_WORKER_STRATEGY,
  AUTH0_WORKER_REQUEUE: constants.TAG_AUTH0_WORKER_REQUEUE,
  AUTH0_JOB_ID: constants.TAG_AUTH0_JOB_ID,
  AUTH0_JOB_TYPE: constants.TAG_AUTH0_JOB_TYPE,
github ZeusWPI / MOZAIC / client / gulpfile.js View on Github external
decode: true,
        verify: true,
        convert: true,
        delimited: true,
        beautify: true,
        comments: true,
        es6: false,
        wrap: 'commonjs',
        "keepCase": false,
        "forceLong": false,
        "forceNumber": true,
        "forceEnumString": true,
        "forceMessage": false,
    };

    var root = new protobuf.Root();

    function parse_file(file, enc, callback) {
        if (!file.isBuffer()) {
            callback(new gutil.PluginError('pbjs', 'unsupported'));
        }

        protobuf.parse(file.contents, root, options);

        callback();
    }

    function gen_output(callback) {
        var target = targets[options.target];
        target(root, options, function(err, result) {
            if (err) {
                callback(err);
github cloudstateio / cloudstate / src / node-support / src / entity.js View on Github external
persistenceId: "entity",
        snapshotEvery: 100,
        includeDirs: ["."],
        //defaults: false, (default)
        //arrays: false, (default)
        //bytes: "Buffer" (default)
      },
      ...options
    };

    const allIncludeDirs = [
      path.resolve(__dirname, "..", "proto"),
      path.resolve(__dirname, "..", "protoc", "include")
    ].concat(this.options.includeDirs);

    this.root = new protobuf.Root();
    this.root.resolvePath = function (origin, target) {
      for (let i = 0; i < allIncludeDirs.length; i++) {
        const directory = allIncludeDirs[i];
        const fullPath = path.resolve(directory, target);
        try {
          fs.accessSync(fullPath, fs.constants.R_OK);
          return fullPath;
        } catch (err) {
        }
      }
      return null;
    };

    this.root.loadSync(desc);
    this.root.resolveAll();
github googleapis / nodejs-datastore / src / entity.ts View on Github external
loadProtos_() {
      const root = new Protobuf.Root();
      const loadedRoot = root.loadSync(
        path.join(__dirname, '..', 'protos', 'app_engine_key.proto')
      );
      loadedRoot.resolveAll();
      return loadedRoot.nested;
    }
github grpc / grpc-node / packages / proto-loader / src / index.ts View on Github external
export function loadSync(
  filename: string | string[],
  options?: Options
): PackageDefinition {
  const root: Protobuf.Root = new Protobuf.Root();
  options = options || {};
  if (!!options.includeDirs) {
    if (!Array.isArray(options.includeDirs)) {
      throw new Error('The includeDirs option must be an array');
    }
    addIncludePathResolver(root, options.includeDirs as string[]);
  }
  const loadedRoot = root.loadSync(filename, options);
  loadedRoot.resolveAll();
  return createPackageDefinition(root, options!);
}