How to use the protobufjs.newBuilder 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 NUbots / NUsight / tests / robot_simulator / RobotSimulator.js View on Github external
function RobotSimulator (opts) {
	opts = opts || {};

	if (opts.net) {
		this.net = opts.net
	}else {
		this.net = 	new NUClearNet();
		this.net.connect({
			name: this.constructor.name,
			address: '10.1.255.255' // TODO: (Josephus/Trent) Remove hardcoded address after RoboCup 2017
		});
	}

	this.protoBuilder = opts.protoBuilder || ProtoBuf.newBuilder({ convertFieldsToCamelCase: true });

	// A map of message types to callback functions which will be called
	// when a message of the type is received
	this.listenerCallbacks = {};

	// Holds the proto messages that have been loaded, to be used
	// for decoding messages
	this.protos = {};
}
github odota / core / js_parser / parser-async.js View on Github external
var path = require('path');
//Long.js, handle 64 bit types
var Long = require('long');
//https://github.com/dcodeIO/ByteBuffer.js, read types out of binary data
var ByteBuffer = require("bytebuffer");
//decompress with snappy
var snappy = require('snappy');
//emit events with events
var events = require('events');
var async = require('async');
//-
//TODO
//need to construct stringtables
//need to construct sendtables
//read the protobufs and build a dota object for reference
var builder = ProtoBuf.newBuilder();
ProtoBuf.loadProtoFile(path.join(__dirname, './proto/base_gcmessages.proto'), builder);
ProtoBuf.loadProtoFile(path.join(__dirname, './proto/gcsdk_gcmessages.proto'), builder);
ProtoBuf.loadProtoFile(path.join(__dirname, './proto/dota_gcmessages_client.proto'), builder);
ProtoBuf.loadProtoFile(path.join(__dirname, './proto/demo.proto'), builder);
var dota = builder.build();
//console.log(dota);
//-
var inStream = process.stdin;
var stop = false;
var count = 0;
inStream.once('readable', function() {
    async.series({
        "header": function(cb) {
            readString(8, function(err, header) {
                cb(err || header.toString() !== "PBDEMS2\0", header);
            });
github kts-dev / kts-node / lib / proto.js View on Github external
'use strict';

const path = require('path');
const protoBuf = require('protobufjs');
const Long = protoBuf.Long;

var builder = protoBuf.newBuilder();
protoBuf.loadProtoFile(path.join(__dirname, '../proto/base.proto'));
protoBuf.loadProtoFile(path.join(__dirname, '../proto/filter.proto'), builder);
protoBuf.loadProtoFile(path.join(__dirname, '../proto/table.proto'), builder);
const Pb = builder.build('com.kingsoft.services.table.proto');
const utils = require('./base.js').utils;
const Encoder = require('./base.js').Encoder;
const Decoder = require('./base.js').Decoder;
const filter = require('./filter.js');

exports.checkResponse = function(pb) {
  if (pb.code !== Pb.Code.kOk) {
    throw utils.newError(pb.code, Decoder.code(pb.code), pb.msg);
  }
};

exports.CreateTable = {
github odota / rapier / generateTypes.js View on Github external
/**
 * Generates a mapping of ids to protobuf message names
 **/
var ProtoBuf = require('protobufjs');
var builder = ProtoBuf.newBuilder();
ProtoBuf.loadJsonFile("./build/protos.json", builder);
var dota = builder.build();
//maintain a mapping for PacketTypes of id to string so we can emit events for different packet types.
//we want to generate them automatically from the protobufs
var packetEnums = {
    "NET_Messages": {
        abbr: "net_",
        full: "CNETMsg_"
    },
    "SVC_Messages": {
        abbr: "svc_",
        full: "CSVCMsg_"
    },
    "EBaseUserMessages": {
        abbr: "UM_",
        full: "CUserMessage"
github protobufjs / protobuf.js / examples / protoify / json.js View on Github external
module.exports = require("protobufjs").newBuilder({})["import"]({
    "package": "js",
    "messages": [
        {
            "name": "Value",
            "fields": [
                {
                    "rule": "optional",
                    "options": {},
                    "type": "sint32",
                    "name": "integer",
                    "id": 1,
                    "oneof": "type"
                },
                {
                    "rule": "optional",
                    "options": {},
github seishun / node-steam-resources / index.js View on Github external
function loadProtoFiles(paths) {
  var builder = ProtoBuf.newBuilder();
  paths.forEach(function(path) {
    ProtoBuf.loadProtoFile(__dirname + '/protobufs/' + path, builder);
  });
  return builder.build();
}
github DoctorMcKay / node-steam-tradeoffer-manager / lib / webapi.js View on Github external
var TradeOfferManager = require('./index.js');
var Protobuf = require('protobufjs');

var EResult = require('../resources/EResult.js');

var builder = Protobuf.newBuilder();
Protobuf.loadProtoFile(__dirname + '/../resources/tradeoffers.proto', builder);
var Protos = builder.build();

TradeOfferManager.prototype._apiCall = function(httpMethod, method, version, input, callback) {
	var iface = 'IEconService';
	if(typeof method === 'object') {
		iface = method.iface;
		method = method.method;
	}
	
	var options = {
		"uri": "https://api.steampowered.com/" + iface + "/" + method + "/v" + version + "/",
		"json": true,
		"method": httpMethod
	};
github aliyun-UED / aliyun-sdk-js / lib / services / ots.js View on Github external
initialize: function initialize(options) {
    var builder = ProtoBuf.newBuilder();
    builder.define("ots2");
    builder.create(
        [
          {
            "name": "Error",
            "fields": [
              {
                "rule": "required",
                "type": "string",
                "name": "code",
                "id": 1
              },
              {
                "rule": "optional",
                "type": "string",
                "name": "message",
github getyoti / yoti-node-sdk / src / proto-root / init.js View on Github external
function initProtoBufBuilder() {
  const builder = ProtoBuf.newBuilder({ convertFieldsToCamelCase: true });
  const attributeListPath = serverConfig.CORE_ATTRIBUTE_LIST_PROTO_BUFF_PATH;
  const encryptedData = serverConfig.CORE_ENCRYPTED_DATA_PROTO_BUFF_PATH;
  const signedTimeStampStructure = serverConfig.CORE_SIGNED_TIMESTAMP_PROTO__BUFF_PATH;

  const extraDataStructure = serverConfig.CORE_EXTRA_DATA_PROTO_BUFF_PATH;
  const dataEntryStructure = serverConfig.CORE_DATA_ENTRY_PROTO_BUFF_PATH;
  const issuingAttributesStructure = serverConfig.CORE_ISSUING_ATTRIBUTES_PROTO_BUFF_PATH;
  const thirdPartyAttributeStructure = serverConfig.CORE_THIRD_PARTY_ATTRIBUTE_PROTO_BUFF_PATH;

  ProtoBuf.loadProtoFile(attributeListPath, builder);
  ProtoBuf.loadProtoFile(encryptedData, builder);
  ProtoBuf.loadProtoFile(signedTimeStampStructure, builder);

  ProtoBuf.loadProtoFile(extraDataStructure, builder);
  ProtoBuf.loadProtoFile(dataEntryStructure, builder);
  ProtoBuf.loadProtoFile(thirdPartyAttributeStructure, builder);
github MobilityData / gtfs-realtime-bindings / nodejs / gtfs-realtime.js View on Github external
/**
 * Copyright 2015 Google Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *   http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
module.exports = require("protobufjs").newBuilder().import({
    "package": "transit_realtime",
    "messages": [
        {
            "name": "FeedMessage",
            "fields": [
                {
                    "rule": "required",
                    "type": "FeedHeader",
                    "name": "header",
                    "id": 1,
                    "options": {}
                },
                {
                    "rule": "repeated",
                    "type": "FeedEntity",
                    "name": "entity",