kaitai_struct_compiler icon indicating copy to clipboard operation
kaitai_struct_compiler copied to clipboard

Custom Scan enhancement #538

Open rodmartin30 opened this issue 6 years ago • 2 comments

Adding first things for custom scan and simulating terminator byte.

rodmartin30 avatar Jun 05 '19 17:06 rodmartin30

Talking with @GreyCat he noticed me some things:

I've taken a look, so on a broader scale: I won't touch BytesEosType and BytesTerminatedType — I'd say that there's very little value in having both size + scan-end support at once, or terminator + scan-end So, BytesScanEndType alone would probably more than enough.

Should I extend BytesType with ScanEnd? or maybe it would be better do something like this:

case class BytesScanEndType(
    override val process: Option[ProcessExpr],
    override val scanEnd: Option[ScanExpr] = None
  ) extends BytesType with ScanEnd

Also, for ScanExpr, it's probably just enough to have ScanCustom arguments right in the ScanExpr, and avoid doing that "trait inherited by multiple classes" thing, and then switching it over every time like this: https://github.com/kaitai-io/kaitai_struct_compiler/compare/538#diff-121a1b8f73b9f24552fa03a24f589eedR191 you can basically remove ScanExpr, replace every time it's mentioned with ScanCustom, and rename ScanCustom to ScanExpr

rodmartin30 avatar Jun 05 '19 17:06 rodmartin30

case class BytesScanEndType(
    override val process: Option[ProcessExpr],
    override val scanEnd: Option[ScanExpr] = None
  ) extends BytesType with ScanEnd

Yep, this looks like the best solution: there's no need to add that functionality to every bytes type, a dedicated feature to will be the best.

GreyCat avatar Jun 05 '19 18:06 GreyCat