message.js
3.71 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
"use strict";
module.exports = Message;
var util = require("./util/minimal");
/**
* Constructs a new message instance.
* @classdesc Abstract runtime message.
* @constructor
* @param {Properties<T>} [properties] Properties to set
* @template T extends object = object
*/
function Message(properties) {
// not used internally
if (properties)
for (var keys = Object.keys(properties), i = 0; i < keys.length; ++i)
this[keys[i]] = properties[keys[i]];
}
/**
* Reference to the reflected type.
* @name Message.$type
* @type {Type}
* @readonly
*/
/**
* Reference to the reflected type.
* @name Message#$type
* @type {Type}
* @readonly
*/
/*eslint-disable valid-jsdoc*/
/**
* Creates a new message of this type using the specified properties.
* @param {Object.<string,*>} [properties] Properties to set
* @returns {Message<T>} Message instance
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.create = function create(properties) {
return this.$type.create(properties);
};
/**
* Encodes a message of this type.
* @param {T|Object.<string,*>} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.encode = function encode(message, writer) {
return this.$type.encode(message, writer);
};
/**
* Encodes a message of this type preceeded by its length as a varint.
* @param {T|Object.<string,*>} message Message to encode
* @param {Writer} [writer] Writer to use
* @returns {Writer} Writer
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.encodeDelimited = function encodeDelimited(message, writer) {
return this.$type.encodeDelimited(message, writer);
};
/**
* Decodes a message of this type.
* @name Message.decode
* @function
* @param {Reader|Uint8Array} reader Reader or buffer to decode
* @returns {T} Decoded message
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.decode = function decode(reader) {
return this.$type.decode(reader);
};
/**
* Decodes a message of this type preceeded by its length as a varint.
* @name Message.decodeDelimited
* @function
* @param {Reader|Uint8Array} reader Reader or buffer to decode
* @returns {T} Decoded message
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.decodeDelimited = function decodeDelimited(reader) {
return this.$type.decodeDelimited(reader);
};
/**
* Verifies a message of this type.
* @name Message.verify
* @function
* @param {Object.<string,*>} message Plain object to verify
* @returns {string|null} `null` if valid, otherwise the reason why it is not
*/
Message.verify = function verify(message) {
return this.$type.verify(message);
};
/**
* Creates a new message of this type from a plain object. Also converts values to their respective internal types.
* @param {Object.<string,*>} object Plain object
* @returns {T} Message instance
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.fromObject = function fromObject(object) {
return this.$type.fromObject(object);
};
/**
* Creates a plain object from a message of this type. Also converts values to other types if specified.
* @param {T} message Message instance
* @param {IConversionOptions} [options] Conversion options
* @returns {Object.<string,*>} Plain object
* @template T extends Message<T>
* @this Constructor<T>
*/
Message.toObject = function toObject(message, options) {
return this.$type.toObject(message, options);
};
/**
* Converts this message to JSON.
* @returns {Object.<string,*>} JSON object
*/
Message.prototype.toJSON = function toJSON() {
return this.$type.toObject(this, util.toJSONOptions);
};
/*eslint-enable valid-jsdoc*/