erickt / rust-zmq

Rust zeromq bindings.
Apache License 2.0
886 stars 189 forks source link

Uft8Error when reciving #364

Open KilroyWasHere-cs-j opened 1 year ago

KilroyWasHere-cs-j commented 1 year ago

str::from_utf8(&data[1]).unwrap() throws Result::unwrap() on an Err value: Utf8Error { valid_up_to: 0, error_len: Some(1) }

New to rust what's the fix.

magnificus commented 7 months ago

I got the same error when a user was sending non-unicode characters and I tried to stringify, solution in my case was to use from_utf8_lossy (which obviously will lose some information though).

String::from_utf8_lossy(&topic).to_string();

jtacoma commented 2 months ago

I think this issue can be closed now: @magnificus responded to the problem @KilroyWasHere-cs-j was dealing with, and the problem was just that data[1] wasn't valid UTF-8, which is not an issue with rust-zmq.

KilroyWasHere-cs-j commented 2 months ago

Yep correct. No need to leave this open.