From 50accfafa11bf1c2e591faa85c194e33c90268e0 Mon Sep 17 00:00:00 2001 From: Valentin Ochs Date: Wed, 30 Dec 2020 07:47:22 +0100 Subject: [PATCH] More enums, and conditional evaluation --- 08_enums.ksy | 37 +++++++++++++++++++++++++------------ 1 file changed, 25 insertions(+), 12 deletions(-) diff --git a/08_enums.ksy b/08_enums.ksy index 1e4aeac..e3f9186 100644 --- a/08_enums.ksy +++ b/08_enums.ksy @@ -5,23 +5,28 @@ meta: endian: le seq: - id: magic - contents: "RIFF" - size: 4 + # Could assert using contents here, but + # just make sections conditional later + #contents: "RIFF" + type: u4be + enum: fourcc - id: size type: u4 - id: wave_str - contents: "WAVE" - size: 4 + #contents: "WAVE" + type: u4be + enum: fourcc - id: sections type: section repeat: eos + if: 'magic == fourcc::riff and wave_str == fourcc::wave' instances: {} types: section: seq: - id: name - type: str - size: 4 + type: u4be # Big endian! + enum: fourcc - id: size type: u4 - id: content @@ -29,11 +34,11 @@ types: type: switch-on: name cases: - '"fmt "': fmt - '"data"': data - '"fact"': fact - '"PEAK"': peak - '"LIST"': list + 'fourcc::fmt': fmt + 'fourcc::data': data + 'fourcc::fact': fact + 'fourcc::peak': peak + 'fourcc::list': list fmt: seq: - id: type @@ -56,7 +61,7 @@ types: type: switch-on: _root.sections[0].name cases: - '"fmt "': sample(_root.sections[0].content.as.type, _root.sections[0].content.as.bits_per_unit) + 'fourcc::fmt': sample(_root.sections[0].content.as.type, _root.sections[0].content.as.bits_per_unit) _: u1 repeat: eos types: @@ -129,6 +134,14 @@ types: type: strz size: size enums: + fourcc: + 0x52494646: 'riff' + 0x57415645: 'wave' + 0x666d7420: 'fmt' + 0x66616374: 'fact' + 0x5045414b: 'peak' + 0x64617461: 'data' + 0x4c495354: 'list' encoding_type_enum: 1: 'int' 3: 'float'