Using variables from parent scope in a 'choice'
See original GitHub issueHey Keichi
I was wondering if it’s somehow possible to use a variable from a parent scope from inside a choice type item. If it’s not implemented I would greatly appreciate a pointer on how to do so. My use-case is parsing of a DNSRecord:
var TXTRecord = new Parser()
.string('txt' { length: 'rdlength' }) // rdlength is undefined
var answer = new Parser()
.nest('name', { type: fqdn_pretty })
.uint16be('type')
.uint16be('class')
.uint32be('ttl')
.uint16be('rdlength')
.choice('record', {
tag: 'type',
choices: {
0x01: ARecord,
0x02: PTRRecord, 0x05: PTRRecord, 0x0c: PTRRecord,
0x10: TXTRecord,
0x21: SRVRecord,
0x1C: AAAARecord
},
defaultChoice: new Parser().buffer('rdata', { length: 'rdlength' }) //rdlength is undefined
})
I enjoy working with your module, thanks for the help in advance!
Issue Analytics
- State:
- Created 9 years ago
- Reactions:1
- Comments:15 (3 by maintainers)
Top Results From Across the Web
cmake - Variables set with PARENT_SCOPE are empty in the ...
If PARENT_SCOPE is present, the variable will be set in the scope above the current scope. Each new directory or function creates a...
Read more >Setting CMake variables in the parent scope - Bastian Rieck
This option can be used in SET() statements of subordinate modules to set a variable in the scope of the calling module, i.e....
Read more >about Scopes - PowerShell | Microsoft Learn
The calling scope is the parent scope. ... It includes all the variables that have the AllScope option, plus some automatic variables.
Read more >Explanation of CMake variable scope , add_subdirectory vs ...
In this post, I will explain the scope of CMake variables with simple ... It sets variable A to “Parent” , then call...
Read more >Some notes on CMake variables and scopes - Matthew Gaudet
Variables are set in CMake using set : ... Each scope when created maintains a link to its parent scope, and so you...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I understand your situation. Unfortunately, there’s currently no way to do that. One idea would be to introduce a special variable name like
$parent
, with which you can reference the parent scope:defaultChoice: new Parser().buffer('rdata', { length: '$parent.rdlength' })
What do you think about this?+1