123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- "use strict";
- var wrappers = exports;
- var Message = require("./message");
- wrappers[".google.protobuf.Any"] = {
- fromObject: function(object) {
-
- if (object && object["@type"]) {
-
- var name = object["@type"].substring(object["@type"].lastIndexOf("/") + 1);
- var type = this.lookup(name);
-
- if (type) {
-
- var type_url = object["@type"].charAt(0) === "." ?
- object["@type"].slice(1) : object["@type"];
-
- if (type_url.indexOf("/") === -1) {
- type_url = "/" + type_url;
- }
- return this.create({
- type_url: type_url,
- value: type.encode(type.fromObject(object)).finish()
- });
- }
- }
- return this.fromObject(object);
- },
- toObject: function(message, options) {
-
- var googleApi = "type.googleapis.com/";
- var prefix = "";
- var name = "";
-
- if (options && options.json && message.type_url && message.value) {
-
- name = message.type_url.substring(message.type_url.lastIndexOf("/") + 1);
-
- prefix = message.type_url.substring(0, message.type_url.lastIndexOf("/") + 1);
- var type = this.lookup(name);
-
- if (type)
- message = type.decode(message.value);
- }
-
- if (!(message instanceof this.ctor) && message instanceof Message) {
- var object = message.$type.toObject(message, options);
- var messageName = message.$type.fullName[0] === "." ?
- message.$type.fullName.slice(1) : message.$type.fullName;
-
- if (prefix === "") {
- prefix = googleApi;
- }
- name = prefix + messageName;
- object["@type"] = name;
- return object;
- }
- return this.toObject(message, options);
- }
- };
|