OLD | NEW |
| (Empty) |
1 #include <google/protobuf/compiler/js/well_known_types_embed.h> | |
2 struct FileToc well_known_types_js[] = { | |
3 {"any.js", | |
4 "// Protocol Buffers - Google's data interchange format\n" | |
5 "// Copyright 2008 Google Inc. All rights reserved.\n" | |
6 "// https://developers.google.com/protocol-buffers/\n" | |
7 "//\n" | |
8 "// Redistribution and use in source and binary forms, with or without\n" | |
9 "// modification, are permitted provided that the following conditions are\n" | |
10 "// met:\n" | |
11 "//\n" | |
12 "// * Redistributions of source code must retain the above copyright\n" | |
13 "// notice, this list of conditions and the following disclaimer.\n" | |
14 "// * Redistributions in binary form must reproduce the above\n" | |
15 "// copyright notice, this list of conditions and the following disclaimer\n" | |
16 "// in the documentation and/or other materials provided with the\n" | |
17 "// distribution.\n" | |
18 "// * Neither the name of Google Inc. nor the names of its\n" | |
19 "// contributors may be used to endorse or promote products derived from\n" | |
20 "// this software without specific prior written permission.\n" | |
21 "//\n" | |
22 "// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" | |
23 "// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" | |
24 "// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" | |
25 "// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" | |
26 "// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" | |
27 "// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" | |
28 "// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" | |
29 "// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" | |
30 "// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" | |
31 "// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" | |
32 "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" | |
33 "\n" | |
34 "/* This code will be inserted into generated code for\n" | |
35 " * google/protobuf/any.proto. */\n" | |
36 "\n" | |
37 "/**\n" | |
38 " * Returns the type name contained in this instance, if any.\n" | |
39 " * @return {string|undefined}\n" | |
40 " */\n" | |
41 "proto.google.protobuf.Any.prototype.getTypeName = function() {\n" | |
42 " return this.getTypeUrl().split('/').pop();\n" | |
43 "};\n" | |
44 "\n" | |
45 "\n" | |
46 "/**\n" | |
47 " * Packs the given message instance into this Any.\n" | |
48 " * @param {!Uint8Array} serialized The serialized data to pack.\n" | |
49 " * @param {string} name The type name of this message object.\n" | |
50 " * @param {string=} opt_typeUrlPrefix the type URL prefix.\n" | |
51 " */\n" | |
52 "proto.google.protobuf.Any.prototype.pack = function(serialized, name,\n" | |
53 " opt_typeUrlPrefix) {\n" | |
54 " if (!opt_typeUrlPrefix) {\n" | |
55 " opt_typeUrlPrefix = 'type.googleapis.com/';\n" | |
56 " }\n" | |
57 "\n" | |
58 " if (opt_typeUrlPrefix.substr(-1) != '/') {\n" | |
59 " this.setTypeUrl(opt_typeUrlPrefix + '/' + name);\n" | |
60 " } else {\n" | |
61 " this.setTypeUrl(opt_typeUrlPrefix + name);\n" | |
62 " }\n" | |
63 "\n" | |
64 " this.setValue(serialized);\n" | |
65 "};\n" | |
66 "\n" | |
67 "\n" | |
68 "/**\n" | |
69 " * @template T\n" | |
70 " * Unpacks this Any into the given message object.\n" | |
71 " * @param {function(Uint8Array):T} deserialize Function that will deserialize
\n" | |
72 " * the binary data properly.\n" | |
73 " * @param {string} name The expected type name of this message object.\n" | |
74 " * @return {?T} If the name matched the expected name, returns the deserializ
ed\n" | |
75 " * object, otherwise returns undefined.\n" | |
76 " */\n" | |
77 "proto.google.protobuf.Any.prototype.unpack = function(deserialize, name) {\n" | |
78 " if (this.getTypeName() == name) {\n" | |
79 " return deserialize(this.getValue_asU8());\n" | |
80 " } else {\n" | |
81 " return null;\n" | |
82 " }\n" | |
83 "};\n" | |
84 }, | |
85 {"struct.js", | |
86 "// Protocol Buffers - Google's data interchange format\n" | |
87 "// Copyright 2008 Google Inc. All rights reserved.\n" | |
88 "// https://developers.google.com/protocol-buffers/\n" | |
89 "//\n" | |
90 "// Redistribution and use in source and binary forms, with or without\n" | |
91 "// modification, are permitted provided that the following conditions are\n" | |
92 "// met:\n" | |
93 "//\n" | |
94 "// * Redistributions of source code must retain the above copyright\n" | |
95 "// notice, this list of conditions and the following disclaimer.\n" | |
96 "// * Redistributions in binary form must reproduce the above\n" | |
97 "// copyright notice, this list of conditions and the following disclaimer\n" | |
98 "// in the documentation and/or other materials provided with the\n" | |
99 "// distribution.\n" | |
100 "// * Neither the name of Google Inc. nor the names of its\n" | |
101 "// contributors may be used to endorse or promote products derived from\n" | |
102 "// this software without specific prior written permission.\n" | |
103 "//\n" | |
104 "// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" | |
105 "// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" | |
106 "// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" | |
107 "// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" | |
108 "// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" | |
109 "// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" | |
110 "// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" | |
111 "// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" | |
112 "// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" | |
113 "// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" | |
114 "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" | |
115 "\n" | |
116 "/* This code will be inserted into generated code for\n" | |
117 " * google/protobuf/struct.proto. */\n" | |
118 "\n" | |
119 "/**\n" | |
120 " * Typedef representing plain JavaScript values that can go into a\n" | |
121 " * Struct.\n" | |
122 " * @typedef {null|number|string|boolean|Array|Object}\n" | |
123 " */\n" | |
124 "proto.google.protobuf.JavaScriptValue;\n" | |
125 "\n" | |
126 "\n" | |
127 "/**\n" | |
128 " * Converts this Value object to a plain JavaScript value.\n" | |
129 " * @return {?proto.google.protobuf.JavaScriptValue} a plain JavaScript\n" | |
130 " * value representing this Struct.\n" | |
131 " */\n" | |
132 "proto.google.protobuf.Value.prototype.toJavaScript = function() {\n" | |
133 " var kindCase = proto.google.protobuf.Value.KindCase;\n" | |
134 " switch (this.getKindCase()) {\n" | |
135 " case kindCase.NULL_VALUE:\n" | |
136 " return null;\n" | |
137 " case kindCase.NUMBER_VALUE:\n" | |
138 " return this.getNumberValue();\n" | |
139 " case kindCase.STRING_VALUE:\n" | |
140 " return this.getStringValue();\n" | |
141 " case kindCase.BOOL_VALUE:\n" | |
142 " return this.getBoolValue();\n" | |
143 " case kindCase.STRUCT_VALUE:\n" | |
144 " return this.getStructValue().toJavaScript();\n" | |
145 " case kindCase.LIST_VALUE:\n" | |
146 " return this.getListValue().toJavaScript();\n" | |
147 " default:\n" | |
148 " throw new Error('Unexpected struct type');\n" | |
149 " }\n" | |
150 "};\n" | |
151 "\n" | |
152 "\n" | |
153 "/**\n" | |
154 " * Converts this JavaScript value to a new Value proto.\n" | |
155 " * @param {!proto.google.protobuf.JavaScriptValue} value The value to\n" | |
156 " * convert.\n" | |
157 " * @return {!proto.google.protobuf.Value} The newly constructed value.\n" | |
158 " */\n" | |
159 "proto.google.protobuf.Value.fromJavaScript = function(value) {\n" | |
160 " var ret = new proto.google.protobuf.Value();\n" | |
161 " switch (goog.typeOf(value)) {\n" | |
162 " case 'string':\n" | |
163 " ret.setStringValue(/** @type {string} */ (value));\n" | |
164 " break;\n" | |
165 " case 'number':\n" | |
166 " ret.setNumberValue(/** @type {number} */ (value));\n" | |
167 " break;\n" | |
168 " case 'boolean':\n" | |
169 " ret.setBoolValue(/** @type {boolean} */ (value));\n" | |
170 " break;\n" | |
171 " case 'null':\n" | |
172 " ret.setNullValue(proto.google.protobuf.NullValue.NULL_VALUE);\n" | |
173 " break;\n" | |
174 " case 'array':\n" | |
175 " ret.setListValue(proto.google.protobuf.ListValue.fromJavaScript(\n" | |
176 " /** @type{!Array} */ (value)));\n" | |
177 " break;\n" | |
178 " case 'object':\n" | |
179 " ret.setStructValue(proto.google.protobuf.Struct.fromJavaScript(\n" | |
180 " /** @type{!Object} */ (value)));\n" | |
181 " break;\n" | |
182 " default:\n" | |
183 " throw new Error('Unexpected struct type.');\n" | |
184 " }\n" | |
185 "\n" | |
186 " return ret;\n" | |
187 "};\n" | |
188 "\n" | |
189 "\n" | |
190 "/**\n" | |
191 " * Converts this ListValue object to a plain JavaScript array.\n" | |
192 " * @return {!Array} a plain JavaScript array representing this List.\n" | |
193 " */\n" | |
194 "proto.google.protobuf.ListValue.prototype.toJavaScript = function() {\n" | |
195 " var ret = [];\n" | |
196 " var values = this.getValuesList();\n" | |
197 "\n" | |
198 " for (var i = 0; i < values.length; i++) {\n" | |
199 " ret[i] = values[i].toJavaScript();\n" | |
200 " }\n" | |
201 "\n" | |
202 " return ret;\n" | |
203 "};\n" | |
204 "\n" | |
205 "\n" | |
206 "/**\n" | |
207 " * Constructs a ListValue protobuf from this plain JavaScript array.\n" | |
208 " * @param {!Array} array a plain JavaScript array\n" | |
209 " * @return {proto.google.protobuf.ListValue} a new ListValue object\n" | |
210 " */\n" | |
211 "proto.google.protobuf.ListValue.fromJavaScript = function(array) {\n" | |
212 " var ret = new proto.google.protobuf.ListValue();\n" | |
213 "\n" | |
214 " for (var i = 0; i < array.length; i++) {\n" | |
215 " ret.addValues(proto.google.protobuf.Value.fromJavaScript(array[i]));\n" | |
216 " }\n" | |
217 "\n" | |
218 " return ret;\n" | |
219 "};\n" | |
220 "\n" | |
221 "\n" | |
222 "/**\n" | |
223 " * Converts this Struct object to a plain JavaScript object.\n" | |
224 " * @return {!Object<string, !proto.google.protobuf.JavaScriptValue>} a plain\
n" | |
225 " * JavaScript object representing this Struct.\n" | |
226 " */\n" | |
227 "proto.google.protobuf.Struct.prototype.toJavaScript = function() {\n" | |
228 " var ret = {};\n" | |
229 "\n" | |
230 " this.getFieldsMap().forEach(function(value, key) {\n" | |
231 " ret[key] = value.toJavaScript();\n" | |
232 " });\n" | |
233 "\n" | |
234 " return ret;\n" | |
235 "};\n" | |
236 "\n" | |
237 "\n" | |
238 "/**\n" | |
239 " * Constructs a Struct protobuf from this plain JavaScript object.\n" | |
240 " * @param {!Object} obj a plain JavaScript object\n" | |
241 " * @return {proto.google.protobuf.Struct} a new Struct object\n" | |
242 " */\n" | |
243 "proto.google.protobuf.Struct.fromJavaScript = function(obj) {\n" | |
244 " var ret = new proto.google.protobuf.Struct();\n" | |
245 " var map = ret.getFieldsMap();\n" | |
246 "\n" | |
247 " for (var property in obj) {\n" | |
248 " var val = obj[property];\n" | |
249 " map.set(property, proto.google.protobuf.Value.fromJavaScript(val));\n" | |
250 " }\n" | |
251 "\n" | |
252 " return ret;\n" | |
253 "};\n" | |
254 }, | |
255 {"timestamp.js", | |
256 "// Protocol Buffers - Google's data interchange format\n" | |
257 "// Copyright 2008 Google Inc. All rights reserved.\n" | |
258 "// https://developers.google.com/protocol-buffers/\n" | |
259 "//\n" | |
260 "// Redistribution and use in source and binary forms, with or without\n" | |
261 "// modification, are permitted provided that the following conditions are\n" | |
262 "// met:\n" | |
263 "//\n" | |
264 "// * Redistributions of source code must retain the above copyright\n" | |
265 "// notice, this list of conditions and the following disclaimer.\n" | |
266 "// * Redistributions in binary form must reproduce the above\n" | |
267 "// copyright notice, this list of conditions and the following disclaimer\n" | |
268 "// in the documentation and/or other materials provided with the\n" | |
269 "// distribution.\n" | |
270 "// * Neither the name of Google Inc. nor the names of its\n" | |
271 "// contributors may be used to endorse or promote products derived from\n" | |
272 "// this software without specific prior written permission.\n" | |
273 "//\n" | |
274 "// THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS\n" | |
275 "// \"AS IS\" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT\n" | |
276 "// LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR\n" | |
277 "// A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT\n" | |
278 "// OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,\n" | |
279 "// SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT\n" | |
280 "// LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,\n" | |
281 "// DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY\n" | |
282 "// THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT\n" | |
283 "// (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE\n" | |
284 "// OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.\n" | |
285 "\n" | |
286 "/* This code will be inserted into generated code for\n" | |
287 " * google/protobuf/timestamp.proto. */\n" | |
288 "\n" | |
289 "/**\n" | |
290 " * Returns a JavaScript 'Date' object corresponding to this Timestamp.\n" | |
291 " * @return {!Date}\n" | |
292 " */\n" | |
293 "proto.google.protobuf.Timestamp.prototype.toDate = function() {\n" | |
294 " var seconds = this.getSeconds();\n" | |
295 " var nanos = this.getNanos();\n" | |
296 "\n" | |
297 " return new Date((seconds * 1000) + (nanos / 1000000));\n" | |
298 "};\n" | |
299 "\n" | |
300 "\n" | |
301 "/**\n" | |
302 " * Sets the value of this Timestamp object to be the given Date.\n" | |
303 " * @param {!Date} value The value to set.\n" | |
304 " */\n" | |
305 "proto.google.protobuf.Timestamp.prototype.fromDate = function(value) {\n" | |
306 " var millis = value.getTime();\n" | |
307 " this.setSeconds(Math.floor(value.getTime() / 1000));\n" | |
308 " this.setNanos(value.getMilliseconds() * 1000000);\n" | |
309 "};\n" | |
310 }, | |
311 {NULL, NULL} // Terminate the list. | |
312 }; | |
OLD | NEW |