How to use the Root function from protobufjs

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

-2
-1

module.exports = protos.POGOProtos;
fork icon8
star icon9
watch icon6

+ 11 other calls in file

130
131
132
133
134
135
136
137
138
139
  const match = line.match(/(?:import "([^"]*)";|file:(.*proto),)/);
  return !match || protos.indexOf(match[1] || match[2]) >= 0;
}).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) => {
fork icon4
star icon3
watch icon4

+ 17 other calls in file

13
14
15
16
17
18
19
20
21
22
```


``` javascript
const protobuf = require('protobufjs');
const root = protobuf.Root.fromJSON(require('bundle.json'));

const AwesomeMessage = root.lookup('awesomepackage.AwesomeMessage');
var message = {
    id: 1,
fork icon2
star icon8
watch icon3

+ 3 other calls in file

6
7
8
9
10
11
12
13
14
15
const converter = require('./lib/converter');
const parse = require('./lib/parse');
const protobuf = require('protobufjs');
const common = protobuf.common;
const Type = protobuf.Type;
const Root = protobuf.Root;
const Reader = protobuf.Reader;
const Writer = protobuf.Writer;
const util = protobuf.util;
const verifier = protobuf.verifier;
fork icon1
star icon3
watch icon15

+ 14 other calls in file

20
21
22
23
24
25
26
27
28
29
const jsonTarget = require('./node_modules/protobufjs/cli/targets/json')

const path = require('path')
const fs = require('fs')

let root = new protobuf.Root()

let files = fs.readdirSync('./protos')
  .map(f => path.resolve('./protos', f))
  .filter(f => f.endsWith('.proto'))
fork icon42
star icon0
watch icon2

+ 9 other calls in file

140
141
142
143
144
145
146
147
148
149
 */
this.requestId = 1000; // 请求序列号,自增

this.isHandStop = false;

this.root = protobufjs.Root.fromJSON(Pb);

this.cacheResponseCallback = {}; // 缓存的回调函数
this.cacheNotifyCallback = {}; // 缓存的通知回调函数
this.header = null; // 缓存接收的数据包头
fork icon13
star icon56
watch icon5

+ 5 other calls in file

2
3
4
5
6
7
8
9
10
11
12
13
const protobuf = require('protobufjs');
const fs = require('fs');
const protoFilePath = '../../config/pbconfig/';
const path = require('path');


const root = protobuf.Root.fromJSON(require("../../config/pbconfig/protobufConfig.json"));
const payloaddecode = require('../utils/payloadDecode')


const opt = require("../../config/config.js").logger;
const createLogger=require('../logs/logger')
fork icon1
star icon0
watch icon0

-2
fork icon1
star icon0
watch icon3

+ 11 other calls in file

58
59
60
61
62
63
64
65
66
67
const protoToSchema = (
  protoPaths,
  schemaIdPrefix = DEFAULT_SCHEMA_ID_PREFIX,
  schemaIdSuffix = DEFAULT_SCHEMA_ID_SUFFIX,
) => {
  const root = new protobufjs.Root();
  const protoSchema = (protobufjs.loadSync(protoPaths, root)).resolveAll();
  const definitions = recursive(protoSchema, {}, '', schemaIdPrefix, schemaIdSuffix);
  return Object.keys(definitions).map(k => ({
    $id: `${schemaIdPrefix}${k}${schemaIdSuffix}`,
fork icon0
star icon3
watch icon2

+ 15 other calls in file

697
698
699
700
701
702
703
704
705
706
Object.defineProperty(exports, "__esModule", { value: true });
var pb = require("protobufjs");
var Protos = /** @class */ (function () {
    function Protos() {
        var _this = this;
        var root = new pb.Root({
            root: "/proto3 versions",
        });
        root.resolvePath = function (origin, file) {
            var str = this.options.root + "/" + file;
fork icon1
star icon0
watch icon0

+ 2 other calls in file

20
21
22
23
24
25
26
27
28
29
exports.loadRoot = async () => {
  const protosPath = path.join(__dirname, '../protos');
  const protos = await readdir(protosPath).then(files =>
    files.map(name => path.join(protosPath, name)),
  );
  const root = new Root();
  return root.load(protos, { keepCase: true });
};

/**
fork icon1
star icon0
watch icon5

2585
2586
2587
2588
2589
2590
2591
2592
2593
2594
 * @see {@link Root#load}
 */
function load(filename, root, callback) {
    if (typeof root === "function") {
        callback = root;
        root = new protobuf.Root();
    } else if (!root)
        root = new protobuf.Root();
    return root.load(filename, callback);
}
fork icon0
star icon1
watch icon0

+ 8 other calls in file

46
47
48
49
50
51
52
53
54
55
    const className = titleify(enumName) + 'Action';
    return _.set(map, key, { enum: enumName, name: className });
}, {});

// Compile Protobufs
const root = protobuf.Root.fromJSON(protoJson);
const SCPayload = root.lookup('SCPayload');
const PropertyValue = root.lookup('PropertyValue');
const PropertySchema = root.lookup('PropertySchema');
const Location = root.lookup('Location');
fork icon0
star icon1
watch icon3

14
15
16
17
18
19
20
21
22
23
});

const mult = 32;
const sizes = { json: 0, compactr: 0, protobuf: 0 };

let root = protobuf.Root.fromJSON({
  nested: {
    IntBenchTest: {
      fields: {
        id: { type: 'uint32', id: 1 },
fork icon6
star icon99
watch icon8

+ 3 other calls in file

6
7
8
9
10
11
12
13
14
15
16
17
let isTs = true;


var Service = protobufjs.Service,
    Enum = protobufjs.Enum,
    Namespace = protobufjs.Namespace,
    Root = protobufjs.Root;


const option = {
    alternateCommentMode: true,
};
fork icon0
star icon0
watch icon1

+ 59 other calls in file

12
13
14
15
16
17
18
19
20
21
22
    int32 age = 2;
  }
`;


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