Skip to content

Commit f2b0e50

Browse files
rafi-kamalcopybara-github
authored andcommitted
Project import generated by Copybara
PiperOrigin-RevId: 299970447
1 parent ff07670 commit f2b0e50

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

experimental/runtime/kernel/buffer_decoder.js

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -279,15 +279,14 @@ class BufferDecoder {
279279
}
280280

281281
/**
282-
* Skips over a varint at a given index.
283-
* @param {number} index Start of the data.
282+
* Skips over a varint from the current cursor position.
284283
* @package
285284
*/
286-
skipVarint(index) {
287-
this.cursor_ = index;
285+
skipVarint() {
286+
const startIndex = this.cursor_;
288287
while (this.dataView_.getUint8(this.cursor_++) & 0x80) {
289288
}
290-
checkCriticalPositionIndex(this.cursor_, index + 10);
289+
checkCriticalPositionIndex(this.cursor_, startIndex + 10);
291290
}
292291

293292
/**

experimental/runtime/kernel/buffer_decoder_test.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ describe('Skip varint does', () => {
4141
it('skip a varint', () => {
4242
const bufferDecoder =
4343
BufferDecoder.fromArrayBuffer(createArrayBuffer(0x01));
44-
bufferDecoder.skipVarint(0);
44+
bufferDecoder.skipVarint();
4545
expect(bufferDecoder.cursor()).toBe(1);
4646
});
4747

@@ -50,21 +50,21 @@ describe('Skip varint does', () => {
5050
0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x80, 0x00));
5151

5252
if (CHECK_CRITICAL_STATE) {
53-
expect(() => bufferDecoder.skipVarint(0)).toThrow();
53+
expect(() => bufferDecoder.skipVarint()).toThrow();
5454
} else {
5555
// Note in unchecked mode we produce invalid output for invalid inputs.
5656
// This test just documents our behavior in those cases.
5757
// These values might change at any point and are not considered
5858
// what the implementation should be doing here.
59-
bufferDecoder.skipVarint(0);
59+
bufferDecoder.skipVarint();
6060
expect(bufferDecoder.cursor()).toBe(11);
6161
}
6262
});
6363

6464
it('fail when varint is beyond end of underlying array', () => {
6565
const bufferDecoder =
6666
BufferDecoder.fromArrayBuffer(createArrayBuffer(0x80, 0x80));
67-
expect(() => bufferDecoder.skipVarint(0)).toThrow();
67+
expect(() => bufferDecoder.skipVarint()).toThrow();
6868
});
6969
});
7070

experimental/runtime/kernel/indexer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ function skipField_(bufferDecoder, wireType, fieldNumber) {
8585
case WireType.VARINT:
8686
checkCriticalElementIndex(
8787
bufferDecoder.cursor(), bufferDecoder.endIndex());
88-
bufferDecoder.skipVarint(bufferDecoder.cursor());
88+
bufferDecoder.skipVarint();
8989
return false;
9090
case WireType.FIXED64:
9191
bufferDecoder.skip(8);

experimental/runtime/kernel/writer.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,8 @@ class Writer {
451451
getLength_(bufferDecoder, start, wireType) {
452452
switch (wireType) {
453453
case WireType.VARINT:
454-
bufferDecoder.skipVarint(start);
454+
bufferDecoder.setCursor(start);
455+
bufferDecoder.skipVarint();
455456
return bufferDecoder.cursor() - start;
456457
case WireType.FIXED64:
457458
return 8;

0 commit comments

Comments
 (0)