GEODE-8837: Announce correct version on handshake. (#737)

- Support multibyte version.
- Use current gossip version.
diff --git a/cppcache/src/CacheImpl.cpp b/cppcache/src/CacheImpl.cpp
index 12fc785..34df55e 100644
--- a/cppcache/src/CacheImpl.cpp
+++ b/cppcache/src/CacheImpl.cpp
@@ -44,7 +44,6 @@
 #include "ThinClientRegion.hpp"
 #include "ThreadPool.hpp"
 #include "Utils.hpp"
-#include "Version.hpp"
 
 #define DEFAULT_DS_NAME "default_GeodeDS"
 
diff --git a/cppcache/src/ClientProxyMembershipID.cpp b/cppcache/src/ClientProxyMembershipID.cpp
index 8779a7d..0c69063 100644
--- a/cppcache/src/ClientProxyMembershipID.cpp
+++ b/cppcache/src/ClientProxyMembershipID.cpp
@@ -142,7 +142,7 @@
         static_cast<int32_t>(durableClntTimeOut.count()));
     int32ptr->toData(m_memID);
   }
-  writeVersion(Version::getOrdinal(), m_memID);
+  Version::write(m_memID, Version::current());
   size_t len;
   char* buf =
       reinterpret_cast<char*>(const_cast<uint8_t*>(m_memID.getBuffer(&len)));
@@ -340,25 +340,10 @@
 }
 
 void ClientProxyMembershipID::readVersion(int flags, DataInput& input) {
-  if ((flags & ClientProxyMembershipID::VERSION_MASK) != 0) {
-    int8_t ordinal = input.read();
-    LOGDEBUG("ClientProxyMembershipID::readVersion ordinal = %d ", ordinal);
-    if (ordinal == ClientProxyMembershipID::TOKEN_ORDINAL) {
-      LOGDEBUG("ClientProxyMembershipID::readVersion ordinal = %d ",
-               input.readInt16());
-    }
-  }
-}
-
-void ClientProxyMembershipID::writeVersion(int16_t ordinal,
-                                           DataOutput& output) {
-  if (ordinal <= SCHAR_MAX) {
-    output.write(static_cast<int8_t>(ordinal));
-    LOGDEBUG("ClientProxyMembershipID::writeVersion ordinal = %d ", ordinal);
-  } else {
-    output.write(ClientProxyMembershipID::TOKEN_ORDINAL);
-    output.writeInt(ordinal);
-    LOGDEBUG("ClientProxyMembershipID::writeVersion ordinal = %d ", ordinal);
+  if (flags & ClientProxyMembershipID::VERSION_MASK) {
+    const auto version = Version::read(input);
+    LOGDEBUG("ClientProxyMembershipID::readVersion ordinal = %d ",
+             version.getOrdinal());
   }
 }
 
diff --git a/cppcache/src/ClientProxyMembershipID.hpp b/cppcache/src/ClientProxyMembershipID.hpp
index f933587..3dd4b3c 100644
--- a/cppcache/src/ClientProxyMembershipID.hpp
+++ b/cppcache/src/ClientProxyMembershipID.hpp
@@ -129,7 +129,6 @@
   static const int8_t TOKEN_ORDINAL;
 
   void readVersion(int flags, DataInput& input);
-  void writeVersion(int16_t ordinal, DataOutput& output);
 
   void readAdditionalData(DataInput& input);
 };
diff --git a/cppcache/src/TcrConnection.cpp b/cppcache/src/TcrConnection.cpp
index 40d1238..58e03e7 100644
--- a/cppcache/src/TcrConnection.cpp
+++ b/cppcache/src/TcrConnection.cpp
@@ -160,11 +160,8 @@
     handShakeMsg.write(static_cast<int8_t>(CLIENT_TO_SERVER));
   }
 
-  // added for versioned client
-  int8_t versionOrdinal = Version::getOrdinal();
-  handShakeMsg.write(versionOrdinal);
-
-  LOGFINE("Client version ordinal is %d", versionOrdinal);
+  Version::write(handShakeMsg, Version::current());
+  LOGFINE("Client version ordinal is %d", Version::current().getOrdinal());
 
   handShakeMsg.write(static_cast<int8_t>(REPLY_OK));
 
diff --git a/cppcache/src/ThinClientLocatorHelper.cpp b/cppcache/src/ThinClientLocatorHelper.cpp
index 357681c..1dc5699 100644
--- a/cppcache/src/ThinClientLocatorHelper.cpp
+++ b/cppcache/src/ThinClientLocatorHelper.cpp
@@ -37,6 +37,7 @@
 #include "TcpSslConn.hpp"
 #include "TcrConnectionManager.hpp"
 #include "ThinClientPoolDM.hpp"
+#include "Version.hpp"
 
 namespace apache {
 namespace geode {
@@ -111,6 +112,7 @@
   }
 }
 
+static constexpr int32_t kGossipVersion = 1002;
 std::shared_ptr<Serializable> ThinClientLocatorHelper::sendRequest(
     const ServerLocation& location,
     const std::shared_ptr<Serializable>& request) const {
@@ -123,7 +125,8 @@
     auto conn = createConnection(location);
     auto data =
         m_poolDM->getConnectionManager().getCacheImpl()->createDataOutput();
-    data.writeInt(static_cast<int32_t>(1001));  // GOSSIPVERSION
+    data.writeInt(kGossipVersion);
+    data.writeInt(Version::current().getOrdinal());
     data.writeObject(request);
     auto sentLength = conn->send(
         reinterpret_cast<char*>(const_cast<uint8_t*>(data.getBuffer())),
diff --git a/cppcache/src/Version.cpp b/cppcache/src/Version.cpp
index 9d3feac..0ebd4ba 100644
--- a/cppcache/src/Version.cpp
+++ b/cppcache/src/Version.cpp
@@ -14,15 +14,36 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
+
 #include "Version.hpp"
 
-#include "CacheImpl.hpp"
+#include <limits>
+
+#include <geode/DataInput.hpp>
+#include <geode/DataOutput.hpp>
 
 namespace apache {
 namespace geode {
 namespace client {
 
-int8_t Version::m_ordinal = 45;  // Geode 1.0.0
+void Version::write(DataOutput& dataOutput, const Version& version,
+                    bool compressed) {
+  const auto ordinal = version.getOrdinal();
+  if (compressed && (ordinal <= std::numeric_limits<int8_t>::max())) {
+    dataOutput.write(static_cast<int8_t>(ordinal));
+  } else {
+    dataOutput.write(kTokenOrdinal);
+    dataOutput.writeInt(ordinal);
+  }
+}
+
+Version Version::read(DataInput& dataInput) {
+  int16_t ordinal = dataInput.read();
+  if (kTokenOrdinal == ordinal) {
+    ordinal = dataInput.readInt16();
+  }
+  return Version(ordinal);
+}
 
 }  // namespace client
 }  // namespace geode
diff --git a/cppcache/src/Version.hpp b/cppcache/src/Version.hpp
index 8fedbde..4b78468 100644
--- a/cppcache/src/Version.hpp
+++ b/cppcache/src/Version.hpp
@@ -1,8 +1,3 @@
-#pragma once
-
-#ifndef GEODE_VERSION_H_
-#define GEODE_VERSION_H_
-
 /*
  * Licensed to the Apache Software Foundation (ASF) under one or more
  * contributor license agreements.  See the NOTICE file distributed with
@@ -20,22 +15,41 @@
  * limitations under the License.
  */
 
-#include "CacheImpl.hpp"
+#pragma once
+
+#ifndef GEODE_VERSION_H_
+#define GEODE_VERSION_H_
+
+#include <cstdint>
 
 namespace apache {
 namespace geode {
 namespace client {
 
+class DataOutput;
+class DataInput;
+
 class Version {
  public:
-  // getter for ordinal
-  static int8_t getOrdinal() { return Version::m_ordinal; }
+  inline int16_t getOrdinal() const noexcept { return ordinal_; }
+
+  static const Version& current() noexcept {
+    static const auto version = Version{45};  // Geode 1.0.0
+    return version;
+  }
+
+  static void write(DataOutput& dataOutput, const Version& version,
+                    bool compressed = true);
+  static Version read(DataInput& dataOutput);
 
  private:
-  static int8_t m_ordinal;
+  const int16_t ordinal_;
 
-  Version() {}
+  inline explicit Version(int16_t ordinal) noexcept : ordinal_(ordinal) {}
+
+  static constexpr int8_t kTokenOrdinal = -1;
 };
+
 }  // namespace client
 }  // namespace geode
 }  // namespace apache