Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions packages/protons-runtime/src/utils/longbits.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ export class LongBits {
/**
* Low bits
*/
this.lo = lo | 0
this.lo = lo >>> 0

/**
* High bits
*/
this.hi = hi | 0
this.hi = hi >>> 0
}

/**
Expand Down
24 changes: 24 additions & 0 deletions packages/protons/test/longbits.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { expect } from 'aegir/chai'
import { writer } from 'protons-runtime'

// low word in [2^31, 2^32) used to be stored signed and written as one byte
describe('64-bit varints', () => {
const cases: Array<[bigint, number[]]> = [
[2147483647n, [0xff, 0xff, 0xff, 0xff, 0x07]],
[2147483648n, [0x80, 0x80, 0x80, 0x80, 0x08]],
[3221225472n, [0x80, 0x80, 0x80, 0x80, 0x0c]],
[4294967295n, [0xff, 0xff, 0xff, 0xff, 0x0f]],
[4294967296n, [0x80, 0x80, 0x80, 0x80, 0x10]]
]

for (const method of ['uint64', 'int64'] as const) {
for (const [value, bytes] of cases) {
it(`should encode ${method} ${value}`, () => {
const w = writer()
w[method](value)

expect(w.finish()).to.equalBytes(bytes)
})
}
}
})
Loading