diff --git a/include/proxy/logging/LogAccess.h b/include/proxy/logging/LogAccess.h index 7cdf8ed48be..1d8d6974e24 100644 --- a/include/proxy/logging/LogAccess.h +++ b/include/proxy/logging/LogAccess.h @@ -316,6 +316,7 @@ class LogAccess static int unmarshal_itox(int64_t val, char *dest, int field_width = 0, char leading_char = ' '); static int unmarshal_int_to_str(char **buf, char *dest, int len); static int unmarshal_int_to_str_hex(char **buf, char *dest, int len); + static int unmarshal_milestone_diff(char **buf, char *dest, int len); static int unmarshal_str(char **buf, char *dest, int len, LogSlice *slice, LogEscapeType escape_type); static int unmarshal_ttmsf(char **buf, char *dest, int len); static int unmarshal_int_to_date_str(char **buf, char *dest, int len); diff --git a/src/proxy/logging/LogAccess.cc b/src/proxy/logging/LogAccess.cc index 908ec8c22ff..3f5d6868564 100644 --- a/src/proxy/logging/LogAccess.cc +++ b/src/proxy/logging/LogAccess.cc @@ -626,6 +626,43 @@ LogAccess::unmarshal_int_to_str(char **buf, char *dest, int len) return -1; } +/*------------------------------------------------------------------------- + LogAccess::unmarshal_milestone_diff + + Unmarshal a milestone difference value. Returns "-" when the + marshalled value is -1 (the "missing" sentinel from difference_msec, + meaning one or both milestones were unset). Other negative values + (reversed milestone order) are preserved as numeric output for + debugging. + -------------------------------------------------------------------------*/ + +int +LogAccess::unmarshal_milestone_diff(char **buf, char *dest, int len) +{ + ink_assert(buf != nullptr); + ink_assert(*buf != nullptr); + ink_assert(dest != nullptr); + + int64_t val = unmarshal_int(buf); + if (val == -1) { + if (len >= 1) { + dest[0] = '-'; + return 1; + } + DBG_UNMARSHAL_DEST_OVERRUN + return -1; + } + + char val_buf[128]; + int val_len = unmarshal_itoa(val, val_buf + 127); + if (val_len < len) { + memcpy(dest, val_buf + 128 - val_len, val_len); + return val_len; + } + DBG_UNMARSHAL_DEST_OVERRUN + return -1; +} + /*------------------------------------------------------------------------- LogAccess::unmarshal_int_to_str_hex diff --git a/src/proxy/logging/LogField.cc b/src/proxy/logging/LogField.cc index f7dcbbd067a..039aca32a74 100644 --- a/src/proxy/logging/LogField.cc +++ b/src/proxy/logging/LogField.cc @@ -388,7 +388,7 @@ LogField::LogField(const char *field, Container container) if (0 != rv) { Note("Invalid milestone range in LogField ctor: %s", m_name); } - m_unmarshal_func = &(LogAccess::unmarshal_int_to_str); + m_unmarshal_func = &(LogAccess::unmarshal_milestone_diff); m_type = LogField::sINT; break; }