Skip to content

Commit

Permalink
fmt
Browse files Browse the repository at this point in the history
  • Loading branch information
marcus-pousette committed Dec 3, 2022
1 parent 1660012 commit 46eb0b4
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@
"dependencies": {
"@protobufjs/utf8": "^1.1.0"
}
}
}
15 changes: 15 additions & 0 deletions src/__tests__/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,21 @@ describe("number", () => {
expect(deserialized.a).toEqual(3);
});

test("u8 max", () => {
class Struct {
@field({ type: "u8" })
public a: number;

constructor(a: number) {
this.a = a;
}
}
const instance = new Struct(255);
const buf = serialize(instance);
const deserialized = deserialize(buf, Struct);
expect(deserialized.a).toEqual(255);
});

test("u16", () => {
class Struct {
@field({ type: "u16" })
Expand Down
2 changes: 1 addition & 1 deletion src/bigint.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ export const readUInt16LE = (buffer: Uint8Array, offset: number) => {



const checkInt = (value: number, min: number | bigint, max: number | bigint, byteLength: number) => {
export const checkInt = (value: number, min: number | bigint, max: number | bigint, byteLength: number) => {
if (value > max || value < min) {
const n = typeof min === 'bigint' ? 'n' : '';
let range;
Expand Down
3 changes: 2 additions & 1 deletion src/binary.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { toBigIntLE, writeBufferLEBigInt, writeUInt32LE, readUInt32LE, readUInt16LE, writeUInt16LE, readBigUInt64LE, readUIntLE } from './bigint.js';
import { toBigIntLE, writeBufferLEBigInt, writeUInt32LE, readUInt32LE, readUInt16LE, writeUInt16LE, readBigUInt64LE, readUIntLE, checkInt } from './bigint.js';
import { BorshError } from "./error.js";
import utf8 from '@protobufjs/utf8';

Expand Down Expand Up @@ -29,6 +29,7 @@ export class BinaryWriter {

public u8(value: number) {
this.maybeResize(1);
checkInt(value, 0, 255, 1);
this._buf[this._length] = value;
this._length += 1;
}
Expand Down

0 comments on commit 46eb0b4

Please sign in to comment.