Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / protobufjs / ext / descriptor / test.js
1 /*eslint-disable no-console*/
2 "use strict";
3 var protobuf   = require("../../"),
4     descriptor = require(".");
5
6 /* var proto = {
7     nested: {
8         Message: {
9             fields: {
10                 foo: {
11                     type: "string",
12                     id: 1
13                 }
14             },
15             nested: {
16                 SubMessage: {
17                     fields: {}
18                 }
19             }
20         },
21         Enum: {
22             values: {
23                 ONE: 1,
24                 TWO: 2
25             }
26         }
27     }
28 }; */
29
30 // var root = protobuf.Root.fromJSON(proto).resolveAll();
31 var root = protobuf.loadSync("tests/data/google/protobuf/descriptor.proto").resolveAll();
32
33 // console.log("Original proto", JSON.stringify(root, null, 2));
34
35 var msg  = root.toDescriptor();
36
37 // console.log("\nDescriptor", JSON.stringify(msg.toObject(), null, 2));
38
39 var buf  = descriptor.FileDescriptorSet.encode(msg).finish();
40 var root2 = protobuf.Root.fromDescriptor(buf, "proto2").resolveAll();
41
42 // console.log("\nDecoded proto", JSON.stringify(root2, null, 2));
43
44 var diff = require("deep-diff").diff(root.toJSON(), root2.toJSON());
45 if (diff) {
46     diff.forEach(function(diff) {
47         console.log(diff.kind + " @ " + diff.path.join("."));
48         console.log("lhs:", typeof diff.lhs, diff.lhs);
49         console.log("rhs:", typeof diff.rhs, diff.rhs);
50         console.log();
51     });
52     process.exitCode = 1;
53 } else
54     console.log("no differences");