-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
return lengthcode from emHeaders for PL_CDR2
- Loading branch information
Showing
4 changed files
with
134 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
export function getLengthCodeForObjectSize(objectSize: number): number { | ||
let defaultLengthCode; | ||
|
||
switch (objectSize) { | ||
case 1: | ||
defaultLengthCode = 0; | ||
break; | ||
case 2: | ||
defaultLengthCode = 1; | ||
break; | ||
case 4: | ||
defaultLengthCode = 2; | ||
break; | ||
case 8: | ||
defaultLengthCode = 3; | ||
break; | ||
} | ||
|
||
if (defaultLengthCode == undefined) { | ||
// Not currently supporting writing of lengthCodes > 4 | ||
if (objectSize > 0xffffffff) { | ||
throw Error( | ||
`Object size ${objectSize} for EMHEADER too large without specifying length code. Max size is ${0xffffffff}`, | ||
); | ||
} | ||
defaultLengthCode = 4; | ||
} | ||
return defaultLengthCode; | ||
} | ||
|
||
export const lengthCodeToObjectSizes = { | ||
0: 1, | ||
1: 2, | ||
2: 4, | ||
3: 8, | ||
}; |