How to use the parse function from protobufjs

Find comprehensive JavaScript protobufjs.parse code examples handpicked from public code repositorys.

44
45
46
47
48
49
50
51
52
53

describe('Protobuf encoding', function () {
    var expectedArray = [0x0a, 0x0d, 0x41, 0x77, 0x65, 0x73, 0x6f, 0x6d, 0x65, 0x53, 0x74, 0x72, 0x69, 0x6e, 0x67];
    var expectedBuffer = Buffer.from(expectedArray);
    it("Encodes a proto message", function () {
        root = protobuf.parse(myMsg).root;

        // Obtain a message type
        var AwesomeMessage = root.lookupType(".awesomepackage.AwesomeMessage");
        var payload = { awesomeField: "AwesomeString" };
fork icon26
star icon15
watch icon16

+ 24 other calls in file

0
1
2
3
4
5
6
7
8
9
10
11
12
// 该文件来自:https://github.com/dcodeIO/protobuf.js/blob/master/src/parse.js
// 查找自定义代码请搜索字符串:"CHANGED"


const protobuf = require('protobufjs');


const parse = protobuf.parse;


parse.filename = null;
parse.defaults = {keepCase: false};

fork icon6
star icon8
watch icon0

+ 3 other calls in file

132
133
134
135
136
137
138
139
140
141
}).join('\n');

// 编译pbjs
const root = new protobuf.Root();
root.loadSync(path.resolve(__dirname, './proto/dzhua.proto'));
const parsed = protobuf.parse(msgContent, root);
if (parsed.imports) {
  parsed.imports.forEach((name) => {
    const absolutePath = path.resolve(__dirname, './proto', name);
    root.loadSync(absolutePath);
fork icon4
star icon3
watch icon4

+ 17 other calls in file

3
4
5
6
7
8
9
10
11
const _ = require('lodash');

describe('message-generator', () => {

  it('should generate a message', () => {
    const givenProto = protobuf.parse(`
      syntax = "proto3";

      package a.test;
fork icon1
star icon0
watch icon65

+ 31 other calls in file

832
833
834
835
836
837
838
839
840
841
 * Create gRPC client stib
 * @param {Object} options from gRPC client
 */
module.exports.grpcQuery = async (options) => {
    const { grpcUrl, grpcProtobufData, grpcServiceName, grpcEnableTls, grpcMethod, grpcBody } = options;
    const protocObject = protojs.parse(grpcProtobufData);
    const protoServiceObject = protocObject.root.lookupService(grpcServiceName);
    const Client = grpc.makeGenericClientConstructor({});
    const credentials = grpcEnableTls ? grpc.credentials.createSsl() : grpc.credentials.createInsecure();
    const client = new Client(
fork icon0
star icon0
watch icon3

+ 3 other calls in file

14
15
16
17
18
19
20
21
22
23
24
25
`;


// Create a Root instance to hold the schema
const root = protobuf.Root.fromJSON({
  nested: {
    Person: protobuf.parse(personSchema).root.lookupType('Person'),
  },
});


// Create a new message object and set its fields
fork icon0
star icon0
watch icon0

94
95
96
97
98
99
100
101
102
103
  const foreignKey = table.foreignKeys.find((fk) => fk.columnNames.indexOf(columnName) !== -1);
  await queryRunner.dropForeignKey(tableName, foreignKey);
}

export async function getServiceAndRpcNames(protoDefinition) {
  const root = protobuf.parse(protoDefinition).root;
  const serviceNamesAndMethods = root.nestedArray
    .filter((item) => item instanceof protobuf.Service)
    .reduce((acc, service) => {
      const rpcMethods = service.methodsArray.map((method) => method.name);
fork icon0
star icon0
watch icon147