Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
cramEncoding(majorVersion) {
const parser = new Parser()
.namely('cramEncoding')
.itf8('codecId')
.itf8('parametersBytes')
.choice('parameters', {
tag: 'codecId',
choices: {
0: new Parser(), // NULL
1: new Parser().itf8('blockContentId'), // EXTERNAL
2: new Parser().itf8('offset').itf8('M'), // GOLOMB,
// HUFFMAN_INT
3: Parser.start()
.itf8('numCodes')
.array('symbols', { length: 'numCodes', type: singleItf8 })
.itf8('numLengths')
.array('bitLengths', { length: 'numLengths', type: singleItf8 }),
4: Parser.start() // BYTE_ARRAY_LEN
.nest('lengthsEncoding', { type: 'cramEncoding' })
.nest('valuesEncoding', { type: 'cramEncoding' }),
// BYTE_ARRAY_STOP is a little different for CRAM v1
5: new Parser()
.uint8('stopByte')
[majorVersion > 1 ? 'itf8' : 'int']('blockContentId'),
6: new Parser().itf8('offset').itf8('length'), // BETA
7: new Parser().itf8('offset').itf8('K'), // SUBEXP
8: new Parser().itf8('offset').itf8('log2m'), // GOLOMB_RICE
9: new Parser().itf8('offset'), // GAMMA
},
.namely('cramEncoding')
.itf8('codecId')
.itf8('parametersBytes')
.choice('parameters', {
tag: 'codecId',
choices: {
0: new Parser(), // NULL
1: new Parser().itf8('blockContentId'), // EXTERNAL
2: new Parser().itf8('offset').itf8('M'), // GOLOMB,
// HUFFMAN_INT
3: Parser.start()
.itf8('numCodes')
.array('symbols', { length: 'numCodes', type: singleItf8 })
.itf8('numLengths')
.array('bitLengths', { length: 'numLengths', type: singleItf8 }),
4: Parser.start() // BYTE_ARRAY_LEN
.nest('lengthsEncoding', { type: 'cramEncoding' })
.nest('valuesEncoding', { type: 'cramEncoding' }),
// BYTE_ARRAY_STOP is a little different for CRAM v1
5: new Parser()
.uint8('stopByte')
[majorVersion > 1 ? 'itf8' : 'int']('blockContentId'),
6: new Parser().itf8('offset').itf8('length'), // BETA
7: new Parser().itf8('offset').itf8('K'), // SUBEXP
8: new Parser().itf8('offset').itf8('log2m'), // GOLOMB_RICE
9: new Parser().itf8('offset'), // GAMMA
},
})
return { parser }
},