You are viewing a plain text version of this content. The canonical link for it is here.
Posted to github@trafficserver.apache.org by "cmcfarlen (via GitHub)" <gi...@apache.org> on 2024/05/24 23:33:56 UTC

[PR] Add ts::hex and ts::unhex [trafficserver]

cmcfarlen opened a new pull request, #11392:
URL: https://github.com/apache/trafficserver/pull/11392

   (no comment)


-- 
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


Re: [PR] Add ts::hex and ts::unhex [trafficserver]

Posted by "cmcfarlen (via GitHub)" <gi...@apache.org>.
cmcfarlen merged PR #11392:
URL: https://github.com/apache/trafficserver/pull/11392


-- 
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


Re: [PR] Add ts::hex and ts::unhex [trafficserver]

Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on PR #11392:
URL: https://github.com/apache/trafficserver/pull/11392#issuecomment-2136075351

   For this use case at least, this is at least as fast as Boost, sometimes even faster.


-- 
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


Re: [PR] Add ts::hex and ts::unhex [trafficserver]

Posted by "cmcfarlen (via GitHub)" <gi...@apache.org>.
cmcfarlen commented on PR #11392:
URL: https://github.com/apache/trafficserver/pull/11392#issuecomment-2141815212

   Cherry-picked to v10.0.x


-- 
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


Re: [PR] Add ts::hex and ts::unhex [trafficserver]

Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on PR #11392:
URL: https://github.com/apache/trafficserver/pull/11392#issuecomment-2138406737

   Looks good, other than the request for documentation. I verified in godbolt that hex this seems to act like boost's.


-- 
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


Re: [PR] Add ts::hex and ts::unhex [trafficserver]

Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #11392:
URL: https://github.com/apache/trafficserver/pull/11392#discussion_r1619569336


##########
include/tsutil/StringConvert.h:
##########
@@ -0,0 +1,71 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+#pragma once
+
+#include <charconv>
+#include <stdexcept>
+#include <string>
+#include <system_error>
+
+namespace ts
+{
+
+inline std::string
+hex(const std::string_view input)

Review Comment:
   I was initially confused, assuming `hex` converted from base 10 or some such to hex. Maybe comment with something like:
   
   ```cpp
   /** Convert values into their hex ascii equivalents.
    *
    * For example, with an input of "01", this returns "3031".
    * 
    * @note This is a reimplementation of boost's hex.
    * @return The series of hex values corresponding to @a input
    */
   ```



-- 
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


Re: [PR] Add ts::hex and ts::unhex [trafficserver]

Posted by "bneradt (via GitHub)" <gi...@apache.org>.
bneradt commented on code in PR #11392:
URL: https://github.com/apache/trafficserver/pull/11392#discussion_r1619569336


##########
include/tsutil/StringConvert.h:
##########
@@ -0,0 +1,71 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+#pragma once
+
+#include <charconv>
+#include <stdexcept>
+#include <string>
+#include <system_error>
+
+namespace ts
+{
+
+inline std::string
+hex(const std::string_view input)

Review Comment:
   I was initially confused, assuming `hex` converted from base 10 or some such to hex. Maybe comment with something like:
   
   ```cpp
   /** Convert values into their hex ascii equivalents.
    * @note This is a reimplementation of boost's hex.
    * @return The series of hex values corresponding to @a input
    */
   ```



##########
include/tsutil/StringConvert.h:
##########
@@ -0,0 +1,71 @@
+/*
+  Licensed to the Apache Software Foundation (ASF) under one
+  or more contributor license agreements.  See the NOTICE file
+  distributed with this work for additional information
+  regarding copyright ownership.  The ASF licenses this file
+  to you under the Apache License, Version 2.0 (the
+  "License"); you may not use this file except in compliance
+  with the License.  You may obtain a copy of the License at
+
+  http://www.apache.org/licenses/LICENSE-2.0
+
+  Unless required by applicable law or agreed to in writing, software
+  distributed under the License is distributed on an "AS IS" BASIS,
+  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+  See the License for the specific language governing permissions and
+  limitations under the License.
+*/
+
+#pragma once
+
+#include <charconv>
+#include <stdexcept>
+#include <string>
+#include <system_error>
+
+namespace ts
+{
+
+inline std::string
+hex(const std::string_view input)
+{
+  std::string result;
+
+  result.resize(input.size() * 2);
+
+  char *p = result.data();
+  for (auto x : input) {
+    if (auto [ptr, err] = std::to_chars(p, result.data() + result.size(), x, 16); err == std::errc()) {
+      p = ptr;
+    } else {
+      throw std::runtime_error(std::make_error_code(err).message().c_str());
+    }
+  }
+
+  return result;
+}
+
+inline std::string
+unhex(const std::string_view input)

Review Comment:
   Maybe doc with:
   
   ```cpp
   /** The inverse function of hex above.
    * @note This is a reimplementation of boost's unhex.
    */



-- 
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


Re: [PR] Add ts::hex and ts::unhex [trafficserver]

Posted by "zwoop (via GitHub)" <gi...@apache.org>.
zwoop commented on PR #11392:
URL: https://github.com/apache/trafficserver/pull/11392#issuecomment-2135959022

   Ship it.


-- 
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