tardis-machine 18.0.0 → 18.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/benchmark.js +35 -14
- package/bin/tardis-machine.js +0 -1
- package/dist/tardismachine.d.ts.map +1 -1
- package/dist/tardismachine.js +20 -55
- package/dist/tardismachine.js.map +1 -1
- package/dist/ws/replay.d.ts +2 -2
- package/dist/ws/replay.d.ts.map +1 -1
- package/dist/ws/replay.js +11 -5
- package/dist/ws/replay.js.map +1 -1
- package/dist/ws/replaynormalized.d.ts +2 -2
- package/dist/ws/replaynormalized.d.ts.map +1 -1
- package/dist/ws/replaynormalized.js +7 -5
- package/dist/ws/replaynormalized.js.map +1 -1
- package/dist/ws/server.d.ts +20 -0
- package/dist/ws/server.d.ts.map +1 -0
- package/dist/ws/server.js +154 -0
- package/dist/ws/server.js.map +1 -0
- package/dist/ws/streamnormalized.d.ts +2 -2
- package/dist/ws/streamnormalized.d.ts.map +1 -1
- package/dist/ws/streamnormalized.js +7 -5
- package/dist/ws/streamnormalized.js.map +1 -1
- package/dist/ws/subscriptionsmappers.d.ts +1 -1
- package/dist/ws/subscriptionsmappers.d.ts.map +1 -1
- package/node_modules/tardis-dev/README.md +1 -1
- package/node_modules/tardis-dev/dist/debug.d.ts +12 -2
- package/node_modules/tardis-dev/dist/debug.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/debug.js +2 -1
- package/node_modules/tardis-dev/dist/debug.js.map +1 -1
- package/node_modules/tardis-dev/dist/handy.d.ts +3 -1
- package/node_modules/tardis-dev/dist/handy.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/handy.js +72 -86
- package/node_modules/tardis-dev/dist/handy.js.map +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.d.ts +0 -7
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.js +2 -70
- package/node_modules/tardis-dev/dist/realtimefeeds/mexc.js.map +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.d.ts +43 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.d.ts.map +1 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.js +294 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/mexcprotobuf.js.map +1 -0
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.d.ts +3 -3
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.d.ts.map +1 -1
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.js +3 -3
- package/node_modules/tardis-dev/dist/realtimefeeds/realtimefeed.js.map +1 -1
- package/node_modules/tardis-dev/dist/worker.js +2 -2
- package/node_modules/tardis-dev/dist/worker.js.map +1 -1
- package/node_modules/tardis-dev/package.json +3 -7
- package/node_modules/tardis-dev/src/debug.ts +16 -1
- package/node_modules/tardis-dev/src/external-modules.d.ts +5 -0
- package/node_modules/tardis-dev/src/handy.ts +93 -89
- package/node_modules/tardis-dev/src/realtimefeeds/mexc.ts +2 -72
- package/node_modules/tardis-dev/src/realtimefeeds/mexcprotobuf.ts +364 -0
- package/node_modules/tardis-dev/src/realtimefeeds/realtimefeed.ts +5 -5
- package/node_modules/tardis-dev/src/worker.ts +2 -2
- package/package.json +8 -34
- package/src/tardismachine.ts +25 -66
- package/src/ws/replay.ts +13 -8
- package/src/ws/replaynormalized.ts +8 -6
- package/src/ws/server.ts +173 -0
- package/src/ws/streamnormalized.ts +8 -6
- package/src/ws/subscriptionsmappers.ts +1 -1
- package/node_modules/follow-redirects/LICENSE +0 -18
- package/node_modules/follow-redirects/README.md +0 -157
- package/node_modules/follow-redirects/debug.js +0 -15
- package/node_modules/follow-redirects/http.js +0 -1
- package/node_modules/follow-redirects/https.js +0 -1
- package/node_modules/follow-redirects/index.js +0 -709
- package/node_modules/follow-redirects/package.json +0 -58
- package/node_modules/long/LICENSE +0 -202
- package/node_modules/long/README.md +0 -286
- package/node_modules/long/index.d.ts +0 -2
- package/node_modules/long/index.js +0 -1581
- package/node_modules/long/package.json +0 -58
- package/node_modules/long/types.d.ts +0 -474
- package/node_modules/long/umd/index.d.ts +0 -3
- package/node_modules/long/umd/index.js +0 -1622
- package/node_modules/long/umd/package.json +0 -3
- package/node_modules/long/umd/types.d.ts +0 -474
- package/node_modules/protobufjs/LICENSE +0 -39
- package/node_modules/protobufjs/README.md +0 -440
- package/node_modules/protobufjs/dist/light/protobuf.js +0 -9276
- package/node_modules/protobufjs/dist/light/protobuf.js.map +0 -1
- package/node_modules/protobufjs/dist/light/protobuf.min.js +0 -8
- package/node_modules/protobufjs/dist/light/protobuf.min.js.map +0 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.js +0 -3556
- package/node_modules/protobufjs/dist/minimal/protobuf.js.map +0 -1
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js +0 -8
- package/node_modules/protobufjs/dist/minimal/protobuf.min.js.map +0 -1
- package/node_modules/protobufjs/dist/protobuf.js +0 -11233
- package/node_modules/protobufjs/dist/protobuf.js.map +0 -1
- package/node_modules/protobufjs/dist/protobuf.min.js +0 -8
- package/node_modules/protobufjs/dist/protobuf.min.js.map +0 -1
- package/node_modules/protobufjs/ext/README.md +0 -70
- package/node_modules/protobufjs/ext/debug/README.md +0 -4
- package/node_modules/protobufjs/ext/debug/index.js +0 -71
- package/node_modules/protobufjs/ext/descriptor/README.md +0 -5
- package/node_modules/protobufjs/ext/descriptor/index.d.ts +0 -2
- package/node_modules/protobufjs/ext/descriptor/index.js +0 -2
- package/node_modules/protobufjs/ext/descriptor.d.ts +0 -87
- package/node_modules/protobufjs/ext/descriptor.generated.d.ts +0 -417
- package/node_modules/protobufjs/ext/descriptor.js +0 -1356
- package/node_modules/protobufjs/ext/protojson.LICENSE +0 -201
- package/node_modules/protobufjs/ext/protojson.d.ts +0 -20
- package/node_modules/protobufjs/ext/protojson.generated.d.ts +0 -49
- package/node_modules/protobufjs/ext/protojson.js +0 -951
- package/node_modules/protobufjs/ext/textformat.d.ts +0 -19
- package/node_modules/protobufjs/ext/textformat.generated.d.ts +0 -33
- package/node_modules/protobufjs/ext/textformat.js +0 -1276
- package/node_modules/protobufjs/google/LICENSE +0 -27
- package/node_modules/protobufjs/google/README.md +0 -1
- package/node_modules/protobufjs/google/api/annotations.json +0 -85
- package/node_modules/protobufjs/google/api/annotations.proto +0 -11
- package/node_modules/protobufjs/google/api/http.json +0 -87
- package/node_modules/protobufjs/google/api/http.proto +0 -31
- package/node_modules/protobufjs/google/protobuf/api.json +0 -124
- package/node_modules/protobufjs/google/protobuf/api.proto +0 -34
- package/node_modules/protobufjs/google/protobuf/compiler/plugin.json +0 -126
- package/node_modules/protobufjs/google/protobuf/compiler/plugin.proto +0 -47
- package/node_modules/protobufjs/google/protobuf/descriptor.json +0 -1465
- package/node_modules/protobufjs/google/protobuf/descriptor.proto +0 -527
- package/node_modules/protobufjs/google/protobuf/source_context.json +0 -21
- package/node_modules/protobufjs/google/protobuf/source_context.proto +0 -7
- package/node_modules/protobufjs/google/protobuf/type.json +0 -209
- package/node_modules/protobufjs/google/protobuf/type.proto +0 -89
- package/node_modules/protobufjs/index.d.ts +0 -3203
- package/node_modules/protobufjs/index.js +0 -4
- package/node_modules/protobufjs/light.d.ts +0 -2
- package/node_modules/protobufjs/light.js +0 -4
- package/node_modules/protobufjs/minimal.d.ts +0 -2
- package/node_modules/protobufjs/minimal.js +0 -4
- package/node_modules/protobufjs/package.json +0 -93
- package/node_modules/protobufjs/src/common.js +0 -405
- package/node_modules/protobufjs/src/converter.js +0 -352
- package/node_modules/protobufjs/src/decoder.js +0 -279
- package/node_modules/protobufjs/src/encoder.js +0 -123
- package/node_modules/protobufjs/src/enum.js +0 -239
- package/node_modules/protobufjs/src/field.js +0 -505
- package/node_modules/protobufjs/src/index-light.js +0 -104
- package/node_modules/protobufjs/src/index-minimal.js +0 -35
- package/node_modules/protobufjs/src/index.js +0 -12
- package/node_modules/protobufjs/src/mapfield.js +0 -144
- package/node_modules/protobufjs/src/message.js +0 -137
- package/node_modules/protobufjs/src/method.js +0 -183
- package/node_modules/protobufjs/src/namespace.js +0 -574
- package/node_modules/protobufjs/src/object.js +0 -392
- package/node_modules/protobufjs/src/oneof.js +0 -233
- package/node_modules/protobufjs/src/parse.js +0 -1111
- package/node_modules/protobufjs/src/reader.js +0 -788
- package/node_modules/protobufjs/src/reader_buffer.js +0 -77
- package/node_modules/protobufjs/src/root.js +0 -424
- package/node_modules/protobufjs/src/roots.js +0 -18
- package/node_modules/protobufjs/src/rpc/service.js +0 -155
- package/node_modules/protobufjs/src/rpc.js +0 -36
- package/node_modules/protobufjs/src/service.js +0 -206
- package/node_modules/protobufjs/src/tokenize.js +0 -421
- package/node_modules/protobufjs/src/type.js +0 -676
- package/node_modules/protobufjs/src/types.js +0 -196
- package/node_modules/protobufjs/src/typescript.js +0 -25
- package/node_modules/protobufjs/src/util/aspromise.d.ts +0 -13
- package/node_modules/protobufjs/src/util/aspromise.js +0 -52
- package/node_modules/protobufjs/src/util/base64.d.ts +0 -32
- package/node_modules/protobufjs/src/util/base64.js +0 -146
- package/node_modules/protobufjs/src/util/codegen.d.ts +0 -31
- package/node_modules/protobufjs/src/util/codegen.js +0 -118
- package/node_modules/protobufjs/src/util/eventemitter.d.ts +0 -45
- package/node_modules/protobufjs/src/util/eventemitter.js +0 -86
- package/node_modules/protobufjs/src/util/fetch.d.ts +0 -56
- package/node_modules/protobufjs/src/util/fetch.js +0 -112
- package/node_modules/protobufjs/src/util/float.d.ts +0 -83
- package/node_modules/protobufjs/src/util/float.js +0 -335
- package/node_modules/protobufjs/src/util/fs.js +0 -11
- package/node_modules/protobufjs/src/util/longbits.js +0 -204
- package/node_modules/protobufjs/src/util/minimal.js +0 -511
- package/node_modules/protobufjs/src/util/path.d.ts +0 -22
- package/node_modules/protobufjs/src/util/path.js +0 -100
- package/node_modules/protobufjs/src/util/patterns.js +0 -7
- package/node_modules/protobufjs/src/util/pool.d.ts +0 -32
- package/node_modules/protobufjs/src/util/pool.js +0 -48
- package/node_modules/protobufjs/src/util/utf8.d.ts +0 -24
- package/node_modules/protobufjs/src/util/utf8.js +0 -190
- package/node_modules/protobufjs/src/util.js +0 -264
- package/node_modules/protobufjs/src/verifier.js +0 -185
- package/node_modules/protobufjs/src/wrappers.js +0 -106
- package/node_modules/protobufjs/src/writer.js +0 -700
- package/node_modules/protobufjs/src/writer_buffer.js +0 -100
- package/node_modules/protobufjs/tsconfig.json +0 -6
- package/node_modules/uWebSockets.js/ESM_wrapper.mjs +0 -53
- package/node_modules/uWebSockets.js/LICENSE +0 -201
- package/node_modules/uWebSockets.js/README.md +0 -6
- package/node_modules/uWebSockets.js/index.d.ts +0 -468
- package/node_modules/uWebSockets.js/package.json +0 -12
- package/node_modules/uWebSockets.js/source_commit +0 -1
- package/node_modules/uWebSockets.js/uws.js +0 -76
- package/node_modules/uWebSockets.js/uws_darwin_arm64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_arm64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_arm64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_x64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_x64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_darwin_x64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_arm64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_arm64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_arm64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_x64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_x64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_linux_x64_147.node +0 -0
- package/node_modules/uWebSockets.js/uws_win32_x64_127.node +0 -0
- package/node_modules/uWebSockets.js/uws_win32_x64_137.node +0 -0
- package/node_modules/uWebSockets.js/uws_win32_x64_147.node +0 -0
|
@@ -1,700 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
module.exports = Writer;
|
|
3
|
-
|
|
4
|
-
var util = require("./util/minimal");
|
|
5
|
-
|
|
6
|
-
var BufferWriter; // cyclic
|
|
7
|
-
|
|
8
|
-
var LongBits = util.LongBits,
|
|
9
|
-
base64 = util.base64,
|
|
10
|
-
utf8 = util.utf8;
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Constructs a new writer instance.
|
|
14
|
-
* @classdesc Wire format writer using `Uint8Array`.
|
|
15
|
-
* @constructor
|
|
16
|
-
*/
|
|
17
|
-
function Writer() {
|
|
18
|
-
|
|
19
|
-
/**
|
|
20
|
-
* Write cursor into {@link Writer#buf}.
|
|
21
|
-
* @type {number}
|
|
22
|
-
*/
|
|
23
|
-
this.pos = 0;
|
|
24
|
-
|
|
25
|
-
/**
|
|
26
|
-
* Backing buffer.
|
|
27
|
-
* @type {Uint8Array}
|
|
28
|
-
*/
|
|
29
|
-
this.buf = this.constructor.alloc(64);
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Cached DataView over {@link Writer#buf}.
|
|
33
|
-
* @type {DataView|null}
|
|
34
|
-
*/
|
|
35
|
-
this.view = null;
|
|
36
|
-
|
|
37
|
-
/**
|
|
38
|
-
* Stack of forked length-prefix positions.
|
|
39
|
-
* @type {Array<number>|null}
|
|
40
|
-
*/
|
|
41
|
-
this.states = null;
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
/**
|
|
45
|
-
* Current write position.
|
|
46
|
-
* @name Writer#len
|
|
47
|
-
* @type {number}
|
|
48
|
-
* @deprecated Use {@link Writer#pos} instead.
|
|
49
|
-
*/
|
|
50
|
-
Object.defineProperty(Writer.prototype, "len", {
|
|
51
|
-
configurable: true,
|
|
52
|
-
enumerable: true,
|
|
53
|
-
get: function get_len() {
|
|
54
|
-
return this.pos;
|
|
55
|
-
}
|
|
56
|
-
});
|
|
57
|
-
|
|
58
|
-
var create = function create() {
|
|
59
|
-
return util.Buffer
|
|
60
|
-
? function create_buffer_setup() {
|
|
61
|
-
return (Writer.create = function create_buffer() {
|
|
62
|
-
return new BufferWriter();
|
|
63
|
-
})();
|
|
64
|
-
}
|
|
65
|
-
/* istanbul ignore next */
|
|
66
|
-
: function create_array() {
|
|
67
|
-
return new Writer();
|
|
68
|
-
};
|
|
69
|
-
};
|
|
70
|
-
|
|
71
|
-
/**
|
|
72
|
-
* Creates a new writer.
|
|
73
|
-
* @function
|
|
74
|
-
* @returns {BufferWriter|Writer} A {@link BufferWriter} when Buffers are supported, otherwise a {@link Writer}
|
|
75
|
-
*/
|
|
76
|
-
Writer.create = create();
|
|
77
|
-
|
|
78
|
-
/**
|
|
79
|
-
* Allocates a buffer of the specified size.
|
|
80
|
-
* @param {number} size Buffer size
|
|
81
|
-
* @returns {Uint8Array} Buffer
|
|
82
|
-
*/
|
|
83
|
-
Writer.alloc = function alloc(size) {
|
|
84
|
-
return new Uint8Array(size);
|
|
85
|
-
};
|
|
86
|
-
|
|
87
|
-
// Use Uint8Array buffer pool in the browser, just like node does with buffers
|
|
88
|
-
Writer.alloc = util.pool(Writer.alloc, Uint8Array.prototype.subarray);
|
|
89
|
-
|
|
90
|
-
/**
|
|
91
|
-
* Calculates the number of bytes a value occupies as a varint.
|
|
92
|
-
* @param {number} value Value to size (unsigned)
|
|
93
|
-
* @returns {number} Byte length (1..5)
|
|
94
|
-
* @ignore
|
|
95
|
-
*/
|
|
96
|
-
function sizeVarint32(value) {
|
|
97
|
-
return value < 128 ? 1
|
|
98
|
-
: value < 16384 ? 2
|
|
99
|
-
: value < 2097152 ? 3
|
|
100
|
-
: value < 268435456 ? 4
|
|
101
|
-
: 5;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* Ensures that at least `n` more bytes fit into the backing buffer, doubling it if not.
|
|
106
|
-
* @param {number} n Number of additional bytes required
|
|
107
|
-
* @returns {undefined}
|
|
108
|
-
* @private
|
|
109
|
-
*/
|
|
110
|
-
Writer.prototype._reserve = function _reserve(n) {
|
|
111
|
-
var need = this.pos + n;
|
|
112
|
-
if (need > this.buf.length) {
|
|
113
|
-
var size = this.buf.length << 1;
|
|
114
|
-
if (size < need)
|
|
115
|
-
size = need;
|
|
116
|
-
var buf = this.constructor.alloc(size);
|
|
117
|
-
buf.set(this.buf.subarray(0, this.pos), 0);
|
|
118
|
-
this.buf = buf;
|
|
119
|
-
this.view = null; // invalidate
|
|
120
|
-
}
|
|
121
|
-
};
|
|
122
|
-
|
|
123
|
-
function writeStringAscii(val, buf, pos) {
|
|
124
|
-
for (var i = 0; i < val.length;)
|
|
125
|
-
buf[pos++] = val.charCodeAt(i++);
|
|
126
|
-
}
|
|
127
|
-
|
|
128
|
-
function writeVarint32(val, buf, pos) {
|
|
129
|
-
while (val > 127) {
|
|
130
|
-
buf[pos++] = val & 127 | 128;
|
|
131
|
-
val >>>= 7;
|
|
132
|
-
}
|
|
133
|
-
buf[pos] = val;
|
|
134
|
-
return pos + 1;
|
|
135
|
-
}
|
|
136
|
-
|
|
137
|
-
/**
|
|
138
|
-
* Writes an unsigned 32 bit value as a varint.
|
|
139
|
-
* @param {number} value Value to write
|
|
140
|
-
* @returns {Writer} `this`
|
|
141
|
-
*/
|
|
142
|
-
Writer.prototype.uint32 = function write_uint32(value) {
|
|
143
|
-
value = value >>> 0;
|
|
144
|
-
this._reserve(5);
|
|
145
|
-
var pos = this.pos;
|
|
146
|
-
this.pos = writeVarint32(value, this.buf, pos);
|
|
147
|
-
return this;
|
|
148
|
-
};
|
|
149
|
-
|
|
150
|
-
/**
|
|
151
|
-
* Writes a signed 32 bit value as a varint.
|
|
152
|
-
* @function
|
|
153
|
-
* @param {number} value Value to write
|
|
154
|
-
* @returns {Writer} `this`
|
|
155
|
-
*/
|
|
156
|
-
Writer.prototype.int32 = function write_int32(value) {
|
|
157
|
-
if ((value |= 0) < 0) { // 10 bytes per spec
|
|
158
|
-
this._reserve(10);
|
|
159
|
-
writeVarint64(LongBits.fromNumber(value), this.buf, this.pos);
|
|
160
|
-
this.pos += 10;
|
|
161
|
-
return this;
|
|
162
|
-
}
|
|
163
|
-
return this.uint32(value);
|
|
164
|
-
};
|
|
165
|
-
|
|
166
|
-
/**
|
|
167
|
-
* Writes a 32 bit value as a varint, zig-zag encoded.
|
|
168
|
-
* @param {number} value Value to write
|
|
169
|
-
* @returns {Writer} `this`
|
|
170
|
-
*/
|
|
171
|
-
Writer.prototype.sint32 = function write_sint32(value) {
|
|
172
|
-
return this.uint32((value << 1 ^ value >> 31) >>> 0);
|
|
173
|
-
};
|
|
174
|
-
|
|
175
|
-
function writeVarint64(val, buf, pos) {
|
|
176
|
-
var lo = val.lo,
|
|
177
|
-
hi = val.hi;
|
|
178
|
-
while (hi) {
|
|
179
|
-
buf[pos++] = lo & 127 | 128;
|
|
180
|
-
lo = (lo >>> 7 | hi << 25) >>> 0;
|
|
181
|
-
hi >>>= 7;
|
|
182
|
-
}
|
|
183
|
-
while (lo > 127) {
|
|
184
|
-
buf[pos++] = lo & 127 | 128;
|
|
185
|
-
lo = lo >>> 7;
|
|
186
|
-
}
|
|
187
|
-
buf[pos] = lo;
|
|
188
|
-
return pos + 1;
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
/**
|
|
192
|
-
* Writes an unsigned 64 bit value as a varint.
|
|
193
|
-
* @param {Long|number|string} value Value to write
|
|
194
|
-
* @returns {Writer} `this`
|
|
195
|
-
* @throws {TypeError} If `value` is a string and no long library is present.
|
|
196
|
-
*/
|
|
197
|
-
Writer.prototype.uint64 = function write_uint64(value) {
|
|
198
|
-
var bits = LongBits.from(value);
|
|
199
|
-
this._reserve(10);
|
|
200
|
-
var pos = this.pos;
|
|
201
|
-
this.pos = writeVarint64(bits, this.buf, pos);
|
|
202
|
-
return this;
|
|
203
|
-
};
|
|
204
|
-
|
|
205
|
-
/**
|
|
206
|
-
* Writes a signed 64 bit value as a varint.
|
|
207
|
-
* @function
|
|
208
|
-
* @param {Long|number|string} value Value to write
|
|
209
|
-
* @returns {Writer} `this`
|
|
210
|
-
* @throws {TypeError} If `value` is a string and no long library is present.
|
|
211
|
-
*/
|
|
212
|
-
Writer.prototype.int64 = Writer.prototype.uint64;
|
|
213
|
-
|
|
214
|
-
/**
|
|
215
|
-
* Writes a signed 64 bit value as a varint, zig-zag encoded.
|
|
216
|
-
* @param {Long|number|string} value Value to write
|
|
217
|
-
* @returns {Writer} `this`
|
|
218
|
-
* @throws {TypeError} If `value` is a string and no long library is present.
|
|
219
|
-
*/
|
|
220
|
-
Writer.prototype.sint64 = function write_sint64(value) {
|
|
221
|
-
var bits = LongBits.from(value).zzEncode();
|
|
222
|
-
this._reserve(10);
|
|
223
|
-
var pos = this.pos;
|
|
224
|
-
this.pos = writeVarint64(bits, this.buf, pos);
|
|
225
|
-
return this;
|
|
226
|
-
};
|
|
227
|
-
|
|
228
|
-
/**
|
|
229
|
-
* Writes a boolish value as a varint.
|
|
230
|
-
* @param {boolean} value Value to write
|
|
231
|
-
* @returns {Writer} `this`
|
|
232
|
-
*/
|
|
233
|
-
Writer.prototype.bool = function write_bool(value) {
|
|
234
|
-
this._reserve(1);
|
|
235
|
-
this.buf[this.pos++] = value ? 1 : 0;
|
|
236
|
-
return this;
|
|
237
|
-
};
|
|
238
|
-
|
|
239
|
-
function writeFixed32(val, buf, pos) {
|
|
240
|
-
buf[pos ] = val & 255;
|
|
241
|
-
buf[pos + 1] = val >>> 8 & 255;
|
|
242
|
-
buf[pos + 2] = val >>> 16 & 255;
|
|
243
|
-
buf[pos + 3] = val >>> 24;
|
|
244
|
-
}
|
|
245
|
-
|
|
246
|
-
/**
|
|
247
|
-
* Writes an unsigned 32 bit value as fixed 32 bits.
|
|
248
|
-
* @param {number} value Value to write
|
|
249
|
-
* @returns {Writer} `this`
|
|
250
|
-
*/
|
|
251
|
-
Writer.prototype.fixed32 = function write_fixed32(value) {
|
|
252
|
-
this._reserve(4);
|
|
253
|
-
writeFixed32(value >>> 0, this.buf, this.pos);
|
|
254
|
-
this.pos += 4;
|
|
255
|
-
return this;
|
|
256
|
-
};
|
|
257
|
-
|
|
258
|
-
/**
|
|
259
|
-
* Writes a signed 32 bit value as fixed 32 bits.
|
|
260
|
-
* @function
|
|
261
|
-
* @param {number} value Value to write
|
|
262
|
-
* @returns {Writer} `this`
|
|
263
|
-
*/
|
|
264
|
-
Writer.prototype.sfixed32 = Writer.prototype.fixed32;
|
|
265
|
-
|
|
266
|
-
/**
|
|
267
|
-
* Writes an unsigned 64 bit value as fixed 64 bits.
|
|
268
|
-
* @param {Long|number|string} value Value to write
|
|
269
|
-
* @returns {Writer} `this`
|
|
270
|
-
* @throws {TypeError} If `value` is a string and no long library is present.
|
|
271
|
-
*/
|
|
272
|
-
Writer.prototype.fixed64 = function write_fixed64(value) {
|
|
273
|
-
var bits = LongBits.from(value);
|
|
274
|
-
this._reserve(8);
|
|
275
|
-
writeFixed32(bits.lo, this.buf, this.pos);
|
|
276
|
-
writeFixed32(bits.hi, this.buf, this.pos + 4);
|
|
277
|
-
this.pos += 8;
|
|
278
|
-
return this;
|
|
279
|
-
};
|
|
280
|
-
|
|
281
|
-
/**
|
|
282
|
-
* Writes a signed 64 bit value as fixed 64 bits.
|
|
283
|
-
* @function
|
|
284
|
-
* @param {Long|number|string} value Value to write
|
|
285
|
-
* @returns {Writer} `this`
|
|
286
|
-
* @throws {TypeError} If `value` is a string and no long library is present.
|
|
287
|
-
*/
|
|
288
|
-
Writer.prototype.sfixed64 = Writer.prototype.fixed64;
|
|
289
|
-
|
|
290
|
-
/**
|
|
291
|
-
* Writes a float (32 bit).
|
|
292
|
-
* @function
|
|
293
|
-
* @param {number} value Value to write
|
|
294
|
-
* @returns {Writer} `this`
|
|
295
|
-
*/
|
|
296
|
-
Writer.prototype.float = function write_float(value) {
|
|
297
|
-
this._reserve(4);
|
|
298
|
-
util.float.writeFloatLE(value, this.buf, this.pos);
|
|
299
|
-
this.pos += 4;
|
|
300
|
-
return this;
|
|
301
|
-
};
|
|
302
|
-
|
|
303
|
-
/**
|
|
304
|
-
* Writes a double (64 bit float).
|
|
305
|
-
* @function
|
|
306
|
-
* @param {number} value Value to write
|
|
307
|
-
* @returns {Writer} `this`
|
|
308
|
-
*/
|
|
309
|
-
Writer.prototype.double = function write_double(value) {
|
|
310
|
-
this._reserve(8);
|
|
311
|
-
util.float.writeDoubleLE(value, this.buf, this.pos);
|
|
312
|
-
this.pos += 8;
|
|
313
|
-
return this;
|
|
314
|
-
};
|
|
315
|
-
|
|
316
|
-
/**
|
|
317
|
-
* Writes a sequence of bytes.
|
|
318
|
-
* @param {Uint8Array|string} value Buffer or base64 encoded string to write
|
|
319
|
-
* @returns {Writer} `this`
|
|
320
|
-
*/
|
|
321
|
-
Writer.prototype.bytes = function write_bytes(value) {
|
|
322
|
-
var len = value.length >>> 0;
|
|
323
|
-
if (!len) {
|
|
324
|
-
this._reserve(1);
|
|
325
|
-
this.buf[this.pos++] = 0;
|
|
326
|
-
return this;
|
|
327
|
-
}
|
|
328
|
-
if (util.isString(value)) {
|
|
329
|
-
var buf = Writer.alloc(len = base64.length(value));
|
|
330
|
-
base64.decode(value, buf, 0);
|
|
331
|
-
value = buf;
|
|
332
|
-
}
|
|
333
|
-
this.uint32(len);
|
|
334
|
-
this._reserve(len);
|
|
335
|
-
this.buf.set(value, this.pos);
|
|
336
|
-
this.pos += len;
|
|
337
|
-
return this;
|
|
338
|
-
};
|
|
339
|
-
|
|
340
|
-
/**
|
|
341
|
-
* Writes raw bytes without a tag or length prefix.
|
|
342
|
-
* @param {Uint8Array} value Raw bytes
|
|
343
|
-
* @returns {Writer} `this`
|
|
344
|
-
*/
|
|
345
|
-
Writer.prototype.raw = function write_raw(value) {
|
|
346
|
-
var len = value.length >>> 0;
|
|
347
|
-
if (!len)
|
|
348
|
-
return this;
|
|
349
|
-
this._reserve(len);
|
|
350
|
-
this.buf.set(value, this.pos);
|
|
351
|
-
this.pos += len;
|
|
352
|
-
return this;
|
|
353
|
-
};
|
|
354
|
-
|
|
355
|
-
/**
|
|
356
|
-
* Backfills the length varint.
|
|
357
|
-
* @param {number} pos Position of reserved length byte
|
|
358
|
-
* @param {number} len Length of content after length varint
|
|
359
|
-
* @returns {Writer} `this`
|
|
360
|
-
* @private
|
|
361
|
-
*/
|
|
362
|
-
Writer.prototype._delim = function _delim(pos, len) {
|
|
363
|
-
var n = sizeVarint32(len);
|
|
364
|
-
if (n > 1)
|
|
365
|
-
this.buf.copyWithin(pos + n, pos + 1, pos + 1 + len);
|
|
366
|
-
writeVarint32(len, this.buf, pos);
|
|
367
|
-
this.pos = pos + n + len;
|
|
368
|
-
return this;
|
|
369
|
-
};
|
|
370
|
-
|
|
371
|
-
/**
|
|
372
|
-
* Writes a string.
|
|
373
|
-
* @param {string} value Value to write
|
|
374
|
-
* @returns {Writer} `this`
|
|
375
|
-
*/
|
|
376
|
-
Writer.prototype.string = function write_string(value) {
|
|
377
|
-
var n = value.length;
|
|
378
|
-
if (!n) {
|
|
379
|
-
this._reserve(1);
|
|
380
|
-
this.buf[this.pos++] = 0;
|
|
381
|
-
return this;
|
|
382
|
-
}
|
|
383
|
-
if (n < 0x80) {
|
|
384
|
-
this._reserve(n * 3 + 5); // worst case
|
|
385
|
-
var lenPos = this.pos;
|
|
386
|
-
return this._delim(lenPos, utf8.write(value, this.buf, lenPos + 1));
|
|
387
|
-
}
|
|
388
|
-
var len = utf8.length(value);
|
|
389
|
-
this.uint32(len);
|
|
390
|
-
this._reserve(len);
|
|
391
|
-
if (len === value.length)
|
|
392
|
-
writeStringAscii(value, this.buf, this.pos);
|
|
393
|
-
else
|
|
394
|
-
utf8.write(value, this.buf, this.pos);
|
|
395
|
-
this.pos += len;
|
|
396
|
-
return this;
|
|
397
|
-
};
|
|
398
|
-
|
|
399
|
-
/**
|
|
400
|
-
* Writes an array of unsigned 32 bit values as a packed repeated field.
|
|
401
|
-
* @param {number[]} value Values to write
|
|
402
|
-
* @returns {Writer} `this`
|
|
403
|
-
*/
|
|
404
|
-
Writer.prototype.uint32s = function write_uint32s(value) {
|
|
405
|
-
var n = value.length;
|
|
406
|
-
this._reserve(n * 5 + 5); // worst case: 5 bytes per value + length varint
|
|
407
|
-
var buf = this.buf, lenPos = this.pos, p = lenPos + 1;
|
|
408
|
-
for (var i = 0; i < n; ++i)
|
|
409
|
-
p = writeVarint32(value[i] >>> 0, buf, p);
|
|
410
|
-
return this._delim(lenPos, p - lenPos - 1);
|
|
411
|
-
};
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Writes an array of signed 32 bit values as a packed repeated field.
|
|
415
|
-
* @param {number[]} value Values to write
|
|
416
|
-
* @returns {Writer} `this`
|
|
417
|
-
*/
|
|
418
|
-
Writer.prototype.int32s = function write_int32s(value) {
|
|
419
|
-
var n = value.length;
|
|
420
|
-
this._reserve(n * 10 + 5); // worst case: 10 bytes per negative value + length varint
|
|
421
|
-
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1, val;
|
|
422
|
-
for (var i = 0; i < n; ++i) {
|
|
423
|
-
if ((val = value[i] | 0) < 0) { // negatives are 10 bytes per spec
|
|
424
|
-
pos = writeVarint64(LongBits.fromNumber(val), buf, pos);
|
|
425
|
-
} else {
|
|
426
|
-
pos = writeVarint32(val, buf, pos);
|
|
427
|
-
}
|
|
428
|
-
}
|
|
429
|
-
return this._delim(lenPos, pos - lenPos - 1);
|
|
430
|
-
};
|
|
431
|
-
|
|
432
|
-
/**
|
|
433
|
-
* Writes an array of 32 bit values as packed, zig-zag encoded varints.
|
|
434
|
-
* @param {number[]} value Values to write
|
|
435
|
-
* @returns {Writer} `this`
|
|
436
|
-
*/
|
|
437
|
-
Writer.prototype.sint32s = function write_sint32s(value) {
|
|
438
|
-
var n = value.length;
|
|
439
|
-
this._reserve(n * 5 + 5);
|
|
440
|
-
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
|
|
441
|
-
for (var i = 0; i < n; ++i)
|
|
442
|
-
pos = writeVarint32((value[i] << 1 ^ value[i] >> 31) >>> 0, buf, pos);
|
|
443
|
-
return this._delim(lenPos, pos - lenPos - 1);
|
|
444
|
-
};
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Writes an array of unsigned 64 bit values as a packed repeated field.
|
|
448
|
-
* @param {Array.<Long|number|string>} value Values to write
|
|
449
|
-
* @returns {Writer} `this`
|
|
450
|
-
*/
|
|
451
|
-
Writer.prototype.uint64s = function write_uint64s(value) {
|
|
452
|
-
var n = value.length;
|
|
453
|
-
this._reserve(n * 10 + 5);
|
|
454
|
-
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
|
|
455
|
-
for (var i = 0; i < n; ++i) {
|
|
456
|
-
pos = writeVarint64(LongBits.from(value[i]), buf, pos);
|
|
457
|
-
}
|
|
458
|
-
return this._delim(lenPos, pos - lenPos - 1);
|
|
459
|
-
};
|
|
460
|
-
|
|
461
|
-
/**
|
|
462
|
-
* Writes an array of signed 64 bit values as a packed repeated field.
|
|
463
|
-
* @function
|
|
464
|
-
* @param {Array.<Long|number|string>} value Values to write
|
|
465
|
-
* @returns {Writer} `this`
|
|
466
|
-
*/
|
|
467
|
-
Writer.prototype.int64s = Writer.prototype.uint64s;
|
|
468
|
-
|
|
469
|
-
/**
|
|
470
|
-
* Writes an array of 64 bit values as packed, zig-zag encoded varints.
|
|
471
|
-
* @param {Array.<Long|number|string>} value Values to write
|
|
472
|
-
* @returns {Writer} `this`
|
|
473
|
-
*/
|
|
474
|
-
Writer.prototype.sint64s = function write_sint64s(value) {
|
|
475
|
-
var n = value.length;
|
|
476
|
-
this._reserve(n * 10 + 5);
|
|
477
|
-
var buf = this.buf, lenPos = this.pos, pos = lenPos + 1;
|
|
478
|
-
for (var i = 0; i < n; ++i) {
|
|
479
|
-
pos = writeVarint64(LongBits.from(value[i]).zzEncode(), buf, pos);
|
|
480
|
-
}
|
|
481
|
-
return this._delim(lenPos, pos - lenPos - 1);
|
|
482
|
-
};
|
|
483
|
-
|
|
484
|
-
/**
|
|
485
|
-
* Writes an array of boolish values as a packed repeated field.
|
|
486
|
-
* @param {boolean[]} value Values to write
|
|
487
|
-
* @returns {Writer} `this`
|
|
488
|
-
*/
|
|
489
|
-
Writer.prototype.bools = function write_bools(value) {
|
|
490
|
-
var n = value.length;
|
|
491
|
-
this.uint32(n); // one byte per value
|
|
492
|
-
this._reserve(n);
|
|
493
|
-
var buf = this.buf, p = this.pos;
|
|
494
|
-
for (var i = 0; i < n; ++i)
|
|
495
|
-
buf[p++] = value[i] ? 1 : 0;
|
|
496
|
-
this.pos += n;
|
|
497
|
-
return this;
|
|
498
|
-
};
|
|
499
|
-
|
|
500
|
-
// The view allocation only pays off when amortized over enough writes
|
|
501
|
-
var VIEW_THRESHOLD_FLOAT = 16,
|
|
502
|
-
VIEW_THRESHOLD_INT = 128;
|
|
503
|
-
|
|
504
|
-
function getLazyView(writer, count, threshold) {
|
|
505
|
-
var view = writer.view;
|
|
506
|
-
if (view || count < threshold)
|
|
507
|
-
return view;
|
|
508
|
-
var buf = writer.buf;
|
|
509
|
-
return writer.view = new DataView(buf.buffer, buf.byteOffset, buf.byteLength);
|
|
510
|
-
}
|
|
511
|
-
|
|
512
|
-
/**
|
|
513
|
-
* Writes an array of unsigned 32 bit values as packed, fixed 32 bits.
|
|
514
|
-
* @param {number[]} value Values to write
|
|
515
|
-
* @returns {Writer} `this`
|
|
516
|
-
*/
|
|
517
|
-
Writer.prototype.fixed32s = function write_fixed32s(value) {
|
|
518
|
-
var n = value.length, bytes = n * 4;
|
|
519
|
-
this.uint32(bytes); // length is known exactly
|
|
520
|
-
this._reserve(bytes);
|
|
521
|
-
var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_INT);
|
|
522
|
-
if (dv)
|
|
523
|
-
for (i = 0; i < n; ++i) { dv.setUint32(p, value[i] >>> 0, true); p += 4; }
|
|
524
|
-
else {
|
|
525
|
-
var buf = this.buf;
|
|
526
|
-
for (i = 0; i < n; ++i) { writeFixed32(value[i] >>> 0, buf, p); p += 4; }
|
|
527
|
-
}
|
|
528
|
-
this.pos += bytes;
|
|
529
|
-
return this;
|
|
530
|
-
};
|
|
531
|
-
|
|
532
|
-
/**
|
|
533
|
-
* Writes an array of signed 32 bit values as packed, fixed 32 bits.
|
|
534
|
-
* @function
|
|
535
|
-
* @param {number[]} value Values to write
|
|
536
|
-
* @returns {Writer} `this`
|
|
537
|
-
*/
|
|
538
|
-
Writer.prototype.sfixed32s = Writer.prototype.fixed32s;
|
|
539
|
-
|
|
540
|
-
/**
|
|
541
|
-
* Writes an array of unsigned 64 bit values as packed, fixed 64 bits.
|
|
542
|
-
* @param {Array.<Long|number|string>} value Values to write
|
|
543
|
-
* @returns {Writer} `this`
|
|
544
|
-
*/
|
|
545
|
-
Writer.prototype.fixed64s = function write_fixed64s(value) {
|
|
546
|
-
var n = value.length, bytes = n * 8;
|
|
547
|
-
this.uint32(bytes);
|
|
548
|
-
this._reserve(bytes);
|
|
549
|
-
var p = this.pos, i, bits, dv = getLazyView(this, n, VIEW_THRESHOLD_INT);
|
|
550
|
-
if (dv)
|
|
551
|
-
for (i = 0; i < n; ++i) { bits = LongBits.from(value[i]); dv.setUint32(p, bits.lo, true); dv.setUint32(p + 4, bits.hi, true); p += 8; }
|
|
552
|
-
else {
|
|
553
|
-
var buf = this.buf;
|
|
554
|
-
for (i = 0; i < n; ++i) { bits = LongBits.from(value[i]); writeFixed32(bits.lo, buf, p); writeFixed32(bits.hi, buf, p + 4); p += 8; }
|
|
555
|
-
}
|
|
556
|
-
this.pos += bytes;
|
|
557
|
-
return this;
|
|
558
|
-
};
|
|
559
|
-
|
|
560
|
-
/**
|
|
561
|
-
* Writes an array of signed 64 bit values as packed, fixed 64 bits.
|
|
562
|
-
* @function
|
|
563
|
-
* @param {Array.<Long|number|string>} value Values to write
|
|
564
|
-
* @returns {Writer} `this`
|
|
565
|
-
*/
|
|
566
|
-
Writer.prototype.sfixed64s = Writer.prototype.fixed64s;
|
|
567
|
-
|
|
568
|
-
/**
|
|
569
|
-
* Writes an array of floats (32 bit) as a packed repeated field.
|
|
570
|
-
* @param {number[]} value Values to write
|
|
571
|
-
* @returns {Writer} `this`
|
|
572
|
-
*/
|
|
573
|
-
Writer.prototype.floats = function write_floats(value) {
|
|
574
|
-
var n = value.length, bytes = n * 4;
|
|
575
|
-
this.uint32(bytes);
|
|
576
|
-
this._reserve(bytes);
|
|
577
|
-
var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_FLOAT);
|
|
578
|
-
if (dv)
|
|
579
|
-
for (i = 0; i < n; ++i) { dv.setFloat32(p, value[i], true); p += 4; }
|
|
580
|
-
else {
|
|
581
|
-
var buf = this.buf;
|
|
582
|
-
for (i = 0; i < n; ++i) { util.float.writeFloatLE(value[i], buf, p); p += 4; }
|
|
583
|
-
}
|
|
584
|
-
this.pos += bytes;
|
|
585
|
-
return this;
|
|
586
|
-
};
|
|
587
|
-
|
|
588
|
-
/**
|
|
589
|
-
* Writes an array of doubles (64 bit float) as a packed repeated field.
|
|
590
|
-
* @param {number[]} value Values to write
|
|
591
|
-
* @returns {Writer} `this`
|
|
592
|
-
*/
|
|
593
|
-
Writer.prototype.doubles = function write_doubles(value) {
|
|
594
|
-
var n = value.length, bytes = n * 8;
|
|
595
|
-
this.uint32(bytes);
|
|
596
|
-
this._reserve(bytes);
|
|
597
|
-
var p = this.pos, i, dv = getLazyView(this, n, VIEW_THRESHOLD_FLOAT);
|
|
598
|
-
if (dv)
|
|
599
|
-
for (i = 0; i < n; ++i) { dv.setFloat64(p, value[i], true); p += 8; }
|
|
600
|
-
else {
|
|
601
|
-
var buf = this.buf;
|
|
602
|
-
for (i = 0; i < n; ++i) { util.float.writeDoubleLE(value[i], buf, p); p += 8; }
|
|
603
|
-
}
|
|
604
|
-
this.pos += bytes;
|
|
605
|
-
return this;
|
|
606
|
-
};
|
|
607
|
-
|
|
608
|
-
/**
|
|
609
|
-
* Forks this writer's state by pushing it to a stack.
|
|
610
|
-
* @returns {Writer} `this`
|
|
611
|
-
*/
|
|
612
|
-
Writer.prototype.fork = function fork() {
|
|
613
|
-
this._reserve(1);
|
|
614
|
-
(this.states || (this.states = [])).push(this.pos);
|
|
615
|
-
this.pos += 1;
|
|
616
|
-
return this;
|
|
617
|
-
};
|
|
618
|
-
|
|
619
|
-
/**
|
|
620
|
-
* Resets this instance to the last state.
|
|
621
|
-
* @returns {Writer} `this`
|
|
622
|
-
*/
|
|
623
|
-
Writer.prototype.reset = function reset() {
|
|
624
|
-
var states = this.states;
|
|
625
|
-
if (states && states.length) {
|
|
626
|
-
this.pos = states.pop();
|
|
627
|
-
} else {
|
|
628
|
-
this.pos = 0;
|
|
629
|
-
}
|
|
630
|
-
return this;
|
|
631
|
-
};
|
|
632
|
-
|
|
633
|
-
/**
|
|
634
|
-
* Resets to the last state and prepends the fork state's current write length as a varint.
|
|
635
|
-
* @returns {Writer} `this`
|
|
636
|
-
*/
|
|
637
|
-
Writer.prototype.ldelim = function ldelim() {
|
|
638
|
-
var states = this.states,
|
|
639
|
-
len,
|
|
640
|
-
vlen;
|
|
641
|
-
if (states && states.length) {
|
|
642
|
-
var lenPos = states.pop();
|
|
643
|
-
len = this.pos - lenPos - 1;
|
|
644
|
-
vlen = sizeVarint32(len);
|
|
645
|
-
if (vlen > 1) { // grow the reserved single byte and shift content forward
|
|
646
|
-
this._reserve(vlen - 1);
|
|
647
|
-
this.buf.copyWithin(lenPos + vlen, lenPos + 1, lenPos + 1 + len);
|
|
648
|
-
this.pos += vlen - 1;
|
|
649
|
-
writeVarint32(len, this.buf, lenPos);
|
|
650
|
-
} else {
|
|
651
|
-
this.buf[lenPos] = len;
|
|
652
|
-
}
|
|
653
|
-
} else { // not forked: prefix the entire buffer with its length
|
|
654
|
-
// TODO: Compatibility with older generated code.
|
|
655
|
-
// Remove this branch in the next major release.
|
|
656
|
-
len = this.pos;
|
|
657
|
-
vlen = sizeVarint32(len);
|
|
658
|
-
this._reserve(vlen);
|
|
659
|
-
this.buf.copyWithin(vlen, 0, len);
|
|
660
|
-
writeVarint32(len, this.buf, 0);
|
|
661
|
-
this.pos += vlen;
|
|
662
|
-
}
|
|
663
|
-
return this;
|
|
664
|
-
};
|
|
665
|
-
|
|
666
|
-
/**
|
|
667
|
-
* Finishes the write operation.
|
|
668
|
-
* Returns a buffer sized to the written data by default.
|
|
669
|
-
* @param {boolean} [shared=false] Whether to return a shared view instead of a unique copy
|
|
670
|
-
* @returns {Uint8Array} Finished buffer
|
|
671
|
-
*/
|
|
672
|
-
Writer.prototype.finish = function finish(shared) {
|
|
673
|
-
if (shared)
|
|
674
|
-
return this.buf.subarray(0, this.pos);
|
|
675
|
-
var buf = this.constructor.alloc(this.pos);
|
|
676
|
-
buf.set(this.buf.subarray(0, this.pos), 0);
|
|
677
|
-
return buf;
|
|
678
|
-
};
|
|
679
|
-
|
|
680
|
-
/**
|
|
681
|
-
* Finishes the write operation, writing into the provided buffer.
|
|
682
|
-
* The caller must ensure that `buf` has enough space starting at `offset`
|
|
683
|
-
* to hold {@link Writer#pos} bytes.
|
|
684
|
-
* @param {T} buf Target buffer
|
|
685
|
-
* @param {number} [offset=0] Offset to start writing at
|
|
686
|
-
* @returns {T} The provided buffer
|
|
687
|
-
* @template T extends Uint8Array
|
|
688
|
-
*/
|
|
689
|
-
Writer.prototype.finishInto = function finishInto(buf, offset) {
|
|
690
|
-
if (offset === undefined)
|
|
691
|
-
offset = 0;
|
|
692
|
-
buf.set(this.buf.subarray(0, this.pos), offset);
|
|
693
|
-
return buf;
|
|
694
|
-
};
|
|
695
|
-
|
|
696
|
-
Writer._configure = function(BufferWriter_) {
|
|
697
|
-
BufferWriter = BufferWriter_;
|
|
698
|
-
Writer.create = create();
|
|
699
|
-
BufferWriter._configure();
|
|
700
|
-
};
|