basant307/AI_Governance_Project
048
1"use strict";2module.exports = Message;3 4var util = require("./util/minimal");5 6/**7 * Constructs a new message instance.8 * @classdesc Abstract runtime message.9 * @constructor10 * @param {Properties<T>} [properties] Properties to set11 * @template T extends object = object12 */13function Message(properties) {14 // not used internally15 if (properties)16 for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i) {17 var key = keys[i];18 if (key === "__proto__")19 continue;20 this[key] = properties[key];21 }22}23 24/**25 * Reference to the reflected type.26 * @name Message.$type27 * @type {Type}28 * @readonly29 */30 31/**32 * Reference to the reflected type.33 * @name Message#$type34 * @type {Type}35 * @readonly36 */37 38/*eslint-disable valid-jsdoc*/39 40/**41 * Creates a new message of this type using the specified properties.42 * @param {Object.<string,*>} [properties] Properties to set43 * @returns {Message<T>} Message instance44 * @template T extends Message<T>45 * @this Constructor<T>46 */47Message.create = function create(properties) {48 return this.$type.create(properties);49};50 51/**52 * Encodes a message of this type.53 * @param {T|Object.<string,*>} message Message to encode54 * @param {Writer} [writer] Writer to use55 * @returns {Writer} Writer56 * @template T extends Message<T>57 * @this Constructor<T>58 */59Message.encode = function encode(message, writer) {60 return this.$type.encode(message, writer);61};62 63/**64 * Encodes a message of this type preceeded by its length as a varint.65 * @param {T|Object.<string,*>} message Message to encode66 * @param {Writer} [writer] Writer to use67 * @returns {Writer} Writer68 * @template T extends Message<T>69 * @this Constructor<T>70 */71Message.encodeDelimited = function encodeDelimited(message, writer) {72 return this.$type.encodeDelimited(message, writer);73};74 75/**76 * Decodes a message of this type.77 * @name Message.decode78 * @function79 * @param {Reader|Uint8Array} reader Reader or buffer to decode80 * @returns {T} Decoded message81 * @template T extends Message<T>82 * @this Constructor<T>83 */84Message.decode = function decode(reader) {85 return this.$type.decode(reader);86};87 88/**89 * Decodes a message of this type preceeded by its length as a varint.90 * @name Message.decodeDelimited91 * @function92 * @param {Reader|Uint8Array} reader Reader or buffer to decode93 * @returns {T} Decoded message94 * @template T extends Message<T>95 * @this Constructor<T>96 */97Message.decodeDelimited = function decodeDelimited(reader) {98 return this.$type.decodeDelimited(reader);99};100 101/**102 * Verifies a message of this type.103 * @name Message.verify104 * @function105 * @param {Object.<string,*>} message Plain object to verify106 * @returns {string|null} `null` if valid, otherwise the reason why it is not107 */108Message.verify = function verify(message) {109 return this.$type.verify(message);110};111 112/**113 * Creates a new message of this type from a plain object. Also converts values to their respective internal types.114 * @param {Object.<string,*>} object Plain object115 * @returns {T} Message instance116 * @template T extends Message<T>117 * @this Constructor<T>118 */119Message.fromObject = function fromObject(object) {120 return this.$type.fromObject(object);121};122 123/**124 * Creates a plain object from a message of this type. Also converts values to other types if specified.125 * @param {T} message Message instance126 * @param {IConversionOptions} [options] Conversion options127 * @returns {Object.<string,*>} Plain object128 * @template T extends Message<T>129 * @this Constructor<T>130 */131Message.toObject = function toObject(message, options) {132 return this.$type.toObject(message, options);133};134 135/**136 * Converts this message to JSON.137 * @returns {Object.<string,*>} JSON object138 */139Message.prototype.toJSON = function toJSON() {140 return this.$type.toObject(this, util.toJSONOptions);141};142 143/*eslint-enable valid-jsdoc*/144 