将数组参数传递给 Kaitai Struct 用户定义类型
Passing array parameter to Kaitai Struct user defined type
我正在尝试使用 Kaitai Struct 来解码一些数据。
我需要传递一个数组参数,但是ksc报错了。
以下是示例代码:
meta:
id: cat_34
seq:
- id: test1
type: fixed([0,1,2])
types:
fixed:
params:
- id: f_size
#no type is just an array
seq:
- id: val
type: u1
repeat: expr
repeat-expr: f_size[1] #trying to use second value of array.
它给出了以下错误:
cat_34: /types/fixed/seq/0/repeat-expr: 无法将操作 [] 应用于 CalcBytesType
参数声明中没有类型(或使用 type: bytes
)会产生 字节数组 类型(又称 "CalcBytesType"),这与 真正的阵列 的东西。
在这种情况下,您遇到了一个错误,即操作 []
未在 Kaitai Struct v0.8 及更低版本中实现,而在 0.9 中是 only fixed recently and not for all targets 不稳定。因此,您的选择之一是升级到 v0.9+。
作为一种解决方法,您可能希望坚持使用真正的数组 - 即不传递 [0, 1, 2]
,而是使用 [0, 1, 2].as<u1[]>
。这将适用于所有版本,但会产生 (1) 可能效率较低的真实数组,(2) 可能不受支持的数组实例化。
我正在尝试使用 Kaitai Struct 来解码一些数据。 我需要传递一个数组参数,但是ksc报错了。 以下是示例代码:
meta:
id: cat_34
seq:
- id: test1
type: fixed([0,1,2])
types:
fixed:
params:
- id: f_size
#no type is just an array
seq:
- id: val
type: u1
repeat: expr
repeat-expr: f_size[1] #trying to use second value of array.
它给出了以下错误: cat_34: /types/fixed/seq/0/repeat-expr: 无法将操作 [] 应用于 CalcBytesType
参数声明中没有类型(或使用 type: bytes
)会产生 字节数组 类型(又称 "CalcBytesType"),这与 真正的阵列 的东西。
在这种情况下,您遇到了一个错误,即操作 []
未在 Kaitai Struct v0.8 及更低版本中实现,而在 0.9 中是 only fixed recently and not for all targets 不稳定。因此,您的选择之一是升级到 v0.9+。
作为一种解决方法,您可能希望坚持使用真正的数组 - 即不传递 [0, 1, 2]
,而是使用 [0, 1, 2].as<u1[]>
。这将适用于所有版本,但会产生 (1) 可能效率较低的真实数组,(2) 可能不受支持的数组实例化。