--- /dev/null
+/**\r
+ * Constructs a new Enum.\r
+ * @exports ProtoBuf.Reflect.Enum\r
+ * @param {!ProtoBuf.Builder} builder Builder reference\r
+ * @param {!ProtoBuf.Reflect.T} parent Parent Reflect object\r
+ * @param {string} name Enum name\r
+ * @param {Object.<string,*>=} options Enum options\r
+ * @param {string?} syntax The syntax level (e.g., proto3)\r
+ * @constructor\r
+ * @extends ProtoBuf.Reflect.Namespace\r
+ */\r
+var Enum = function(builder, parent, name, options, syntax) {\r
+ Namespace.call(this, builder, parent, name, options, syntax);\r
+\r
+ /**\r
+ * @override\r
+ */\r
+ this.className = "Enum";\r
+\r
+ /**\r
+ * Runtime enum object.\r
+ * @type {Object.<string,number>|null}\r
+ * @expose\r
+ */\r
+ this.object = null;\r
+};\r
+\r
+/**\r
+ * Gets the string name of an enum value.\r
+ * @param {!ProtoBuf.Builder.Enum} enm Runtime enum\r
+ * @param {number} value Enum value\r
+ * @returns {?string} Name or `null` if not present\r
+ * @expose\r
+ */\r
+Enum.getName = function(enm, value) {\r
+ var keys = Object.keys(enm);\r
+ for (var i=0, key; i<keys.length; ++i)\r
+ if (enm[key = keys[i]] === value)\r
+ return key;\r
+ return null;\r
+};\r
+\r
+/**\r
+ * @alias ProtoBuf.Reflect.Enum.prototype\r
+ * @inner\r
+ */\r
+var EnumPrototype = Enum.prototype = Object.create(Namespace.prototype);\r
+\r
+/**\r
+ * Builds this enum and returns the runtime counterpart.\r
+ * @param {boolean} rebuild Whether to rebuild or not, defaults to false\r
+ * @returns {!Object.<string,number>}\r
+ * @expose\r
+ */\r
+EnumPrototype.build = function(rebuild) {\r
+ if (this.object && !rebuild)\r
+ return this.object;\r
+ var enm = new ProtoBuf.Builder.Enum(),\r
+ values = this.getChildren(Enum.Value);\r
+ for (var i=0, k=values.length; i<k; ++i)\r
+ enm[values[i]['name']] = values[i]['id'];\r
+ if (Object.defineProperty)\r
+ Object.defineProperty(enm, '$options', {\r
+ "value": this.buildOpt(),\r
+ "enumerable": false\r
+ });\r
+ return this.object = enm;\r
+};\r