Comments (1)
Try something like that:
meta:
id: dat
application: script
endian: le
seq:
- id: commands
repeat: eos
type: script_cmd
types:
script_cmd:
seq:
- id: cmd_start
contents: [0x23]
- id: num
type: u2
- id: params
type: strz
encoding: SJIS
terminator: 0x23
consume: false
eos-error: false
That allows to parse the file you've provided without errors. However, it is still probably not a very good idea to parse the file using "parse anything up to 0x23" semantic - real parsing code rarely use something like that, and parsing params
as a 0x23-terminated string is probably not what you want anyway.
In 99% of cases I've seen (with notable exception of terminator-based strings encoding), if we're dealing with something like a bytecode (i.e. [opcode] [parameters]
), variable length parameters depend on the opcode itself, not the termination symbol. Notably, it's generally a very bad idea to add "termination bytes" like 0x23, given that some opcode might have genuine integer 0x23 as a parameter.
It is possible to implement something like "read bytes until some termination byte / sequence of bytes, and then reinterpret them as some complex subtype" in future, but so far I haven't seen a single example where such a semantic would be helpful. I'd be grateful if you'll prove me wrong :)
from kaitai_struct.
Related Issues (20)
- Warnings (and maybe errors) are reported in unstable order HOT 1
- Warning about encoding name is reported even for types without explicit `encoding`
- `_root` / `_parent` chain broken by recursive use of the top-level type
- `bytes.to_s(encoding)` should validate the passed encoding
- Using enum members as int is broken in ruby HOT 3
- Add explanation to errors `spec_build_failed` and `format_build_failed` on https://ci.kaitai.io/ HOT 1
- C++: the type of all integer constants wrongly deduced as `int32_t` HOT 1
- ci.kaitai.io: use snake_case for test names instead of PascalCase HOT 1
- Java: byte array elements propageted to `int` as signed values (0xFF -> -1 instead of 255)
- Unclear expected values for integer division HOT 4
- Invalid Java code generated: Incompatible types: possible lossy conversion from int to byte HOT 3
- Ruby, Lua: missing `require`s not detected by tests due to `require` leaks HOT 1
- Invalid Java code generated: Switch selectors cannot be of type "long" HOT 1
- Recursive decoding of value HOT 3
- Python: Fix missing `assertRaisesRegexp` method in Python 3.12
- C++11: segfault in debug mode for arrays HOT 1
- Construct: the order of `Computed` fields matter
- How to disable building documentation and JS?
- Health of the project?
- Support for Julia HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from kaitai_struct.