How to use the protobufjs.Root.fromJSON 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 singnet / snet-betav1-dapp / src / components / JobDetails.js View on Github external
var caller = this;
      var stripped = signed.substring(2, signed.length)
      var byteSig = new Buffer(Buffer.from(stripped, 'hex'));
      console.log(byteSig.toString('base64'))
      const byteschannelID = Buffer.alloc(4);
      byteschannelID.writeUInt32BE(this.channelHelper.getChannelId(), 0);

      let requestObject   = ({"channelId":byteschannelID, "signature":byteSig})
      const requestHeaders = {}

      const packageName = 'escrow'
      const serviceName = 'PaymentChannelStateService'
      const methodName = 'GetChannelState'

      const Service = Root.fromJSON(serviceStateJSON).lookup(serviceName);
      const serviceObject = Service.create(rpcImpl(this.channelHelper.getEndpoint(), packageName, serviceName, methodName, requestHeaders), false, false)

      return new Promise(function(resolve, reject) {
        grpcRequest(serviceObject, methodName, requestObject)
        .then(response => {
          if(typeof response.currentSignedAmount !== 'undefined') {
            console.log("Setting currentSignedAmount " + response.currentSignedAmount);
            let buffer = Buffer.from(response.currentSignedAmount);
            const currentSignedAmount = buffer.readUIntBE(0, response.currentSignedAmount.length);
            if(typeof currentSignedAmount !== 'undefined') {
              caller.channelHelper.setCurrentSignedAmount(currentSignedAmount);

              const nonceBuffer = Buffer.from(response.currentNonce);
              caller.channelHelper.setNonce(nonceBuffer.readUIntBE(0, response.currentNonce.length));
              console.log("Nonce " + nonceBuffer.readUIntBE(0, response.currentNonce.length));
            }
github singnet / alpha-dapp / src / components / job.js View on Github external
this.props.agent.contractInstance.validateJobInvocation(this.state.jobAddress, v, r, s, {from: this.props.account}).then(validateJob => {
          console.log('job invocation validation returned: ' + validateJob[0]);

          const requestHeaders = { "snet-job-address": this.state.jobAddress, "snet-job-signature": signature }
          const requestObject = params

          const serviceSpecJSON = Root.fromJSON(this.props.serviceSpec[0])
          const packageName = Object.keys(serviceSpecJSON.nested)
            .find(key =>
              typeof serviceSpecJSON.nested[key] === "object" &&
              hasOwnDefinedProperty(serviceSpecJSON.nested[key], "nested")
            )
 
          if (this.props.serviceEncoding === "json") {
            grpcJSONRequest(this.props.agent.endpoint, packageName, serviceName, methodName, requestHeaders, requestObject)
              .then(response => {
                this.setState(() => ({ "jobResult": response }))
                this.nextJobStep()
              })
              .catch(console.error)
          } else if (this.props.serviceEncoding === "proto") {
            const Service = serviceSpecJSON.lookup(serviceName)
            const serviceObject = Service.create(rpcImpl(this.props.agent.endpoint, packageName, serviceName, methodName, requestHeaders), false, false)
github poetapp / poet-js / src / Serialization / PoetProto.ts View on Github external
import { Root, Type, INamespace } from 'protobufjs'

import * as PoetProto from './Proto.json'

const poetProtoRoot = Root.fromJSON(PoetProto as INamespace)

export const ClaimProto = poetProtoRoot.lookup('Poet.Claim') as Type
export const AttributeProto = poetProtoRoot.lookup('Poet.Attribute') as Type
github apple / turicreate / src / visualization / client / Turi Create Visualization / src / user_interface / src / index.js View on Github external
window.setProtoMessage = function setProtoMessage(value){

    document.getElementById("loading_container").style.display = "none";
    document.getElementById('annotate_viz').style.display = 'block';

    var root = Root.fromJSON(messageFormat);

    const ParcelMessage = root.lookupType("TuriCreate.Annotation.Specification.Parcel");
    const buffer = Uint8Array.from(atob(value), c => c.charCodeAt(0));
    var decoded = ParcelMessage.decode(buffer);

    if (decoded.hasOwnProperty('metadata')) {
        component_rendered = ReactDOM.render(, document.getElementById('annotate_viz'));
        spec_type = SpecType.annotate;
    } else if(decoded.hasOwnProperty('data')) {
        for (var i = 0; i < decoded["data"]["data"].length; i++) {
            const row_index = decoded["data"]["data"][i]["rowIndex"];
            const type = decoded["data"]["data"][i]["images"][0]["type"];
            const data = decoded["data"]["data"][i]["images"][0]["imgData"];

            const width = decoded["data"]["data"][i]["images"][0]["width"];
            const height = decoded["data"]["data"][i]["images"][0]["height"];
github uber / xviz / modules / schema / src / proto-validation.js View on Github external
export function loadProtos() {
  return Root.fromJSON(PROTO_DATA);
}
github apple / turicreate / src / visualization / Turi Create Visualization / src / user_interface / src / elements / Annotate / index.js View on Github external
getHelper = (start, end, type) => {
    const root = Root.fromJSON(messageFormat);
    const ParcelMessage = root.lookupType("TuriCreate.Annotation.Specification.ClientRequest");
    const payload = {"getter": {"type": type, "start": start, "end": end}};
    const err = ParcelMessage.verify(payload);
    if (err)
      throw Error(err);
    
    const message = ParcelMessage.create(payload);
    const buffer = ParcelMessage.encode(message).finish();
    const encoded = btoa(String.fromCharCode.apply(null, buffer));

    if (window.navigator.platform == 'MacIntel') {
      window.webkit.messageHandlers["scriptHandler"].postMessage({status: 'writeProtoBuf', message: encoded});
    } else {
      window.postMessageToNativeClient(encoded);
    }
  }
github singnet / snet-betav1-dapp / src / components / JobDetails.js View on Github external
.then(serviceSpec => new Promise(function(resolve) {
          const serviceSpecJSON = Root.fromJSON(serviceSpec[0]);
          caller.setServiceSpec(serviceSpecJSON)
          resolve();
        }));
    }
github poetapp / frost-api / src / utils / PoetNode / Serialization / PoetProto.ts View on Github external
import { Root, Type, INamespace } from 'protobufjs'

import { PoetProto } from './PoetProtoJson'

const poetProtoRoot = Root.fromJSON(PoetProto as INamespace)

export const ClaimProto = poetProtoRoot.lookup('Poet.Claim') as Type
export const AttributeProto = poetProtoRoot.lookup('Poet.Attribute') as Type
github poetapp / node / src / Serialization / PoetProto.ts View on Github external
import { Root, Type, INamespace } from 'protobufjs'

import * as PoetProto from './PoetProto.json'

const poetProtoRoot = Root.fromJSON(PoetProto as INamespace)

export const ClaimProto = poetProtoRoot.lookup('Poet.Claim') as Type
export const AttributeProto = poetProtoRoot.lookup('Poet.Attribute') as Type