Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / node_modules / protobufjs / src / protobuf.js
diff --git a/legacy-libs/grpc/node_modules/protobufjs/src/protobuf.js b/legacy-libs/grpc/node_modules/protobufjs/src/protobuf.js
new file mode 100644 (file)
index 0000000..6efc681
--- /dev/null
@@ -0,0 +1,421 @@
+/**\r
+ * The ProtoBuf namespace.\r
+ * @exports ProtoBuf\r
+ * @namespace\r
+ * @expose\r
+ */\r
+var ProtoBuf = {};\r
+\r
+/**\r
+ * @type {!function(new: ByteBuffer, ...[*])}\r
+ * @expose\r
+ */\r
+ProtoBuf.ByteBuffer = ByteBuffer;\r
+\r
+/**\r
+ * @type {?function(new: Long, ...[*])}\r
+ * @expose\r
+ */\r
+ProtoBuf.Long = ByteBuffer.Long || null;\r
+\r
+/**\r
+ * ProtoBuf.js version.\r
+ * @type {string}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.VERSION = "/*?= VERSION */";\r
+\r
+/**\r
+ * Wire types.\r
+ * @type {Object.<string,number>}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.WIRE_TYPES = {};\r
+\r
+/**\r
+ * Varint wire type.\r
+ * @type {number}\r
+ * @expose\r
+ */\r
+ProtoBuf.WIRE_TYPES.VARINT = 0;\r
+\r
+/**\r
+ * Fixed 64 bits wire type.\r
+ * @type {number}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.WIRE_TYPES.BITS64 = 1;\r
+\r
+/**\r
+ * Length delimited wire type.\r
+ * @type {number}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.WIRE_TYPES.LDELIM = 2;\r
+\r
+/**\r
+ * Start group wire type.\r
+ * @type {number}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.WIRE_TYPES.STARTGROUP = 3;\r
+\r
+/**\r
+ * End group wire type.\r
+ * @type {number}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.WIRE_TYPES.ENDGROUP = 4;\r
+\r
+/**\r
+ * Fixed 32 bits wire type.\r
+ * @type {number}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.WIRE_TYPES.BITS32 = 5;\r
+\r
+/**\r
+ * Packable wire types.\r
+ * @type {!Array.<number>}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.PACKABLE_WIRE_TYPES = [\r
+    ProtoBuf.WIRE_TYPES.VARINT,\r
+    ProtoBuf.WIRE_TYPES.BITS64,\r
+    ProtoBuf.WIRE_TYPES.BITS32\r
+];\r
+\r
+/**\r
+ * Types.\r
+ * @dict\r
+ * @type {!Object.<string,{name: string, wireType: number, defaultValue: *}>}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.TYPES = {\r
+    // According to the protobuf spec.\r
+    "int32": {\r
+        name: "int32",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: 0\r
+    },\r
+    "uint32": {\r
+        name: "uint32",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: 0\r
+    },\r
+    "sint32": {\r
+        name: "sint32",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: 0\r
+    },\r
+    "int64": {\r
+        name: "int64",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined\r
+    },\r
+    "uint64": {\r
+        name: "uint64",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined\r
+    },\r
+    "sint64": {\r
+        name: "sint64",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined\r
+    },\r
+    "bool": {\r
+        name: "bool",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: false\r
+    },\r
+    "double": {\r
+        name: "double",\r
+        wireType: ProtoBuf.WIRE_TYPES.BITS64,\r
+        defaultValue: 0\r
+    },\r
+    "string": {\r
+        name: "string",\r
+        wireType: ProtoBuf.WIRE_TYPES.LDELIM,\r
+        defaultValue: ""\r
+    },\r
+    "bytes": {\r
+        name: "bytes",\r
+        wireType: ProtoBuf.WIRE_TYPES.LDELIM,\r
+        defaultValue: null // overridden in the code, must be a unique instance\r
+    },\r
+    "fixed32": {\r
+        name: "fixed32",\r
+        wireType: ProtoBuf.WIRE_TYPES.BITS32,\r
+        defaultValue: 0\r
+    },\r
+    "sfixed32": {\r
+        name: "sfixed32",\r
+        wireType: ProtoBuf.WIRE_TYPES.BITS32,\r
+        defaultValue: 0\r
+    },\r
+    "fixed64": {\r
+        name: "fixed64",\r
+        wireType: ProtoBuf.WIRE_TYPES.BITS64,\r
+        defaultValue:  ProtoBuf.Long ? ProtoBuf.Long.UZERO : undefined\r
+    },\r
+    "sfixed64": {\r
+        name: "sfixed64",\r
+        wireType: ProtoBuf.WIRE_TYPES.BITS64,\r
+        defaultValue: ProtoBuf.Long ? ProtoBuf.Long.ZERO : undefined\r
+    },\r
+    "float": {\r
+        name: "float",\r
+        wireType: ProtoBuf.WIRE_TYPES.BITS32,\r
+        defaultValue: 0\r
+    },\r
+    "enum": {\r
+        name: "enum",\r
+        wireType: ProtoBuf.WIRE_TYPES.VARINT,\r
+        defaultValue: 0\r
+    },\r
+    "message": {\r
+        name: "message",\r
+        wireType: ProtoBuf.WIRE_TYPES.LDELIM,\r
+        defaultValue: null\r
+    },\r
+    "group": {\r
+        name: "group",\r
+        wireType: ProtoBuf.WIRE_TYPES.STARTGROUP,\r
+        defaultValue: null\r
+    }\r
+};\r
+\r
+/**\r
+ * Valid map key types.\r
+ * @type {!Array.<!Object.<string,{name: string, wireType: number, defaultValue: *}>>}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.MAP_KEY_TYPES = [\r
+    ProtoBuf.TYPES["int32"],\r
+    ProtoBuf.TYPES["sint32"],\r
+    ProtoBuf.TYPES["sfixed32"],\r
+    ProtoBuf.TYPES["uint32"],\r
+    ProtoBuf.TYPES["fixed32"],\r
+    ProtoBuf.TYPES["int64"],\r
+    ProtoBuf.TYPES["sint64"],\r
+    ProtoBuf.TYPES["sfixed64"],\r
+    ProtoBuf.TYPES["uint64"],\r
+    ProtoBuf.TYPES["fixed64"],\r
+    ProtoBuf.TYPES["bool"],\r
+    ProtoBuf.TYPES["string"],\r
+    ProtoBuf.TYPES["bytes"]\r
+];\r
+\r
+/**\r
+ * Minimum field id.\r
+ * @type {number}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.ID_MIN = 1;\r
+\r
+/**\r
+ * Maximum field id.\r
+ * @type {number}\r
+ * @const\r
+ * @expose\r
+ */\r
+ProtoBuf.ID_MAX = 0x1FFFFFFF;\r
+\r
+/**\r
+ * If set to `true`, field names will be converted from underscore notation to camel case. Defaults to `false`.\r
+ *  Must be set prior to parsing.\r
+ * @type {boolean}\r
+ * @expose\r
+ */\r
+ProtoBuf.convertFieldsToCamelCase = false;\r
+\r
+/**\r
+ * By default, messages are populated with (setX, set_x) accessors for each field. This can be disabled by\r
+ *  setting this to `false` prior to building messages.\r
+ * @type {boolean}\r
+ * @expose\r
+ */\r
+ProtoBuf.populateAccessors = true;\r
+\r
+/**\r
+ * By default, messages are populated with default values if a field is not present on the wire. To disable\r
+ *  this behavior, set this setting to `false`.\r
+ * @type {boolean}\r
+ * @expose\r
+ */\r
+ProtoBuf.populateDefaults = true;\r
+\r
+//? include("ProtoBuf/Util.js");\r
+\r
+//? include("ProtoBuf/Lang.js");\r
+\r
+//? if (DOTPROTO) include("ProtoBuf/DotProto.js");\r
+\r
+//? include("ProtoBuf/Reflect.js");\r
+\r
+//? include("ProtoBuf/Builder.js");\r
+\r
+//? include("ProtoBuf/Map.js");\r
+\r
+//? if (DOTPROTO) {\r
+\r
+/**\r
+ * Loads a .proto string and returns the Builder.\r
+ * @param {string} proto .proto file contents\r
+ * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted.\r
+ * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports.\r
+ * @return {ProtoBuf.Builder} Builder to create new messages\r
+ * @throws {Error} If the definition cannot be parsed or built\r
+ * @expose\r
+ */\r
+ProtoBuf.loadProto = function(proto, builder, filename) {\r
+    if (typeof builder === 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string'))\r
+        filename = builder,\r
+        builder = undefined;\r
+    return ProtoBuf.loadJson(ProtoBuf.DotProto.Parser.parse(proto), builder, filename);\r
+};\r
+\r
+/**\r
+ * Loads a .proto string and returns the Builder. This is an alias of {@link ProtoBuf.loadProto}.\r
+ * @function\r
+ * @param {string} proto .proto file contents\r
+ * @param {(ProtoBuf.Builder|string)=} builder Builder to append to. Will create a new one if omitted.\r
+ * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports.\r
+ * @return {ProtoBuf.Builder} Builder to create new messages\r
+ * @throws {Error} If the definition cannot be parsed or built\r
+ * @expose\r
+ */\r
+ProtoBuf.protoFromString = ProtoBuf.loadProto; // Legacy\r
+\r
+/**\r
+ * Loads a .proto file and returns the Builder.\r
+ * @param {string|{root: string, file: string}} filename Path to proto file or an object specifying 'file' with\r
+ *  an overridden 'root' path for all imported files.\r
+ * @param {function(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and\r
+ *  the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the\r
+ *  file will be read synchronously and this function will return the Builder.\r
+ * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted.\r
+ * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the\r
+ *   request has failed), else undefined\r
+ * @expose\r
+ */\r
+ProtoBuf.loadProtoFile = function(filename, callback, builder) {\r
+    if (callback && typeof callback === 'object')\r
+        builder = callback,\r
+        callback = null;\r
+    else if (!callback || typeof callback !== 'function')\r
+        callback = null;\r
+    if (callback)\r
+        return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename["root"]+"/"+filename["file"], function(contents) {\r
+            if (contents === null) {\r
+                callback(Error("Failed to fetch file"));\r
+                return;\r
+            }\r
+            try {\r
+                callback(null, ProtoBuf.loadProto(contents, builder, filename));\r
+            } catch (e) {\r
+                callback(e);\r
+            }\r
+        });\r
+    var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename);\r
+    return contents === null ? null : ProtoBuf.loadProto(contents, builder, filename);\r
+};\r
+\r
+/**\r
+ * Loads a .proto file and returns the Builder. This is an alias of {@link ProtoBuf.loadProtoFile}.\r
+ * @function\r
+ * @param {string|{root: string, file: string}} filename Path to proto file or an object specifying 'file' with\r
+ *  an overridden 'root' path for all imported files.\r
+ * @param {function(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and\r
+ *  the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the\r
+ *  file will be read synchronously and this function will return the Builder.\r
+ * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted.\r
+ * @return {!ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the\r
+ *   request has failed), else undefined\r
+ * @expose\r
+ */\r
+ProtoBuf.protoFromFile = ProtoBuf.loadProtoFile; // Legacy\r
+\r
+//? } // DOTPROTO\r
+\r
+/**\r
+ * Constructs a new empty Builder.\r
+ * @param {Object.<string,*>=} options Builder options, defaults to global options set on ProtoBuf\r
+ * @return {!ProtoBuf.Builder} Builder\r
+ * @expose\r
+ */\r
+ProtoBuf.newBuilder = function(options) {\r
+    options = options || {};\r
+    if (typeof options['convertFieldsToCamelCase'] === 'undefined')\r
+        options['convertFieldsToCamelCase'] = ProtoBuf.convertFieldsToCamelCase;\r
+    if (typeof options['populateAccessors'] === 'undefined')\r
+        options['populateAccessors'] = ProtoBuf.populateAccessors;\r
+    return new ProtoBuf.Builder(options);\r
+};\r
+\r
+/**\r
+ * Loads a .json definition and returns the Builder.\r
+ * @param {!*|string} json JSON definition\r
+ * @param {(ProtoBuf.Builder|string|{root: string, file: string})=} builder Builder to append to. Will create a new one if omitted.\r
+ * @param {(string|{root: string, file: string})=} filename The corresponding file name if known. Must be specified for imports.\r
+ * @return {ProtoBuf.Builder} Builder to create new messages\r
+ * @throws {Error} If the definition cannot be parsed or built\r
+ * @expose\r
+ */\r
+ProtoBuf.loadJson = function(json, builder, filename) {\r
+    if (typeof builder === 'string' || (builder && typeof builder["file"] === 'string' && typeof builder["root"] === 'string'))\r
+        filename = builder,\r
+        builder = null;\r
+    if (!builder || typeof builder !== 'object')\r
+        builder = ProtoBuf.newBuilder();\r
+    if (typeof json === 'string')\r
+        json = JSON.parse(json);\r
+    builder["import"](json, filename);\r
+    builder.resolveAll();\r
+    return builder;\r
+};\r
+\r
+/**\r
+ * Loads a .json file and returns the Builder.\r
+ * @param {string|!{root: string, file: string}} filename Path to json file or an object specifying 'file' with\r
+ *  an overridden 'root' path for all imported files.\r
+ * @param {function(?Error, !ProtoBuf.Builder=)=} callback Callback that will receive `null` as the first and\r
+ *  the Builder as its second argument on success, otherwise the error as its first argument. If omitted, the\r
+ *  file will be read synchronously and this function will return the Builder.\r
+ * @param {ProtoBuf.Builder=} builder Builder to append to. Will create a new one if omitted.\r
+ * @return {?ProtoBuf.Builder|undefined} The Builder if synchronous (no callback specified, will be NULL if the\r
+ *   request has failed), else undefined\r
+ * @expose\r
+ */\r
+ProtoBuf.loadJsonFile = function(filename, callback, builder) {\r
+    if (callback && typeof callback === 'object')\r
+        builder = callback,\r
+        callback = null;\r
+    else if (!callback || typeof callback !== 'function')\r
+        callback = null;\r
+    if (callback)\r
+        return ProtoBuf.Util.fetch(typeof filename === 'string' ? filename : filename["root"]+"/"+filename["file"], function(contents) {\r
+            if (contents === null) {\r
+                callback(Error("Failed to fetch file"));\r
+                return;\r
+            }\r
+            try {\r
+                callback(null, ProtoBuf.loadJson(JSON.parse(contents), builder, filename));\r
+            } catch (e) {\r
+                callback(e);\r
+            }\r
+        });\r
+    var contents = ProtoBuf.Util.fetch(typeof filename === 'object' ? filename["root"]+"/"+filename["file"] : filename);\r
+    return contents === null ? null : ProtoBuf.loadJson(JSON.parse(contents), builder, filename);\r
+};\r