Skip to content

Commit e6d9b22

Browse files
committed
Document Message::gets behavior regarding non-UTF8 values
1 parent 3606a3e commit e6d9b22

File tree

1 file changed

+11
-3
lines changed

1 file changed

+11
-3
lines changed

src/message.rs

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,17 @@ impl Message {
116116
}
117117

118118
/// Query a message metadata property.
119+
///
120+
/// # Non-UTF8 values
121+
///
122+
/// The `zmq_msg_gets` man page notes "The encoding of the property and
123+
/// value shall be UTF8". However, this is not actually enforced. For API
124+
/// compatibility reasons, this function will return `None` when
125+
/// encountering a non-UTF8 value; so a missing and a non-UTF8 value cannot
126+
/// currently be distinguished.
127+
///
128+
/// This is considered a bug in the bindings, and will be fixed with the
129+
/// next API-breaking release.
119130
pub fn gets<'a>(&'a mut self, property: &str) -> Option<&'a str> {
120131
let c_str = ffi::CString::new(property.as_bytes()).unwrap();
121132

@@ -124,9 +135,6 @@ impl Message {
124135
if value.is_null() {
125136
None
126137
} else {
127-
// Note: libzmq` does not do UTF-8 validation, even though its doc
128-
// suggest that UTF-8 "shall" be used here. Maybe we should changge
129-
// the API to return a bytes slice.
130138
str::from_utf8(unsafe { ffi::CStr::from_ptr(value) }.to_bytes()).ok()
131139
}
132140
}

0 commit comments

Comments
 (0)