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

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

pivotal-jbarrett commented on a change in pull request #909:
URL: https://github.com/apache/geode-native/pull/909#discussion_r787172287



##########
File path: c-bindings/src/data_serializable_raw.cpp
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#include <iterator>
+
+// C++ client public headers
+#include "geode/DataInput.hpp"
+#include "geode/DataOutput.hpp"
+#include "geode/internal/DataSerializablePrimitive.hpp"
+
+// C client public headers
+#include "data_serializable_raw.hpp"
+
+// C client private headers
+
+using apache::geode::client::DataInput;
+using apache::geode::client::DataOutput;
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace internal {
+
+DataSerializableRaw::DataSerializableRaw(const int8_t* data, size_t size) {
+  bytes_.reserve(size);
+  std::copy(data, data + size, std::back_inserter(bytes_));
+}
+
+std::shared_ptr<DataSerializableRaw> DataSerializableRaw::create(
+    const int8_t* data, size_t size) {
+  return std::make_shared<DataSerializableRaw>(data, size);
+}
+
+void DataSerializableRaw::toData(DataOutput& dataOutput) const {
+  dataOutput.writeBytesOnly(bytes_.data() + dsCodeSize_,
+                            bytes_.size() - dsCodeSize_);
+}
+
+void DataSerializableRaw::fromData(DataInput& dataInput) {
+  dataInput.readBytesOnly(bytes_.data() + dsCodeSize_,
+                          bytes_.size() - dsCodeSize_);
+}
+
+DSCode DataSerializableRaw::getDsCode() const {
+  return static_cast<DSCode>(bytes_[0]);
+}
+
+bool DataSerializableRaw::operator==(const CacheableKey& other) const {
+  if (auto otherKey = dynamic_cast<const DataSerializableRaw*>(&other)) {
+    return bytes_ == otherKey->bytes_;
+  }
+
+  return false;
+}
+
+int32_t DataSerializableRaw::hashcode() const {
+  if (hashCode_ == 0) {
+    hashCode_ = internal::geode_hash<std::vector<int8_t>>{}(bytes_);

Review comment:
       This is going to result in a hash on the client that is not consistent 
with the hash on the server. The hash value needs to come from the 
pre-serialized form of the object being serialized here. This will result in 
sub-optimal put operations.

##########
File path: c-bindings/src/data_serializable_raw.cpp
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#include <iterator>
+
+// C++ client public headers
+#include "geode/DataInput.hpp"
+#include "geode/DataOutput.hpp"
+#include "geode/internal/DataSerializablePrimitive.hpp"
+
+// C client public headers
+#include "data_serializable_raw.hpp"
+
+// C client private headers
+
+using apache::geode::client::DataInput;
+using apache::geode::client::DataOutput;
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace internal {
+
+DataSerializableRaw::DataSerializableRaw(const int8_t* data, size_t size) {

Review comment:
       Any way to use `std::vector`? In other places where we needed arrays of 
bytes we have used `std::vector` to encapsulate the length and lifecycle 
management of the array. While in this method the `const` makes it very clear 
that the caller is the owner often times it isn't so clear. 

##########
File path: c-bindings/src/data_serializable_raw.hpp
##########
@@ -0,0 +1,53 @@
+/*
+ * 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 <vector>
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace internal {
+
+class DataSerializableRaw : public DataSerializablePrimitive , public 
CacheableKey {
+ public:
+  DataSerializableRaw(const int8_t* data, size_t size);
+  ~DataSerializableRaw() noexcept override = default;
+
+  static std::shared_ptr<DataSerializableRaw> create(
+      const int8_t* data, size_t size);
+
+
+  virtual void toData(DataOutput& dataOutput) const override;

Review comment:
       `virtual` is implied by `override`. `clang-tidy` should be complaining 
about this.

##########
File path: c-bindings/src/data_serializable_raw.cpp
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#include <iterator>
+
+// C++ client public headers
+#include "geode/DataInput.hpp"
+#include "geode/DataOutput.hpp"
+#include "geode/internal/DataSerializablePrimitive.hpp"
+
+// C client public headers
+#include "data_serializable_raw.hpp"
+
+// C client private headers
+
+using apache::geode::client::DataInput;
+using apache::geode::client::DataOutput;
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace internal {
+
+DataSerializableRaw::DataSerializableRaw(const int8_t* data, size_t size) {
+  bytes_.reserve(size);
+  std::copy(data, data + size, std::back_inserter(bytes_));
+}
+
+std::shared_ptr<DataSerializableRaw> DataSerializableRaw::create(
+    const int8_t* data, size_t size) {
+  return std::make_shared<DataSerializableRaw>(data, size);
+}
+
+void DataSerializableRaw::toData(DataOutput& dataOutput) const {
+  dataOutput.writeBytesOnly(bytes_.data() + dsCodeSize_,
+                            bytes_.size() - dsCodeSize_);
+}
+
+void DataSerializableRaw::fromData(DataInput& dataInput) {
+  dataInput.readBytesOnly(bytes_.data() + dsCodeSize_,
+                          bytes_.size() - dsCodeSize_);
+}
+
+DSCode DataSerializableRaw::getDsCode() const {
+  return static_cast<DSCode>(bytes_[0]);
+}
+
+bool DataSerializableRaw::operator==(const CacheableKey& other) const {
+  if (auto otherKey = dynamic_cast<const DataSerializableRaw*>(&other)) {
+    return bytes_ == otherKey->bytes_;
+  }
+
+  return false;
+}
+
+int32_t DataSerializableRaw::hashcode() const {
+  if (hashCode_ == 0) {

Review comment:
       `0` is a valid hash so this could result in multiple re-hashes.

##########
File path: c-bindings/src/data_serializable_raw.hpp
##########
@@ -0,0 +1,53 @@
+/*
+ * 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 <vector>
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace internal {
+
+class DataSerializableRaw : public DataSerializablePrimitive , public 
CacheableKey {
+ public:
+  DataSerializableRaw(const int8_t* data, size_t size);
+  ~DataSerializableRaw() noexcept override = default;
+
+  static std::shared_ptr<DataSerializableRaw> create(
+      const int8_t* data, size_t size);
+
+
+  virtual void toData(DataOutput& dataOutput) const override;
+  virtual void fromData(DataInput& dataInput) override;
+  virtual DSCode getDsCode() const override;
+
+  bool operator==(const CacheableKey& other) const override;
+
+  int32_t hashcode() const override;
+
+  private:
+   std::vector<int8_t> bytes_;
+   static constexpr int dsCodeSize_ = 1;

Review comment:
       Constants have a different naming convention.

##########
File path: c-bindings/src/data_serializable_raw.cpp
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#include <iterator>
+
+// C++ client public headers
+#include "geode/DataInput.hpp"
+#include "geode/DataOutput.hpp"
+#include "geode/internal/DataSerializablePrimitive.hpp"
+
+// C client public headers
+#include "data_serializable_raw.hpp"
+
+// C client private headers
+
+using apache::geode::client::DataInput;
+using apache::geode::client::DataOutput;
+
+namespace apache {
+namespace geode {
+namespace client {
+namespace internal {
+
+DataSerializableRaw::DataSerializableRaw(const int8_t* data, size_t size) {
+  bytes_.reserve(size);
+  std::copy(data, data + size, std::back_inserter(bytes_));
+}
+
+std::shared_ptr<DataSerializableRaw> DataSerializableRaw::create(
+    const int8_t* data, size_t size) {
+  return std::make_shared<DataSerializableRaw>(data, size);
+}
+
+void DataSerializableRaw::toData(DataOutput& dataOutput) const {
+  dataOutput.writeBytesOnly(bytes_.data() + dsCodeSize_,
+                            bytes_.size() - dsCodeSize_);
+}
+
+void DataSerializableRaw::fromData(DataInput& dataInput) {
+  dataInput.readBytesOnly(bytes_.data() + dsCodeSize_,
+                          bytes_.size() - dsCodeSize_);
+}
+
+DSCode DataSerializableRaw::getDsCode() const {
+  return static_cast<DSCode>(bytes_[0]);
+}
+
+bool DataSerializableRaw::operator==(const CacheableKey& other) const {
+  if (auto otherKey = dynamic_cast<const DataSerializableRaw*>(&other)) {
+    return bytes_ == otherKey->bytes_;
+  }
+
+  return false;
+}
+
+int32_t DataSerializableRaw::hashcode() const {
+  if (hashCode_ == 0) {
+    hashCode_ = internal::geode_hash<std::vector<int8_t>>{}(bytes_);
+  }
+  return 0;
+}
+
+}  // namespace internal
+}  // namespace client
+}  // namespace geode
+}  // namespace apache

Review comment:
       Missing new line.

##########
File path: c-bindings/src/data_serializable_raw.hpp
##########
@@ -0,0 +1,53 @@
+/*
+ * 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
+

Review comment:
       Missing header guard. `#pragma once` is not a standard.

##########
File path: c-bindings/src/data_serializable_raw.cpp
##########
@@ -0,0 +1,80 @@
+/*
+ * 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.
+ */
+
+#include <iterator>
+
+// C++ client public headers
+#include "geode/DataInput.hpp"
+#include "geode/DataOutput.hpp"
+#include "geode/internal/DataSerializablePrimitive.hpp"

Review comment:
       The corresponding header for a class should always be listed first. 




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


> Genericize All .NET Core Classes
> --------------------------------
>
>                 Key: GEODE-9712
>                 URL: https://issues.apache.org/jira/browse/GEODE-9712
>             Project: Geode
>          Issue Type: New Feature
>          Components: native client
>            Reporter: Michael Martell
>            Assignee: Michael Martell
>            Priority: Major
>              Labels: pull-request-available
>
> We need to implement IRegion<TKey, TValue> in .NET Core. This will require 
> writing generic versions of RegionFactory, Region, and Cache.



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

Reply via email to