Parsing issue with empty Arrays
Nobody has claimed this yet.
- Dominant language
- JavaScript
- Stars
- 10
- Forks
- 3
- Avg merge
- 1m
- Merged PRs (30d)
- 2
Description
Watch this simple example using the binopsy parser vs. the original binary-parser. We expect to end up with the same result, but some data is missing when using binopsy.
const Binopsy = require('binopsy').Parser;
const BinaryParser = require('binary-parser').Parser;
function makeParser(Parser) {
const inner = Parser.start()
.string('airportCode', {
length: 3,
})
.uint8('count')
.array('subs', {
type: Parser.start()
.uint8('val'),
length: 'count',
});
const outter = Parser.start()
.uint8('type')
.choice('inner', {
tag: 'type',
choices: {
1: inner,
2: inner,
},
});
return outter;
}
const binopsy = makeParser(Binopsy);
const binaryParser = makeParser(BinaryParser);
const buf = binopsy.serialize({
type: 1,
inner: {
airportCode: 'BER',
count: 0,
subs: [],
},
});
console.log(buf);
console.log(JSON.stringify(binopsy.parse(buf), null, 2));
console.log(JSON.stringify(binaryParser.parse(buf), null, 2));
The output:
<Buffer 01 42 45 52 00>
{
"type": 1,
"inner": null
}
{
"type": 1,
"inner": {
"airportCode": "BER",
"count": 0,
"subs": []
}
}
Any ideas on how to fix this?
Thanks anyway for the nice serializing feature!
BR,
Martin
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by running the JavaScript reproducer in the issue and compare the serialized output and parsed results from binopsy and binary-parser. Trace the array and choice parser entry points involved in parsing a zero-length subs array; done means the parsed result preserves the inner object with airportCode, count, and an empty subs array.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100