E4177

E4177#

使用位串模式提取字节序列必须按字节对齐。

错误示例#

test {
  let a : Array[Byte] = [b'\xFF', b'\x00']
  match a {
    [u1be(flag), ..rest] => {
      inspect(flag, content="1")
      inspect(rest.length(), content="1")
    }
    _ => fail("")
  }
}

建议#

在提取字节序列之前将位模式对齐到整字节。

test {
  let a : Array[Byte] = [b'\xFF', b'\x00']
  match a {
    [u8be(value), ..rest] => {
      inspect(value, content="255")
      inspect(rest.length(), content="1")
    }
    _ => fail("")
  }
}