Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
module.exports = function (proto, opts) {
if (!opts) opts = {}
if (!proto) throw new Error('Pass in a .proto string or a protobuf-schema parsed object')
var sch = (typeof proto === 'object' && !Buffer.isBuffer(proto)) ? proto : schema.parse(proto)
// to not make toString,toJSON enumarable we make a fire-and-forget prototype
var Messages = function () {
var self = this
compile(sch, opts.encodings || {}).forEach(function (m) {
self[m.name] = flatten(m.values) || m
})
}
Messages.prototype.toString = function () {
return schema.stringify(sch)
}
Messages.prototype.toJSON = function () {
return sch
DecodeSuite.prototype.__pbf = function (args) {
var parts = args.split(':');
var proto = pbSchema.parse(fs.readFileSync(parts[0]));
var message = pbCompile(proto)[parts[1]];
var pbf = new Pbf();
message.write(this.getValue(true), pbf);
var buf = pbf.finish();
return function () {
var obj = message.read(new Pbf(buf));
if (obj.$) {
throw new Error();
}
};
};
export function parseSchema(contents: string): ParsedSchema {
const schema = parser.parse(contents);
return {
compile(): any {
const result = {};
new Function('exports', generate(schema))(result);
return result;
},
toJavaScript({ es6 }: JsOptions = {}): string {
return generate(schema, { es6 });
},
toTypeScript(): string {
return generate(schema, { typescript: true });
},
};
.map(p => schema.parse(fs.readFileSync(p)))
.forEach((sch, si) => {
.map(p => schema.parse(fs.readFileSync(p)))
.forEach((sch, si) => {