Skip to content

Commit

Permalink
fix encode issue
Browse files Browse the repository at this point in the history
  • Loading branch information
dangell7 committed Nov 27, 2024
1 parent 8f2153c commit de41aa4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@transia/binary-models",
"version": "1.0.0",
"version": "1.0.2",
"description": "Binary Models",
"main": "dist/npm/src/index.js",
"files": [
Expand Down
8 changes: 8 additions & 0 deletions src/encode.ts
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,14 @@ export function varStringToHex(
const prefixLength = lengthToHex(value.length, maxStringLength)
const content = Buffer.from(value, 'utf8').toString('hex')
const paddedContent = content.padEnd(maxStringLength * 2, '0')
if (
(prefixLength + paddedContent).toUpperCase().length >
maxStringLength * 2 + 2
) {
throw Error(
`Encoded string length ${value.length} exceeds max length of ${maxStringLength}`
)
}
return (prefixLength + paddedContent).toUpperCase()
}

Expand Down

0 comments on commit de41aa4

Please sign in to comment.