Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / node_modules / protobufjs / cli / pbjs / sources / binary.js
diff --git a/legacy-libs/grpc/node_modules/protobufjs/cli/pbjs/sources/binary.js b/legacy-libs/grpc/node_modules/protobufjs/cli/pbjs/sources/binary.js
new file mode 100644 (file)
index 0000000..2eb64c9
--- /dev/null
@@ -0,0 +1,130 @@
+/*\r
+ Copyright 2013 Daniel Wirtz <dcode@dcode.io>\r
+\r
+ Licensed under the Apache License, Version 2.0 (the "License");\r
+ you may not use this file except in compliance with the License.\r
+ You may obtain a copy of the License at\r
+\r
+ http://www.apache.org/licenses/LICENSE-2.0\r
+\r
+ Unless required by applicable law or agreed to in writing, software\r
+ distributed under the License is distributed on an "AS IS" BASIS,\r
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
+ See the License for the specific language governing permissions and\r
+ limitations under the License.\r
+ */\r
+var description = "Binary descriptor set";\r
+\r
+var ProtoBuf = require(__dirname+"/../../../index.js"),\r
+    util = require(__dirname+"/../util.js"),\r
+    node_path = require("path"),\r
+    fs = require("fs");\r
+\r
+/**\r
+ * pbjs source: Binary descriptor\r
+ * @exports pbjs/sources/binary\r
+ * @function\r
+ * @param {!Array.<string>} filenames Source files\r
+ * @param {!Object.<string,*>=} options Options\r
+ * @returns {!ProtoBuf.Builder}\r
+ */\r
+var binary = module.exports = function(filenames, options) {\r
+    options = options || [];\r
+    var builder = ProtoBuf.newBuilder(util.getBuilderOptions(options, "using")),\r
+        loaded = [];\r
+    filenames.forEach(function(filename) {\r
+        var data = binary.load(filename, options, loaded);\r
+        builder["import"](data, filename);\r
+    });\r
+    builder.resolveAll();\r
+    return builder;\r
+};\r
+\r
+/**\r
+ * Module description.\r
+ * @type {string}\r
+ */\r
+binary.description = description;\r
+\r
+binary.exclude = true; // Unfinished\r
+\r
+/**\r
+ * Loads a binary descriptor.\r
+ * @param {string} filename Source file\r
+ * @param {!Object.<string,*>} options Options\r
+ * @param {!Array.<string>=} loaded An array of already loaded filenames\r
+ * @returns {*} JSON descriptor\r
+ */\r
+binary.load = function(filename, options, loaded) {\r
+    filename = node_path.resolve(filename);\r
+    loaded = loaded || [];\r
+    if (loaded.indexOf(filename) >= 0)\r
+        return {};\r
+    var data = fs.readFileSync(filename);\r
+    loaded.push(filename);\r
+    var builder = ProtoBuf.loadProtoFile(node_path.join("..", "..", "..", "src", "google", "protobuf", "descriptor.proto")),\r
+        FileDescriptorSet = builder.build("google.protobuf.FileDescriptorSet");\r
+    var fds = FileDescriptorSet.decode(data),\r
+        imports = [];\r
+    var json = {\r
+        "package": null,\r
+        "imports": imports\r
+    };\r
+    fds.file.forEach(function(fdp) {\r
+        imports.push(buildFileDescriptorProto(fdp));\r
+    });\r
+    return json;\r
+};\r
+\r
+function buildFileDescriptorProto(fdp) {\r
+    var pkg = fdp.package,\r
+        messages = [],\r
+        enums = [],\r
+        services = [],\r
+        extensions = [],\r
+        options = {},\r
+        imports = [];\r
+    fdp.message_type.forEach(function(dp) {\r
+        messages.push(buildMessageDescriptorProto(dp));\r
+    });\r
+    fdp.enum_type.forEach(function(edp) {\r
+        enums.push(buildEnumDescriptorProto(edp));\r
+    });\r
+    fdp.service.forEach(function(sdp) {\r
+        enums.push(buildServiceDescriptorProto(sdp));\r
+    });\r
+    fdp.extension.forEach(function(fdp) {\r
+        extensions.push(buildFieldDescriptorProtoAsExtension(fdp));\r
+    });\r
+    fdp.options.forEach(function(fo) {\r
+        // TODO\r
+    });\r
+    fdp.dependency.forEach(function(filename) {\r
+        // TODO\r
+    });\r
+    return {\r
+        "package": pkg,\r
+        "messages": messages,\r
+        "enums": enums,\r
+        "services": services,\r
+        "extensions": extensions,\r
+        "options": options,\r
+        "imports": imports\r
+    };\r
+}\r
+\r
+function buildMessageDescriptorProto(mdp) {\r
+\r
+}\r
+\r
+function buildEnumDescriptorProto(edp) {\r
+\r
+}\r
+\r
+function buildServiceDescriptorProto(sdp) {\r
+\r
+}\r
+\r
+function buildFieldDescriptorProtoAsExtension(fdp) {\r
+\r
+}
\ No newline at end of file