Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Encoding and decoding behavior difference #94

Open
artem-tim opened this issue Mar 28, 2023 · 0 comments
Open

Encoding and decoding behavior difference #94

artem-tim opened this issue Mar 28, 2023 · 0 comments

Comments

@artem-tim
Copy link

Please help me understand whether the difference in behavior between Encoder and Decoder is intentional or not. Consider the following code :

let t_utf8 = "ハロー世界";
let t_iso_2022_jp = b"\x1B\x24\x42\x25\x4F\x25\x6D\x21\x3C\x40\x24\x33\x26\x1B\x28\x42";

{
    let mut dec = ISO_2022_JP.new_decoder();
    let mut dst = [0 as u8; 6];
    let out = dec.decode_to_utf8(t_iso_2022_jp, &mut dst, false);
    println!("Partially decoded : {:?}", dst);
    println!("Result : {:?}", out);
}

{
    let mut enc = ISO_2022_JP.new_encoder();
    let mut dst = [0 as u8; 6];
    let out = enc.encode_from_utf8(t_utf8, &mut dst, false);
    println!("Partially encoded : {:?}", dst);
    println!("Result : {:?}", out);
}

Here is the output :

Partially decoded : [227, 131, 143, 227, 131, 173]
Result : (OutputFull, 7, 6, false)
Partially encoded : [0, 0, 0, 0, 0, 0]
Result : (OutputFull, 0, 0, false)

In both cases, we are attempting to decode or encode something that wouldn't fit the target buffer size, however the decoder is able to partially fill the buffer, where the encoder just does nothing.
If the buffer size is big enough, both work normally.
Is this behavior expected ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant