How to use the protobufjs.util 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 MatthieuLemoine / push-receiver / src / gcm / index.js View on Github external
const path = require('path');
const request = require('../utils/request');
const protobuf = require('protobufjs');
const Long = require('long');
const { waitFor } = require('../utils/timeout');
const fcmKey = require('../fcm/server-key');
const { toBase64 } = require('../utils/base64');

// Hack to fix PHONE_REGISTRATION_ERROR #17 when bundled with webpack
// https://github.com/dcodeIO/protobuf.js#browserify-integration
protobuf.util.Long = Long
protobuf.configure()

const serverKey = toBase64(Buffer.from(fcmKey));

const REGISTER_URL = 'https://android.clients.google.com/c2dm/register3';
const CHECKIN_URL = 'https://android.clients.google.com/checkin';

let root;
let AndroidCheckinResponse;

module.exports = {
  register,
  checkIn,
};

async function register(appId) {
github googleapis / nodejs-proto-files / src / load.ts View on Github external
// Fully qualified paths don't need to be resolved.
    if (path.isAbsolute(includePath)) {
      return includePath;
    }

    const fullIncludePath = path.join(
      __dirname,
      path.relative(__dirname, includePath)
    );
    const commonProtoFiles = GoogleProtoFilesRoot.getCommonProtoFiles();

    if (commonProtoFiles.indexOf(fullIncludePath) > -1) {
      return fullIncludePath;
    }

    return protobuf.util.path.resolve(_, includePath, alreadyNormalized);
  }
}
github RiseVision / rise-node / packages / core-p2p / src / helpers / protobuf.ts View on Github external
public decode(
    data: Buffer,
    namespace: string,
    messageType?: string
  ): T {
    const message = this.getMessageInstance(namespace, messageType);
    if (message !== null) {
      try {
        return message.decode(data) as any;
      } catch (e) {
        if (e instanceof protobuf.util.ProtocolError) {
          // e.instance holds the so far decoded message with missing required fields
          throw new Error(`ProtoBuf Protocol Error ${e.message}`);
        } else {
          // wire format is invalid
          throw new Error(`ProtoBuf Wire format invalid ${e.message}`);
        }
      }
    }
    throw new Error('ProtoBuf Message missing');
  }
github nebulasio / go-nebulas / cmd / console / neb.js / lib / transaction.js View on Github external
fromProto: function (data) {

        var txBuffer;
        if (utils.isString(data)) {
            txBuffer = new Array(protobuf.util.base64.length(data));
            protobuf.util.base64.decode(data, txBuffer, 0);
        } else {
            txBuffer = data;
        }

        var TransactionProto = root.lookup("corepb.Transaction");
        var txProto = TransactionProto.decode(txBuffer);

        this.hash = cryptoUtils.toBuffer(txProto.hash);
        this.from = account.fromAddress(txProto.from);
        this.to = account.fromAddress(txProto.to);
        this.value = utils.toBigNumber("0x" + cryptoUtils.toBuffer(txProto.value).toString("hex"));
        // long number is object, should convert to int
        this.nonce = parseInt(txProto.nonce.toString());
        this.timestamp = parseInt(txProto.timestamp.toString());
        this.data = txProto.data;
github auth0 / node-baas / messages / decoders.js View on Github external
return through2.obj(function(chunk, enc, callback) {
        var chunk = protobuf.util.Buffer.from(chunk);
        buff = buff ? protobuf.util.Buffer.concat([buff, chunk]) : chunk;
        var reader = protobuf.Reader.create(buff);
        var decoded;
        while (reader.pos < reader.len) {
            try {
                decoded = Message.decodeDelimited(reader);
            } catch (err) {
                this.emit('error', err);
            }
            if (!decoded) {
                break;
            }
            this.push(decoded);
        }
        buff = buff.slice(reader.pos);
        callback();
    });
github nebulasio / go-nebulas / cmd / console / neb.js / lib / transaction.js View on Github external
toProtoString: function () {
        var txBuffer = this.toProto();
        return protobuf.util.base64.encode(txBuffer, 0, txBuffer.length);
    },
github wallix / datapeps-sdk-js / src / DataPeps.ts View on Github external
import * as Long from "long";
import * as protobufjs from "protobufjs";
import * as HTTP from "./HTTP";

export {
  Error,
  ErrorKind,
  ServerKind as ServerError,
  SDKKind as SDKError
} from "./Error";

protobufjs.util.Long = Long;
protobufjs.configure();

/**
 * Configure the endpoint of the SDK.
 * @param APIUrl The url of the DataPeps service.
 */
export function configure(APIUrl: string, WSUrl?: string) {
  HTTP.configure(APIUrl);
}

export * from "./Register";
export * from "./ID";
export * from "./Session";
export * from "./DelegatedAccess";
export * from "./IdentityAPI";
export * from "./ResourceAPI";
github wallix / datapeps-sdk-js / src / Register.ts View on Github external
import * as protobufjs from "protobufjs";
import { api } from "./proto";
import { Base64, Uint8Tool } from "./Tools";
import * as HTTP from "./HTTP";

import { IdentityFields } from "./IdentityAPI";
import { IdentityKeySet } from "./IdentityKeySet";
import { IdentityKeySetAPI } from "./IdentityKeySetAPI";
export {
  Error,
  ErrorKind,
  ServerKind as ServerError,
  SDKKind as SDKError
} from "./Error";

protobufjs.util.Long = Long;
protobufjs.configure();

/**
 * Register a new DataPeps identity.
 * @param identity The description of the identity to register.
 *  The login MUST be a peps email address, i.e. @
 * @param secret The secret of the identity.
 * @return(p) a promise that rejects with an {@link Error} with kind
 * - `IdentityInvalidLogin` if identity.login is not a valid login.
 * - `IdentityAlreadyExists` if identity.login already exists.
 */
export async function register(
  identity: IdentityFields,
  secret: string | Uint8Array
): Promise {
  return await _register("/api/v1/register", identity, secret, r =>
github Leo501 / CocosCreatorTutorial / protubuf / ProtoBufDemo / assets / Script / proto / proto.js View on Github external
Skill.prototype.toJSON = function toJSON() {
                return this.constructor.toObject(this, $protobuf.util.toJSONOptions);
            };
github wallix / datapeps-sdk-js / src / Register.js View on Github external
} catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
        if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
    }
};
Object.defineProperty(exports, "__esModule", { value: true });
var Long = require("long");
var protobufjs = require("protobufjs");
var proto_1 = require("./proto");
var Tools_1 = require("./Tools");
var HTTP = require("./HTTP");
var IdentityKeySetAPI_1 = require("./IdentityKeySetAPI");
var Error_1 = require("./Error");
exports.Error = Error_1.Error;
exports.ServerError = Error_1.ServerKind;
exports.SDKError = Error_1.SDKKind;
protobufjs.util.Long = Long;
protobufjs.configure();
/**
 * Register a new DataPeps identity.
 * @param identity The description of the identity to register.
 *  The login MUST be a peps email address, i.e. @
 * @param secret The secret of the identity.
 * @return(p) a promise that rejects with an {@link Error} with kind
 * - `IdentityInvalidLogin` if identity.login is not a valid login.
 * - `IdentityAlreadyExists` if identity.login already exists.
 */
function register(identity, secret) {
    return __awaiter(this, void 0, void 0, function () {
        return __generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, _register("/api/v1/register", identity, secret, function (r) {
                        return proto_1.api.IdentityRegisterRequest.encode(r).finish();