[ 
https://issues.apache.org/jira/browse/GEODE-10096?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17502462#comment-17502462
 ] 

ASF GitHub Bot commented on GEODE-10096:
----------------------------------------

mreddington commented on a change in pull request #938:
URL: https://github.com/apache/geode-native/pull/938#discussion_r820950242



##########
File path: cppcache/src/util/to_underlying.hpp
##########
@@ -0,0 +1,35 @@
+/*
+ * 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.
+ */
+
+#ifndef UTIL_UNDERLYING_TYPE_HPP
+#define UTIL_UNDERLYING_TYPE_HPP
+
+#include <type_traits>
+
+/* Note: this implementation can be thrown away once we upgrade to C++14. */
+
+template< class T >
+using underlying_type_t = typename std::underlying_type<T>::type;
+
+/* Note: this implementation can be thrown away once we upgrade to C++23. */
+
+template< class Enum >
+constexpr underlying_type_t<Enum> to_underlying( Enum e ) noexcept {

Review comment:
       Counterpoints:
   
   * This is a direct copy of an STL utility we just don't have in C++11.
   * Look where I'm using it - at some point, we need to write these enum 
values to the byte stream. Now there are two ways we can do that:
     - We can map an enum to a value, and a value to an enum, like via some 
switch statement. If we do that, then we don't need to specify the enum values 
themselves, since we'd never cast the enum to or from an integer type. This is 
just redundant in every way.
     - We cast the enum where we write bytes to the wire.
   * It doesn't need a reverse. You can static cast any integer to an enum and 
the compiler will let you know if you're narrowing, but if you want to cast 
from an enum to the numeric type used to implement it, that's built into the 
enum type but you wouldn't know it, or can't rely on it since it can change, 
either by the compiler, or in the case of an enum class, the implementer. The 
compiler always knows, so this leverages deduction to get it right for you.
   
   But I feel you. I don't like the use of enums overall. There's just 
something about them that don't seem "good enough". I don't think C++ would 
have had enumerations in the form we have them today if we didn't inherit from 
C, so I'm always aware of the loose type safety they come with.




-- 
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: notifications-unsubscr...@geode.apache.org

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


> Handshake "acceptance codes" should be an enum class
> ----------------------------------------------------
>
>                 Key: GEODE-10096
>                 URL: https://issues.apache.org/jira/browse/GEODE-10096
>             Project: Geode
>          Issue Type: Improvement
>          Components: native client
>            Reporter: Blake Bender
>            Priority: Major
>              Labels: pull-request-available
>
> In the method TcrConnection::initTcrConnection, the following block of code 
> appears:
> {code:java}
>     switch (acceptanceCode[0]) {
>       case REPLY_OK:
>       case SUCCESSFUL_SERVER_TO_CLIENT:
>         LOGFINER("Handshake reply: %u,%u,%u", acceptanceCode[0],
>                  serverQueueStatus[0], recvMsgLen2);
>         if (isClientNotification) 
> readHandshakeInstantiatorMsg(connectTimeout);
>         break;
>       case REPLY_AUTHENTICATION_FAILED: {
>         AuthenticationFailedException ex(
>             reinterpret_cast<char*>(recvMessage.data()));
>         m_conn.reset();
>         throwException(ex);
>       }
>       case REPLY_AUTHENTICATION_REQUIRED: {
>         AuthenticationRequiredException ex(
>             reinterpret_cast<char*>(recvMessage.data()));
>         m_conn.reset();
>         throwException(ex);
>       }
>       case REPLY_DUPLICATE_DURABLE_CLIENT: {
>         DuplicateDurableClientException ex(
>             reinterpret_cast<char*>(recvMessage.data()));
>         m_conn.reset();
>         throwException(ex);
>       }
>       case REPLY_REFUSED:
>       case REPLY_INVALID:
>       case UNSUCCESSFUL_SERVER_TO_CLIENT: {
>         LOGERROR("Handshake rejected by server[%s]: %s",
>                  m_endpointObj->name().c_str(),
>                  reinterpret_cast<char*>(recvMessage.data()));
>         auto message = std::string("TcrConnection::TcrConnection: ") +
>                        "Handshake rejected by server: " +
>                        reinterpret_cast<char*>(recvMessage.data());
>         CacheServerException ex(message);
>         m_conn.reset();
>         throw ex;
>       }
> {code}
> These response codes are unique to the server handshake, and not used 
> anywhere else in the code. We need to remove the #defines for them and put 
> them in a proper enum class.



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to