Skip to content

Commit

Permalink
feat: Update code
Browse files Browse the repository at this point in the history
  • Loading branch information
nuintun committed Aug 31, 2023
1 parent 1189e13 commit d9b78c9
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
7 changes: 3 additions & 4 deletions packages/core/src/decoder/BitMatrixParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ export class BitMatrixParser {
const versionNumber = toInt32((size - 17) / 4);

if (versionNumber < 1) {
// TODO 重写错误消息
throw new Error('');
throw new Error('illegal version');
}

if (versionNumber <= 6) {
Expand Down Expand Up @@ -60,7 +59,7 @@ export class BitMatrixParser {

if (version.size > size) {
// TODO 重写错误消息
throw new Error('');
throw new Error('matrix size too small for version');
}

return version;
Expand Down Expand Up @@ -154,7 +153,7 @@ export class BitMatrixParser {

// TODO 重写错误消息
if (byteOffset !== ecBlocks.numTotalCodewords) {
throw new Error('byteOffset !== ecBlocks.numTotalCodewords');
throw new Error('illegal codewords length');
}

return codewords;
Expand Down
2 changes: 2 additions & 0 deletions packages/core/src/decoder/utils/source.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,12 +32,14 @@ function parseECIValue(source: BitSource): number {
// just one byte
return firstByte & 0x7f;
}

if ((firstByte & 0xc0) == 0x80) {
// two bytes
const secondByte = source.read(8);

return ((firstByte & 0x3f) << 8) | secondByte;
}

if ((firstByte & 0xe0) == 0xc0) {
// three bytes
const secondThirdBytes = source.read(16);
Expand Down

0 comments on commit d9b78c9

Please sign in to comment.