1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc. All rights reserved.
3 // https://developers.google.com/protocol-buffers/
5 // Redistribution and use in source and binary forms, with or without
6 // modification, are permitted provided that the following conditions are
9 // * Redistributions of source code must retain the above copyright
10 // notice, this list of conditions and the following disclaimer.
11 // * Redistributions in binary form must reproduce the above
12 // copyright notice, this list of conditions and the following disclaimer
13 // in the documentation and/or other materials provided with the
15 // * Neither the name of Google Inc. nor the names of its
16 // contributors may be used to endorse or promote products derived from
17 // this software without specific prior written permission.
19 // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 // "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 // A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 // OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
24 // SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
25 // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 // DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 // THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 // (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29 // OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #include <google/protobuf/compiler/js/well_known_types_embed.h>
33 struct FileToc well_known_types_js[] = {
35 "/* This code will be inserted into generated code for\n"
36 " * google/protobuf/any.proto. */\n"
39 " * Returns the type name contained in this instance, if any.\n"
40 " * @return {string|undefined}\n"
42 "proto.google.protobuf.Any.prototype.getTypeName = function() {\n"
43 " return this.getTypeUrl().split('/').pop();\n"
48 " * Packs the given message instance into this Any.\n"
49 " * For binary format usage only.\n"
50 " * @param {!Uint8Array} serialized The serialized data to pack.\n"
51 " * @param {string} name The type name of this message object.\n"
52 " * @param {string=} opt_typeUrlPrefix the type URL prefix.\n"
54 "proto.google.protobuf.Any.prototype.pack = function(serialized, name,\n"
55 " opt_typeUrlPrefix) "
57 " if (!opt_typeUrlPrefix) {\n"
58 " opt_typeUrlPrefix = 'type.googleapis.com/';\n"
61 " if (opt_typeUrlPrefix.substr(-1) != '/') {\n"
62 " this.setTypeUrl(opt_typeUrlPrefix + '/' + name);\n"
64 " this.setTypeUrl(opt_typeUrlPrefix + name);\n"
67 " this.setValue(serialized);\n"
73 " * Unpacks this Any into the given message object.\n"
74 " * @param {function(Uint8Array):T} deserialize Function that will "
76 " * the binary data properly.\n"
77 " * @param {string} name The expected type name of this message object.\n"
78 " * @return {?T} If the name matched the expected name, returns the "
80 " * object, otherwise returns null.\n"
82 "proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) "
84 " if (this.getTypeName() == name) {\n"
85 " return deserialize(this.getValue_asU8());\n"
92 "/* This code will be inserted into generated code for\n"
93 " * google/protobuf/timestamp.proto. */\n"
96 " * Returns a JavaScript 'Date' object corresponding to this Timestamp.\n"
97 " * @return {!Date}\n"
99 "proto.google.protobuf.Timestamp.prototype.toDate = function() {\n"
100 " var seconds = this.getSeconds();\n"
101 " var nanos = this.getNanos();\n"
103 " return new Date((seconds * 1000) + (nanos / 1000000));\n"
108 " * Sets the value of this Timestamp object to be the given Date.\n"
109 " * @param {!Date} value The value to set.\n"
111 "proto.google.protobuf.Timestamp.prototype.fromDate = function(value) {\n"
112 " this.setSeconds(Math.floor(value.getTime() / 1000));\n"
113 " this.setNanos(value.getMilliseconds() * 1000000);\n"
118 " * Factory method that returns a Timestamp object with value equal to\n"
119 " * the given Date.\n"
120 " * @param {!Date} value The value to set.\n"
121 " * @return {!proto.google.protobuf.Timestamp}\n"
123 "proto.google.protobuf.Timestamp.fromDate = function(value) {\n"
124 " var timestamp = new proto.google.protobuf.Timestamp();\n"
125 " timestamp.fromDate(value);\n"
126 " return timestamp;\n"
129 "/* This code will be inserted into generated code for\n"
130 " * google/protobuf/struct.proto. */\n"
133 " * Typedef representing plain JavaScript values that can go into a\n"
135 " * @typedef {null|number|string|boolean|Array|Object}\n"
137 "proto.google.protobuf.JavaScriptValue;\n"
141 " * Converts this Value object to a plain JavaScript value.\n"
142 " * @return {?proto.google.protobuf.JavaScriptValue} a plain JavaScript\n"
143 " * value representing this Struct.\n"
145 "proto.google.protobuf.Value.prototype.toJavaScript = function() {\n"
146 " var kindCase = proto.google.protobuf.Value.KindCase;\n"
147 " switch (this.getKindCase()) {\n"
148 " case kindCase.NULL_VALUE:\n"
150 " case kindCase.NUMBER_VALUE:\n"
151 " return this.getNumberValue();\n"
152 " case kindCase.STRING_VALUE:\n"
153 " return this.getStringValue();\n"
154 " case kindCase.BOOL_VALUE:\n"
155 " return this.getBoolValue();\n"
156 " case kindCase.STRUCT_VALUE:\n"
157 " return this.getStructValue().toJavaScript();\n"
158 " case kindCase.LIST_VALUE:\n"
159 " return this.getListValue().toJavaScript();\n"
161 " throw new Error('Unexpected struct type');\n"
167 " * Converts this JavaScript value to a new Value proto.\n"
168 " * @param {!proto.google.protobuf.JavaScriptValue} value The value to\n"
170 " * @return {!proto.google.protobuf.Value} The newly constructed value.\n"
172 "proto.google.protobuf.Value.fromJavaScript = function(value) {\n"
173 " var ret = new proto.google.protobuf.Value();\n"
174 " switch (goog.typeOf(value)) {\n"
176 " ret.setStringValue(/** @type {string} */ (value));\n"
179 " ret.setNumberValue(/** @type {number} */ (value));\n"
182 " ret.setBoolValue(/** @type {boolean} */ (value));\n"
185 " ret.setNullValue(proto.google.protobuf.NullValue.NULL_VALUE);\n"
188 " ret.setListValue(proto.google.protobuf.ListValue.fromJavaScript(\n"
189 " /** @type{!Array} */ (value)));\n"
192 " ret.setStructValue(proto.google.protobuf.Struct.fromJavaScript(\n"
193 " /** @type{!Object} */ (value)));\n"
196 " throw new Error('Unexpected struct type.');\n"
204 " * Converts this ListValue object to a plain JavaScript array.\n"
205 " * @return {!Array} a plain JavaScript array representing this List.\n"
207 "proto.google.protobuf.ListValue.prototype.toJavaScript = function() {\n"
209 " var values = this.getValuesList();\n"
211 " for (var i = 0; i < values.length; i++) {\n"
212 " ret[i] = values[i].toJavaScript();\n"
220 " * Constructs a ListValue protobuf from this plain JavaScript array.\n"
221 " * @param {!Array} array a plain JavaScript array\n"
222 " * @return {proto.google.protobuf.ListValue} a new ListValue object\n"
224 "proto.google.protobuf.ListValue.fromJavaScript = function(array) {\n"
225 " var ret = new proto.google.protobuf.ListValue();\n"
227 " for (var i = 0; i < array.length; i++) {\n"
229 "ret.addValues(proto.google.protobuf.Value.fromJavaScript(array[i]));\n"
237 " * Converts this Struct object to a plain JavaScript object.\n"
238 " * @return {!Object<string, !proto.google.protobuf.JavaScriptValue>} a "
240 " * JavaScript object representing this Struct.\n"
242 "proto.google.protobuf.Struct.prototype.toJavaScript = function() {\n"
245 " this.getFieldsMap().forEach(function(value, key) {\n"
246 " ret[key] = value.toJavaScript();\n"
254 " * Constructs a Struct protobuf from this plain JavaScript object.\n"
255 " * @param {!Object} obj a plain JavaScript object\n"
256 " * @return {proto.google.protobuf.Struct} a new Struct object\n"
258 "proto.google.protobuf.Struct.fromJavaScript = function(obj) {\n"
259 " var ret = new proto.google.protobuf.Struct();\n"
260 " var map = ret.getFieldsMap();\n"
262 " for (var property in obj) {\n"
263 " var val = obj[property];\n"
264 " map.set(property, proto.google.protobuf.Value.fromJavaScript(val));\n"
269 {NULL, NULL} // Terminate the list.