pub const MAX_END_USER_ID_LENGTH: usize = 512;
pub fn validate_end_user_id(s: Option<&str>) -> Option<String> {
let s = match s {
Some(s) if !s.is_empty() => s,
_ => return None,
};
let len = s.encode_utf16().count();
if len > MAX_END_USER_ID_LENGTH {
return Some(format!("endUserId length {len} > {MAX_END_USER_ID_LENGTH}"));
}
for (offset, c) in s.char_indices() {
let code = c as u32;
let ok = (0x61..=0x7a).contains(&code) || (0x41..=0x5a).contains(&code) || (0x30..=0x39).contains(&code) || code == 0x5f || code == 0x2d; if !ok {
return Some(format!(
"endUserId contains invalid char code 0x{code:x} at offset {offset} (allowed: [a-zA-Z0-9_-])"
));
}
}
None
}
pub fn is_sse_comment_line(line: &str) -> bool {
line.as_bytes().first() == Some(&b':')
}