How to use the protobufjs.parse 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 / sandbox / Standalone.js View on Github external
generate_service_spec_json() {
    try {
        const protobuf = require("protobufjs");
        protobuf.parse.defaults.keepCase = true;
        let obj = protobuf.parse(this.state.proto)
        this.serviceSpecJSON = obj.root; 
        this.protoSpec = new GRPCProtoV3Spec(this.serviceSpecJSON);
        this.onOpenJobDetailsSlider();
    }
    catch(ex) {
        this.setState({errorMessage: "Exception while parsing proto [" + ex + "]"});
        console.log("Unable to generate service spec json. Please ensure that " + this.proto + " is a valid proto file")
        console.log(ex)
    }
}
github mtth / avsc / etc / benchmarks / js-serialization-libraries / index.js View on Github external
DecodeSuite.prototype.__protobufjs = function (args) {
  var parts = args.split(':');
  var root = protobufjs.parse(fs.readFileSync(parts[0])).root;
  var message = root.lookup(parts[1]);
  var buf = message.encode(this.getValue(true)).finish();
  return function () {
    var obj = message.decode(buf);
    if (obj.$) {
      throw new Error();
    }
  };
};
github Cirrus-Link / Sparkplug / client_libraries / javascript / sparkplug-payload / lib / kurapayload.js View on Github external
(function () {
    var ProtoBuf = require("protobufjs");

    var Root = ProtoBuf.parse("package kuradatatypes; message KuraPayload { message KuraMetric { enum " +
        		"ValueType { DOUBLE = 0; FLOAT = 1; INT64 = 2; INT32 = 3; BOOL = 4; STRING = 5; BYTES = 6; } " +
        		"required string name = 1; required ValueType type = 2; optional double double_value = 3; optional " +
        		"float float_value = 4; optional int64 long_value = 5; optional int32 int_value = 6; optional bool" +
        		" bool_value = 7; optional string string_value = 8; optional bytes bytes_value = 9; } message " +
        		"KuraPosition { required double latitude = 1; required double longitude = 2; optional double altitude" +
        		" = 3; optional double precision = 4; optional double heading = 5; optional double speed = 6; " +
        		"optional int64 timestamp = 7; optional int32 satellites = 8; optional int32 status = 9; } " +
        		"optional int64 timestamp = 1; optional KuraPosition position = 2; extensions 3 to 4999; repeated " +
        		"KuraMetric metric = 5000; optional bytes body = 5001; }").root,
        KuraPayload = Root.lookup('kuradatatypes.KuraPayload'),
        KuraMetric = Root.lookup('kuradatatypes.KuraPayload.KuraMetric'),
        KuraPosition = Root.lookup('kuradatatypes.KuraPayload.KuraPosition'),
        ValueType = KuraMetric.ValueType;

    exports.generateKuraPayload = function(object) {
        var newPayload = KuraPayload.create({
github eclipse / tahu / client_libraries / javascript / sparkplug-payload / lib / sparkplugbpayload.js View on Github external
(function () {
    var ProtoBuf = require("protobufjs");

    var SparkplugPayload = ProtoBuf.parse("package org.eclipse.tahu.protobuf; message Payload { message Template { " +
            "message Parameter { optional string name = 1;optional uint32 type = 2; oneof value { uint32 int_value = 3; uint64 long_value = 4; " +
            "float float_value = 5; double double_value = 6; bool boolean_value = 7; string string_value = 8; ParameterValueExtension extension_value = 9; } " +
            "message ParameterValueExtension { extensions 1 to max; } } optional string version = 1; repeated Metric metrics = 2; " +
            "repeated Parameter parameters = 3; optional string template_ref = 4; optional bool is_definition = 5; extensions 6 to max; } " +
            "message DataSet { " +
            "message DataSetValue { oneof value { uint32 int_value = 1; uint64 long_value = 2; float float_value = 3; double double_value = 4; " +
            "bool boolean_value = 5; string string_value = 6; DataSetValueExtension extension_value = 7; } " +
            "message DataSetValueExtension { extensions 1 to max; } } " +
            "message Row { repeated DataSetValue elements = 1; extensions 2 to max; } optional uint64 num_of_columns = 1; repeated string columns = 2; " +
            "repeated uint32 types = 3; repeated Row rows = 4; extensions 5 to max; } " +
            "message PropertyValue { optional uint32 type = 1; optional bool is_null = 2;  oneof value { uint32 int_value = 3; uint64 long_value = 4; " +
            "float float_value = 5; double double_value = 6; bool boolean_value = 7; string string_value = 8; PropertySet propertyset_value = 9; " +
            "PropertySetList propertysets_value = 10; PropertyValueExtension extension_value = 11; } " +
            "message PropertyValueExtension { extensions 1 to max; } } " +
            "message PropertySet { repeated string keys = 1; repeated PropertyValue values = 2; extensions 3 to max; } " +
            "message PropertySetList { repeated PropertySet propertyset = 1; extensions 2 to max; } " +
github lazada / grpc-ui / ui / src / Dev.tsx View on Github external
oneof test_oneof {
      string option_a = 2;
      int32 option_b = 3;
    }

    string after = 4;
  }

  service SearchService {
    rpc Search (SearchRequest) returns (Empty);
    rpc TestOneOf(OneOfRequest) returns (Empty);
  }
`;

const root = parse(proto).root;
const adapter = new MockAdapter();

root.resolveAll();

const Dev = () =>
  
;

export default Dev;
github GroaJS / groa / lib / loader.js View on Github external
const parseProto = async function(proto) {

	const root = await prepareRoot();

	let parserResult = ProtoBuf.parse(proto, root);
	let def = grpc.loadObject(parserResult.root);

	return {
		root: root,
		services: listServices('', def)
	};
};
github ZeusWPI / MOZAIC / client / gulpfile.js View on Github external
function parse_file(file, enc, callback) {
        if (!file.isBuffer()) {
            callback(new gutil.PluginError('pbjs', 'unsupported'));
        }

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

        callback();
    }
github Ogadai / zwift-mobile-api / src / riderAttributes.js View on Github external
const proto = `syntax=\"proto3\";
    message Attributes {
        int32 f2 = 2;
        int32 f3 = 3;
        message AttributeMessage {
            int32 myId = 1;
            int32 theirId = 2;
            string firstName = 3;
            string lastName = 4;
            int32 countryCode = 5;
        }
        AttributeMessage attributeMessage = 4;
        int32 theirId = 10;
        int32 f13 = 13;
    }`;
const root = protobuf.parse(proto, { keepCase: true }).root;
const Attributes = root.lookup("Attributes");

export function decodeAttributes(buffer) {
    return Attributes.decode(buffer);
};

export function encodeAttributes(attributes) {
    return Attributes.encode(attributes).finish();
}
github plantain-00 / ws-tool / index.ts View on Github external
loadProtobuf() {
    if (this.protobufContent && this.protobufTypePath) {
      try {
        this.protobufType = protobuf.parse(this.protobufContent).root.lookup(this.protobufTypePath) as protobuf.Type
        this.messages.unshift({
          moment: getNow(),
          type: 'tips',
          tips: 'The protobuf definitions is loaded successfully.',
          id: this.id++
        })
      } catch (error) {
        this.messages.unshift({
          moment: getNow(),
          type: 'error',
          reason: error.message,
          id: this.id++
        })
      }
    }
  }