pub fn decode(
data: &[u8],
max_size: Option<usize>,
) -> Result<Option<LuaValue>, DecodeError>Expand description
Decodes a WeakAuras-compatible string and returns a LuaValue.
The second argument, max_size, is used as a counter-DoS measure. Since the data
is compressed, it’s possible to construct a payload that would consume a lot of memory
after decompression. None is equivalent to 16 MiB.
§Example
use weakauras_codec::{DecodeError, decode};
fn main() -> Result<(), DecodeError> {
let expected_value = "Hello, world!".into();
assert_eq!(
decode(b"!lodJlypsnNCYxN6sO88lkNuumU4aaa", None)?.unwrap(),
expected_value
);
assert_eq!(
decode(b"!WA:2!JXl5rQ5Kt(6Oq55xuoPOiaa", Some(1024))?.unwrap(),
expected_value
);
Ok(())
}