Rust Flatbuffers索引超出范围错误

问题描述 投票:0回答:1

我有这样的架构:

table BinaryValue {
    buf: [ubyte];
}

table MyValue {
    ...[some other fields]
    my_binary_value: BinaryValue;
}

[当我尝试像这样访问my_binary_value时,我收到此消息:

'index 3136 out of range for slice of length 140'

我用来访问的代码是:

        let my_binary_value = match op.my_binary_value() {
            Some(binary_value) => match binary_value.buf() {
                Some(buf) => {
                    println!(
                        "buf: {:?}",
                        buf
                    );
                    buf
                }
                None => {
                    return Err(format_err!("The my_binary_value is required."));
                }
            },
            None => {
                return Err(format_err!(
                    "The binary_value is required"
                ));
            }
        };

此行出现了紧急情况:

let my_binary_value = match op.my_binary_value() {

我打印出binary_value的值,看起来不错(已截断):

Some(BinaryValue { _tab: Table { buf: [20, 0, 0, 0, 48, 52, ...], loc: 60 } })

这里是生成的flatbuffer代码:

#[inline]
  pub fn buf(&self) -> Option<&'a [u8]> {
    self._tab.get::<flatbuffers::ForwardsUOffset<flatbuffers::Vector<'a, u8>>>(BinaryValue::VT_BUF, None).map(|v| v.safe_slice())
  }

任何想法我做错了什么?

rust flatbuffers
1个回答
0
投票

我解决了这个问题,请参见上面的评论。重要的是要确保使用并集字段将正确的类型放在..._type字段中,因为不能进行类型检查。

© www.soinside.com 2019 - 2024. All rights reserved.