use super::redaction_markers::{
INVALID_JSON_REDACTED,
INVALID_NDJSON_REDACTED,
INVALID_OR_TRUNCATED_JSON_REDACTED,
INVALID_OR_TRUNCATED_NDJSON_REDACTED,
};
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub(super) enum BodyInputKind {
Complete,
Preview,
}
impl BodyInputKind {
pub(super) fn empty_output(self, source_len: usize) -> String {
match self {
Self::Complete => String::new(),
Self::Preview => format!("<empty>{}", self.truncation_suffix(0, source_len)),
}
}
pub(super) fn is_truncated(self, bytes_len: usize, source_len: usize) -> bool {
self == Self::Preview && source_len > bytes_len
}
pub(super) fn truncation_suffix(self, bytes_len: usize, source_len: usize) -> String {
if !self.is_truncated(bytes_len, source_len) {
return String::new();
}
let truncated = source_len.saturating_sub(bytes_len);
format!("...<truncated {truncated} bytes>")
}
pub(super) fn invalid_json_marker(self) -> &'static str {
match self {
Self::Complete => INVALID_JSON_REDACTED,
Self::Preview => INVALID_OR_TRUNCATED_JSON_REDACTED,
}
}
pub(super) fn invalid_ndjson_marker(self) -> &'static str {
match self {
Self::Complete => INVALID_NDJSON_REDACTED,
Self::Preview => INVALID_OR_TRUNCATED_NDJSON_REDACTED,
}
}
}