mirror of
https://github.com/hanzoai/protobuf.js.git
synced 2026-09-24 17:02:08 +00:00
27 lines
603 B
TypeScript
27 lines
603 B
TypeScript
import * as protobuf from "../index";
|
|
import textformat = require("../ext/textformat");
|
|
|
|
const root = protobuf.Root.fromJSON({
|
|
nested: {
|
|
Message: {
|
|
fields: {
|
|
value: {
|
|
type: "int32",
|
|
id: 1
|
|
}
|
|
}
|
|
}
|
|
}
|
|
});
|
|
root.resolveAll();
|
|
|
|
const type = root.lookupType("Message");
|
|
textformat.install();
|
|
const message = type.fromText("value: 1");
|
|
const text: string = type.toText(message, { unknowns: true });
|
|
|
|
textformat.unknownRecursionLimit = 10;
|
|
|
|
if (text.length < 0)
|
|
throw Error("unreachable");
|