mirror of
https://github.com/protobufjs/protobuf.js.git
synced 2026-01-25 16:43:02 +00:00
20 lines
550 B
JavaScript
20 lines
550 B
JavaScript
"use strict";
|
|
module.exports = json_module;
|
|
|
|
var util = require("../util");
|
|
|
|
json_module.description = "JSON representation as a module"
|
|
|
|
function json_module(root, options, callback) {
|
|
try {
|
|
var output = "var $root = protobuf.Root.fromJSON(" + JSON.stringify(root, null, 2).replace(/^(?!$)/mg, " ").trim() + ").resolveAll();";
|
|
output = util.wrap(output, options);
|
|
process.nextTick(function() {
|
|
callback(null, output);
|
|
});
|
|
} catch (e) {
|
|
return callback(e);
|
|
}
|
|
return undefined;
|
|
}
|