You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by GitBox <gi...@apache.org> on 2022/06/23 15:12:41 UTC

[GitHub] [trafficserver] cmcfarlen commented on a diff in pull request #8922: Use std::variant to clean up handling of unmarshal functions.

cmcfarlen commented on code in PR #8922:
URL: https://github.com/apache/trafficserver/pull/8922#discussion_r905150318


##########
proxy/logging/LogField.cc:
##########
@@ -600,23 +596,14 @@ LogField::marshal_agg(char *buf)
 unsigned
 LogField::unmarshal(char **buf, char *dest, int len, LogEscapeType escape_type)
 {
-  if (!m_alias_map) {
-    if (m_unmarshal_func == reinterpret_cast<UnmarshalFunc>(LogAccess::unmarshal_str) ||
-        m_unmarshal_func == reinterpret_cast<UnmarshalFunc>(LogAccess::unmarshal_http_text)) {
-      UnmarshalFuncWithSlice func = reinterpret_cast<UnmarshalFuncWithSlice>(m_unmarshal_func);
-      if (escape_type == LOG_ESCAPE_JSON) {
-        if (m_unmarshal_func == reinterpret_cast<UnmarshalFunc>(LogAccess::unmarshal_str)) {
-          func = reinterpret_cast<UnmarshalFuncWithSlice>(LogAccess::unmarshal_str_json);
-        } else if (m_unmarshal_func == reinterpret_cast<UnmarshalFunc>(LogAccess::unmarshal_http_text)) {
-          func = reinterpret_cast<UnmarshalFuncWithSlice>(LogAccess::unmarshal_http_text_json);
-        }
-      }
-      return (*func)(buf, dest, len, &m_slice);
-    }
-    return (*m_unmarshal_func)(buf, dest, len);
-  } else {
-    return (*m_unmarshal_func_map)(buf, dest, len, m_alias_map);
+  if (std::holds_alternative<UnmarshalFuncWithSlice>(m_unmarshal_func)) {
+    return (*std::get<UnmarshalFuncWithSlice>(m_unmarshal_func))(buf, dest, len, &m_slice);
+  } else if (std::holds_alternative<UnmarshalFuncWithSlice>(m_unmarshal_func)) {
+    return (*std::get<UnmarshalFunc>(m_unmarshal_func))(buf, dest, len);

Review Comment:
   This seems to drop the json escape type support.  Also, you could use the variant visit pattern here instead of checking each hold type.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: github-unsubscribe@trafficserver.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org