Built motion from commit 6a09e18b.|2.6.11
[motion2.git] / legacy-libs / grpc / node_modules / protobufjs / src / ProtoBuf / Builder / Message.js
diff --git a/legacy-libs/grpc/node_modules/protobufjs/src/ProtoBuf/Builder/Message.js b/legacy-libs/grpc/node_modules/protobufjs/src/ProtoBuf/Builder/Message.js
new file mode 100644 (file)
index 0000000..fe95141
--- /dev/null
@@ -0,0 +1,721 @@
+/*?\r
+ // --- Scope ------------------\r
+ // T : Reflect.Message instance\r
+ */\r
+var fields = T.getChildren(ProtoBuf.Reflect.Message.Field),\r
+    oneofs = T.getChildren(ProtoBuf.Reflect.Message.OneOf);\r
+\r
+/**\r
+ * Constructs a new runtime Message.\r
+ * @name ProtoBuf.Builder.Message\r
+ * @class Barebone of all runtime messages.\r
+ * @param {!Object.<string,*>|string} values Preset values\r
+ * @param {...string} var_args\r
+ * @constructor\r
+ * @throws {Error} If the message cannot be created\r
+ */\r
+var Message = function(values, var_args) {\r
+    ProtoBuf.Builder.Message.call(this);\r
+\r
+    // Create virtual oneof properties\r
+    for (var i=0, k=oneofs.length; i<k; ++i)\r
+        this[oneofs[i].name] = null;\r
+    // Create fields and set default values\r
+    for (i=0, k=fields.length; i<k; ++i) {\r
+        var field = fields[i];\r
+        this[field.name] =\r
+            field.repeated ? [] :\r
+            (field.map ? new ProtoBuf.Map(field) : null);\r
+        if ((field.required || T.syntax === 'proto3') &&\r
+            field.defaultValue !== null)\r
+            this[field.name] = field.defaultValue;\r
+    }\r
+\r
+    if (arguments.length > 0) {\r
+        var value;\r
+        // Set field values from a values object\r
+        if (arguments.length === 1 && values !== null && typeof values === 'object' &&\r
+            /* not _another_ Message */ (typeof values.encode !== 'function' || values instanceof Message) &&\r
+            /* not a repeated field */ !Array.isArray(values) &&\r
+            /* not a Map */ !(values instanceof ProtoBuf.Map) &&\r
+            /* not a ByteBuffer */ !ByteBuffer.isByteBuffer(values) &&\r
+            /* not an ArrayBuffer */ !(values instanceof ArrayBuffer) &&\r
+            /* not a Long */ !(ProtoBuf.Long && values instanceof ProtoBuf.Long)) {\r
+            this.$set(values);\r
+        } else // Set field values from arguments, in declaration order\r
+            for (i=0, k=arguments.length; i<k; ++i)\r
+                if (typeof (value = arguments[i]) !== 'undefined')\r
+                    this.$set(fields[i].name, value); // May throw\r
+    }\r
+};\r
+\r
+/**\r
+ * @alias ProtoBuf.Builder.Message.prototype\r
+ * @inner\r
+ */\r
+var MessagePrototype = Message.prototype = Object.create(ProtoBuf.Builder.Message.prototype);\r
+\r
+/**\r
+ * Adds a value to a repeated field.\r
+ * @name ProtoBuf.Builder.Message#add\r
+ * @function\r
+ * @param {string} key Field name\r
+ * @param {*} value Value to add\r
+ * @param {boolean=} noAssert Whether to assert the value or not (asserts by default)\r
+ * @returns {!ProtoBuf.Builder.Message} this\r
+ * @throws {Error} If the value cannot be added\r
+ * @expose\r
+ */\r
+MessagePrototype.add = function(key, value, noAssert) {\r
+    var field = T._fieldsByName[key];\r
+    if (!noAssert) {\r
+        if (!field)\r
+            throw Error(this+"#"+key+" is undefined");\r
+        if (!(field instanceof ProtoBuf.Reflect.Message.Field))\r
+            throw Error(this+"#"+key+" is not a field: "+field.toString(true)); // May throw if it's an enum or embedded message\r
+        if (!field.repeated)\r
+            throw Error(this+"#"+key+" is not a repeated field");\r
+        value = field.verifyValue(value, true);\r
+    }\r
+    if (this[key] === null)\r
+        this[key] = [];\r
+    this[key].push(value);\r
+    return this;\r
+};\r
+\r
+/**\r
+ * Adds a value to a repeated field. This is an alias for {@link ProtoBuf.Builder.Message#add}.\r
+ * @name ProtoBuf.Builder.Message#$add\r
+ * @function\r
+ * @param {string} key Field name\r
+ * @param {*} value Value to add\r
+ * @param {boolean=} noAssert Whether to assert the value or not (asserts by default)\r
+ * @returns {!ProtoBuf.Builder.Message} this\r
+ * @throws {Error} If the value cannot be added\r
+ * @expose\r
+ */\r
+MessagePrototype.$add = MessagePrototype.add;\r
+\r
+/**\r
+ * Sets a field's value.\r
+ * @name ProtoBuf.Builder.Message#set\r
+ * @function\r
+ * @param {string|!Object.<string,*>} keyOrObj String key or plain object holding multiple values\r
+ * @param {(*|boolean)=} value Value to set if key is a string, otherwise omitted\r
+ * @param {boolean=} noAssert Whether to not assert for an actual field / proper value type, defaults to `false`\r
+ * @returns {!ProtoBuf.Builder.Message} this\r
+ * @throws {Error} If the value cannot be set\r
+ * @expose\r
+ */\r
+MessagePrototype.set = function(keyOrObj, value, noAssert) {\r
+    if (keyOrObj && typeof keyOrObj === 'object') {\r
+        noAssert = value;\r
+        for (var ikey in keyOrObj) {\r
+            // Check if virtual oneof field - don't set these\r
+            if (keyOrObj.hasOwnProperty(ikey) && typeof (value = keyOrObj[ikey]) !== 'undefined' && T._oneofsByName[ikey] === undefined)\r
+                this.$set(ikey, value, noAssert);\r
+        }\r
+        return this;\r
+    }\r
+    var field = T._fieldsByName[keyOrObj];\r
+    if (!noAssert) {\r
+        if (!field)\r
+            throw Error(this+"#"+keyOrObj+" is not a field: undefined");\r
+        if (!(field instanceof ProtoBuf.Reflect.Message.Field))\r
+            throw Error(this+"#"+keyOrObj+" is not a field: "+field.toString(true));\r
+        this[field.name] = (value = field.verifyValue(value)); // May throw\r
+    } else\r
+        this[keyOrObj] = value;\r
+    if (field && field.oneof) { // Field is part of an OneOf (not a virtual OneOf field)\r
+        var currentField = this[field.oneof.name]; // Virtual field references currently set field\r
+        if (value !== null) {\r
+            if (currentField !== null && currentField !== field.name)\r
+                this[currentField] = null; // Clear currently set field\r
+            this[field.oneof.name] = field.name; // Point virtual field at this field\r
+        } else if (/* value === null && */currentField === keyOrObj)\r
+            this[field.oneof.name] = null; // Clear virtual field (current field explicitly cleared)\r
+    }\r
+    return this;\r
+};\r
+\r
+/**\r
+ * Sets a field's value. This is an alias for [@link ProtoBuf.Builder.Message#set}.\r
+ * @name ProtoBuf.Builder.Message#$set\r
+ * @function\r
+ * @param {string|!Object.<string,*>} keyOrObj String key or plain object holding multiple values\r
+ * @param {(*|boolean)=} value Value to set if key is a string, otherwise omitted\r
+ * @param {boolean=} noAssert Whether to not assert the value, defaults to `false`\r
+ * @throws {Error} If the value cannot be set\r
+ * @expose\r
+ */\r
+MessagePrototype.$set = MessagePrototype.set;\r
+\r
+/**\r
+ * Gets a field's value.\r
+ * @name ProtoBuf.Builder.Message#get\r
+ * @function\r
+ * @param {string} key Key\r
+ * @param {boolean=} noAssert Whether to not assert for an actual field, defaults to `false`\r
+ * @return {*} Value\r
+ * @throws {Error} If there is no such field\r
+ * @expose\r
+ */\r
+MessagePrototype.get = function(key, noAssert) {\r
+    if (noAssert)\r
+        return this[key];\r
+    var field = T._fieldsByName[key];\r
+    if (!field || !(field instanceof ProtoBuf.Reflect.Message.Field))\r
+        throw Error(this+"#"+key+" is not a field: undefined");\r
+    if (!(field instanceof ProtoBuf.Reflect.Message.Field))\r
+        throw Error(this+"#"+key+" is not a field: "+field.toString(true));\r
+    return this[field.name];\r
+};\r
+\r
+/**\r
+ * Gets a field's value. This is an alias for {@link ProtoBuf.Builder.Message#$get}.\r
+ * @name ProtoBuf.Builder.Message#$get\r
+ * @function\r
+ * @param {string} key Key\r
+ * @return {*} Value\r
+ * @throws {Error} If there is no such field\r
+ * @expose\r
+ */\r
+MessagePrototype.$get = MessagePrototype.get;\r
+\r
+// Getters and setters\r
+\r
+for (var i=0; i<fields.length; i++) {\r
+    var field = fields[i];\r
+    // no setters for extension fields as these are named by their fqn\r
+    if (field instanceof ProtoBuf.Reflect.Message.ExtensionField)\r
+        continue;\r
+\r
+    if (T.builder.options['populateAccessors'])\r
+        (function(field) {\r
+            // set/get[SomeValue]\r
+            var Name = field.originalName.replace(/(_[a-zA-Z])/g, function(match) {\r
+                return match.toUpperCase().replace('_','');\r
+            });\r
+            Name = Name.substring(0,1).toUpperCase() + Name.substring(1);\r
+\r
+            // set/get_[some_value] FIXME: Do we really need these?\r
+            var name = field.originalName.replace(/([A-Z])/g, function(match) {\r
+                return "_"+match;\r
+            });\r
+\r
+            /**\r
+             * The current field's unbound setter function.\r
+             * @function\r
+             * @param {*} value\r
+             * @param {boolean=} noAssert\r
+             * @returns {!ProtoBuf.Builder.Message}\r
+             * @inner\r
+             */\r
+            var setter = function(value, noAssert) {\r
+                this[field.name] = noAssert ? value : field.verifyValue(value);\r
+                return this;\r
+            };\r
+\r
+            /**\r
+             * The current field's unbound getter function.\r
+             * @function\r
+             * @returns {*}\r
+             * @inner\r
+             */\r
+            var getter = function() {\r
+                return this[field.name];\r
+            };\r
+\r
+            if (T.getChild("set"+Name) === null)\r
+                /**\r
+                 * Sets a value. This method is present for each field, but only if there is no name conflict with\r
+                 *  another field.\r
+                 * @name ProtoBuf.Builder.Message#set[SomeField]\r
+                 * @function\r
+                 * @param {*} value Value to set\r
+                 * @param {boolean=} noAssert Whether to not assert the value, defaults to `false`\r
+                 * @returns {!ProtoBuf.Builder.Message} this\r
+                 * @abstract\r
+                 * @throws {Error} If the value cannot be set\r
+                 */\r
+                MessagePrototype["set"+Name] = setter;\r
+\r
+            if (T.getChild("set_"+name) === null)\r
+                /**\r
+                 * Sets a value. This method is present for each field, but only if there is no name conflict with\r
+                 *  another field.\r
+                 * @name ProtoBuf.Builder.Message#set_[some_field]\r
+                 * @function\r
+                 * @param {*} value Value to set\r
+                 * @param {boolean=} noAssert Whether to not assert the value, defaults to `false`\r
+                 * @returns {!ProtoBuf.Builder.Message} this\r
+                 * @abstract\r
+                 * @throws {Error} If the value cannot be set\r
+                 */\r
+                MessagePrototype["set_"+name] = setter;\r
+\r
+            if (T.getChild("get"+Name) === null)\r
+                /**\r
+                 * Gets a value. This method is present for each field, but only if there is no name conflict with\r
+                 *  another field.\r
+                 * @name ProtoBuf.Builder.Message#get[SomeField]\r
+                 * @function\r
+                 * @abstract\r
+                 * @return {*} The value\r
+                 */\r
+                MessagePrototype["get"+Name] = getter;\r
+\r
+            if (T.getChild("get_"+name) === null)\r
+                /**\r
+                 * Gets a value. This method is present for each field, but only if there is no name conflict with\r
+                 *  another field.\r
+                 * @name ProtoBuf.Builder.Message#get_[some_field]\r
+                 * @function\r
+                 * @return {*} The value\r
+                 * @abstract\r
+                 */\r
+                MessagePrototype["get_"+name] = getter;\r
+\r
+        })(field);\r
+}\r
+\r
+// En-/decoding\r
+\r
+/**\r
+ * Encodes the message.\r
+ * @name ProtoBuf.Builder.Message#$encode\r
+ * @function\r
+ * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.\r
+ * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`\r
+ * @return {!ByteBuffer} Encoded message as a ByteBuffer\r
+ * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r
+ *  returns the encoded ByteBuffer in the `encoded` property on the error.\r
+ * @expose\r
+ * @see ProtoBuf.Builder.Message#encode64\r
+ * @see ProtoBuf.Builder.Message#encodeHex\r
+ * @see ProtoBuf.Builder.Message#encodeAB\r
+ */\r
+MessagePrototype.encode = function(buffer, noVerify) {\r
+    if (typeof buffer === 'boolean')\r
+        noVerify = buffer,\r
+        buffer = undefined;\r
+    var isNew = false;\r
+    if (!buffer)\r
+        buffer = new ByteBuffer(),\r
+        isNew = true;\r
+    var le = buffer.littleEndian;\r
+    try {\r
+        T.encode(this, buffer.LE(), noVerify);\r
+        return (isNew ? buffer.flip() : buffer).LE(le);\r
+    } catch (e) {\r
+        buffer.LE(le);\r
+        throw(e);\r
+    }\r
+};\r
+\r
+/**\r
+ * Encodes a message using the specified data payload.\r
+ * @param {!Object.<string,*>} data Data payload\r
+ * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.\r
+ * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`\r
+ * @return {!ByteBuffer} Encoded message as a ByteBuffer\r
+ * @expose\r
+ */\r
+Message.encode = function(data, buffer, noVerify) {\r
+    return new Message(data).encode(buffer, noVerify);\r
+};\r
+\r
+/**\r
+ * Calculates the byte length of the message.\r
+ * @name ProtoBuf.Builder.Message#calculate\r
+ * @function\r
+ * @returns {number} Byte length\r
+ * @throws {Error} If the message cannot be calculated or if required fields are missing.\r
+ * @expose\r
+ */\r
+MessagePrototype.calculate = function() {\r
+    return T.calculate(this);\r
+};\r
+\r
+/**\r
+ * Encodes the varint32 length-delimited message.\r
+ * @name ProtoBuf.Builder.Message#encodeDelimited\r
+ * @function\r
+ * @param {(!ByteBuffer|boolean)=} buffer ByteBuffer to encode to. Will create a new one and flip it if omitted.\r
+ * @param {boolean=} noVerify Whether to not verify field values, defaults to `false`\r
+ * @return {!ByteBuffer} Encoded message as a ByteBuffer\r
+ * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r
+ *  returns the encoded ByteBuffer in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.encodeDelimited = function(buffer, noVerify) {\r
+    var isNew = false;\r
+    if (!buffer)\r
+        buffer = new ByteBuffer(),\r
+        isNew = true;\r
+    var enc = new ByteBuffer().LE();\r
+    T.encode(this, enc, noVerify).flip();\r
+    buffer.writeVarint32(enc.remaining());\r
+    buffer.append(enc);\r
+    return isNew ? buffer.flip() : buffer;\r
+};\r
+\r
+/**\r
+ * Directly encodes the message to an ArrayBuffer.\r
+ * @name ProtoBuf.Builder.Message#encodeAB\r
+ * @function\r
+ * @return {ArrayBuffer} Encoded message as ArrayBuffer\r
+ * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r
+ *  returns the encoded ArrayBuffer in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.encodeAB = function() {\r
+    try {\r
+        return this.encode().toArrayBuffer();\r
+    } catch (e) {\r
+        if (e["encoded"]) e["encoded"] = e["encoded"].toArrayBuffer();\r
+        throw(e);\r
+    }\r
+};\r
+\r
+/**\r
+ * Returns the message as an ArrayBuffer. This is an alias for {@link ProtoBuf.Builder.Message#encodeAB}.\r
+ * @name ProtoBuf.Builder.Message#toArrayBuffer\r
+ * @function\r
+ * @return {ArrayBuffer} Encoded message as ArrayBuffer\r
+ * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r
+ *  returns the encoded ArrayBuffer in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.toArrayBuffer = MessagePrototype.encodeAB;\r
+\r
+/**\r
+ * Directly encodes the message to a node Buffer.\r
+ * @name ProtoBuf.Builder.Message#encodeNB\r
+ * @function\r
+ * @return {!Buffer}\r
+ * @throws {Error} If the message cannot be encoded, not running under node.js or if required fields are\r
+ *  missing. The later still returns the encoded node Buffer in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.encodeNB = function() {\r
+    try {\r
+        return this.encode().toBuffer();\r
+    } catch (e) {\r
+        if (e["encoded"]) e["encoded"] = e["encoded"].toBuffer();\r
+        throw(e);\r
+    }\r
+};\r
+\r
+/**\r
+ * Returns the message as a node Buffer. This is an alias for {@link ProtoBuf.Builder.Message#encodeNB}.\r
+ * @name ProtoBuf.Builder.Message#toBuffer\r
+ * @function\r
+ * @return {!Buffer}\r
+ * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r
+ *  returns the encoded node Buffer in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.toBuffer = MessagePrototype.encodeNB;\r
+\r
+/**\r
+ * Directly encodes the message to a base64 encoded string.\r
+ * @name ProtoBuf.Builder.Message#encode64\r
+ * @function\r
+ * @return {string} Base64 encoded string\r
+ * @throws {Error} If the underlying buffer cannot be encoded or if required fields are missing. The later\r
+ *  still returns the encoded base64 string in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.encode64 = function() {\r
+    try {\r
+        return this.encode().toBase64();\r
+    } catch (e) {\r
+        if (e["encoded"]) e["encoded"] = e["encoded"].toBase64();\r
+        throw(e);\r
+    }\r
+};\r
+\r
+/**\r
+ * Returns the message as a base64 encoded string. This is an alias for {@link ProtoBuf.Builder.Message#encode64}.\r
+ * @name ProtoBuf.Builder.Message#toBase64\r
+ * @function\r
+ * @return {string} Base64 encoded string\r
+ * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r
+ *  returns the encoded base64 string in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.toBase64 = MessagePrototype.encode64;\r
+\r
+/**\r
+ * Directly encodes the message to a hex encoded string.\r
+ * @name ProtoBuf.Builder.Message#encodeHex\r
+ * @function\r
+ * @return {string} Hex encoded string\r
+ * @throws {Error} If the underlying buffer cannot be encoded or if required fields are missing. The later\r
+ *  still returns the encoded hex string in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.encodeHex = function() {\r
+    try {\r
+        return this.encode().toHex();\r
+    } catch (e) {\r
+        if (e["encoded"]) e["encoded"] = e["encoded"].toHex();\r
+        throw(e);\r
+    }\r
+};\r
+\r
+/**\r
+ * Returns the message as a hex encoded string. This is an alias for {@link ProtoBuf.Builder.Message#encodeHex}.\r
+ * @name ProtoBuf.Builder.Message#toHex\r
+ * @function\r
+ * @return {string} Hex encoded string\r
+ * @throws {Error} If the message cannot be encoded or if required fields are missing. The later still\r
+ *  returns the encoded hex string in the `encoded` property on the error.\r
+ * @expose\r
+ */\r
+MessagePrototype.toHex = MessagePrototype.encodeHex;\r
+\r
+/**\r
+ * Clones a message object or field value to a raw object.\r
+ * @param {*} obj Object to clone\r
+ * @param {boolean} binaryAsBase64 Whether to include binary data as base64 strings or as a buffer otherwise\r
+ * @param {boolean} longsAsStrings Whether to encode longs as strings\r
+ * @param {!ProtoBuf.Reflect.T=} resolvedType The resolved field type if a field\r
+ * @returns {*} Cloned object\r
+ * @inner\r
+ */\r
+function cloneRaw(obj, binaryAsBase64, longsAsStrings, resolvedType) {\r
+    if (obj === null || typeof obj !== 'object') {\r
+        // Convert enum values to their respective names\r
+        if (resolvedType && resolvedType instanceof ProtoBuf.Reflect.Enum) {\r
+            var name = ProtoBuf.Reflect.Enum.getName(resolvedType.object, obj);\r
+            if (name !== null)\r
+                return name;\r
+        }\r
+        // Pass-through string, number, boolean, null...\r
+        return obj;\r
+    }\r
+    // Convert ByteBuffers to raw buffer or strings\r
+    if (ByteBuffer.isByteBuffer(obj))\r
+        return binaryAsBase64 ? obj.toBase64() : obj.toBuffer();\r
+    // Convert Longs to proper objects or strings\r
+    if (ProtoBuf.Long.isLong(obj))\r
+        return longsAsStrings ? obj.toString() : ProtoBuf.Long.fromValue(obj);\r
+    var clone;\r
+    // Clone arrays\r
+    if (Array.isArray(obj)) {\r
+        clone = [];\r
+        obj.forEach(function(v, k) {\r
+            clone[k] = cloneRaw(v, binaryAsBase64, longsAsStrings, resolvedType);\r
+        });\r
+        return clone;\r
+    }\r
+    clone = {};\r
+    // Convert maps to objects\r
+    if (obj instanceof ProtoBuf.Map) {\r
+        var it = obj.entries();\r
+        for (var e = it.next(); !e.done; e = it.next())\r
+            clone[obj.keyElem.valueToString(e.value[0])] = cloneRaw(e.value[1], binaryAsBase64, longsAsStrings, obj.valueElem.resolvedType);\r
+        return clone;\r
+    }\r
+    // Everything else is a non-null object\r
+    var type = obj.$type,\r
+        field = undefined;\r
+    for (var i in obj)\r
+        if (obj.hasOwnProperty(i)) {\r
+            if (type && (field = type.getChild(i)))\r
+                clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings, field.resolvedType);\r
+            else\r
+                clone[i] = cloneRaw(obj[i], binaryAsBase64, longsAsStrings);\r
+        }\r
+    return clone;\r
+}\r
+\r
+/**\r
+ * Returns the message's raw payload.\r
+ * @param {boolean=} binaryAsBase64 Whether to include binary data as base64 strings instead of Buffers, defaults to `false`\r
+ * @param {boolean} longsAsStrings Whether to encode longs as strings\r
+ * @returns {Object.<string,*>} Raw payload\r
+ * @expose\r
+ */\r
+MessagePrototype.toRaw = function(binaryAsBase64, longsAsStrings) {\r
+    return cloneRaw(this, !!binaryAsBase64, !!longsAsStrings, this.$type);\r
+};\r
+\r
+/**\r
+ * Encodes a message to JSON.\r
+ * @returns {string} JSON string\r
+ * @expose\r
+ */\r
+MessagePrototype.encodeJSON = function() {\r
+    return JSON.stringify(\r
+        cloneRaw(this,\r
+             /* binary-as-base64 */ true,\r
+             /* longs-as-strings */ true,\r
+             this.$type\r
+        )\r
+    );\r
+};\r
+\r
+/**\r
+ * Decodes a message from the specified buffer or string.\r
+ * @name ProtoBuf.Builder.Message.decode\r
+ * @function\r
+ * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from\r
+ * @param {(number|string)=} length Message length. Defaults to decode all the remainig data.\r
+ * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64\r
+ * @return {!ProtoBuf.Builder.Message} Decoded message\r
+ * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r
+ *  returns the decoded message with missing fields in the `decoded` property on the error.\r
+ * @expose\r
+ * @see ProtoBuf.Builder.Message.decode64\r
+ * @see ProtoBuf.Builder.Message.decodeHex\r
+ */\r
+Message.decode = function(buffer, length, enc) {\r
+    if (typeof length === 'string')\r
+        enc = length,\r
+        length = -1;\r
+    if (typeof buffer === 'string')\r
+        buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");\r
+    else if (!ByteBuffer.isByteBuffer(buffer))\r
+        buffer = ByteBuffer.wrap(buffer); // May throw\r
+    var le = buffer.littleEndian;\r
+    try {\r
+        var msg = T.decode(buffer.LE(), length);\r
+        buffer.LE(le);\r
+        return msg;\r
+    } catch (e) {\r
+        buffer.LE(le);\r
+        throw(e);\r
+    }\r
+};\r
+\r
+/**\r
+ * Decodes a varint32 length-delimited message from the specified buffer or string.\r
+ * @name ProtoBuf.Builder.Message.decodeDelimited\r
+ * @function\r
+ * @param {!ByteBuffer|!ArrayBuffer|!Buffer|string} buffer Buffer to decode from\r
+ * @param {string=} enc Encoding if buffer is a string: hex, utf8 (not recommended), defaults to base64\r
+ * @return {ProtoBuf.Builder.Message} Decoded message or `null` if not enough bytes are available yet\r
+ * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r
+ *  returns the decoded message with missing fields in the `decoded` property on the error.\r
+ * @expose\r
+ */\r
+Message.decodeDelimited = function(buffer, enc) {\r
+    if (typeof buffer === 'string')\r
+        buffer = ByteBuffer.wrap(buffer, enc ? enc : "base64");\r
+    else if (!ByteBuffer.isByteBuffer(buffer))\r
+        buffer = ByteBuffer.wrap(buffer); // May throw\r
+    if (buffer.remaining() < 1)\r
+        return null;\r
+    var off = buffer.offset,\r
+        len = buffer.readVarint32();\r
+    if (buffer.remaining() < len) {\r
+        buffer.offset = off;\r
+        return null;\r
+    }\r
+    try {\r
+        var msg = T.decode(buffer.slice(buffer.offset, buffer.offset + len).LE());\r
+        buffer.offset += len;\r
+        return msg;\r
+    } catch (err) {\r
+        buffer.offset += len;\r
+        throw err;\r
+    }\r
+};\r
+\r
+/**\r
+ * Decodes the message from the specified base64 encoded string.\r
+ * @name ProtoBuf.Builder.Message.decode64\r
+ * @function\r
+ * @param {string} str String to decode from\r
+ * @return {!ProtoBuf.Builder.Message} Decoded message\r
+ * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r
+ *  returns the decoded message with missing fields in the `decoded` property on the error.\r
+ * @expose\r
+ */\r
+Message.decode64 = function(str) {\r
+    return Message.decode(str, "base64");\r
+};\r
+\r
+/**\r
+ * Decodes the message from the specified hex encoded string.\r
+ * @name ProtoBuf.Builder.Message.decodeHex\r
+ * @function\r
+ * @param {string} str String to decode from\r
+ * @return {!ProtoBuf.Builder.Message} Decoded message\r
+ * @throws {Error} If the message cannot be decoded or if required fields are missing. The later still\r
+ *  returns the decoded message with missing fields in the `decoded` property on the error.\r
+ * @expose\r
+ */\r
+Message.decodeHex = function(str) {\r
+    return Message.decode(str, "hex");\r
+};\r
+\r
+/**\r
+ * Decodes the message from a JSON string.\r
+ * @name ProtoBuf.Builder.Message.decodeJSON\r
+ * @function\r
+ * @param {string} str String to decode from\r
+ * @return {!ProtoBuf.Builder.Message} Decoded message\r
+ * @throws {Error} If the message cannot be decoded or if required fields are\r
+ * missing.\r
+ * @expose\r
+ */\r
+Message.decodeJSON = function(str) {\r
+    return new Message(JSON.parse(str));\r
+};\r
+\r
+// Utility\r
+\r
+/**\r
+ * Returns a string representation of this Message.\r
+ * @name ProtoBuf.Builder.Message#toString\r
+ * @function\r
+ * @return {string} String representation as of ".Fully.Qualified.MessageName"\r
+ * @expose\r
+ */\r
+MessagePrototype.toString = function() {\r
+    return T.toString();\r
+};\r
+\r
+// Properties\r
+\r
+/**\r
+ * Message options.\r
+ * @name ProtoBuf.Builder.Message.$options\r
+ * @type {Object.<string,*>}\r
+ * @expose\r
+ */\r
+var $optionsS; // cc needs this\r
+\r
+/**\r
+ * Message options.\r
+ * @name ProtoBuf.Builder.Message#$options\r
+ * @type {Object.<string,*>}\r
+ * @expose\r
+ */\r
+var $options;\r
+\r
+/**\r
+ * Reflection type.\r
+ * @name ProtoBuf.Builder.Message.$type\r
+ * @type {!ProtoBuf.Reflect.Message}\r
+ * @expose\r
+ */\r
+var $typeS;\r
+\r
+/**\r
+ * Reflection type.\r
+ * @name ProtoBuf.Builder.Message#$type\r
+ * @type {!ProtoBuf.Reflect.Message}\r
+ * @expose\r
+ */\r
+var $type;\r
+\r
+if (Object.defineProperty)\r
+    Object.defineProperty(Message, '$options', { "value": T.buildOpt() }),\r
+    Object.defineProperty(MessagePrototype, "$options", { "value": Message["$options"] }),\r
+    Object.defineProperty(Message, "$type", { "value": T }),\r
+    Object.defineProperty(MessagePrototype, "$type", { "value": T });\r