[geode-native] 03/03: Support for 32-bit keys/values - includes signed and unsigned

2021-10-04 Thread mmartell
This is an automated email from the ASF dual-hosted git repository.

mmartell pushed a commit to branch wip-bytearray-for-values
in repository https://gitbox.apache.org/repos/asf/geode-native.git

commit 198ac47d176d70bab097aee984d264d62f17a224
Author: Mike Martell 
AuthorDate: Wed Sep 22 21:38:46 2021 -0700

Support for 32-bit keys/values
- includes signed and unsigned
---
 c-bindings/include/geode/region.h |  7 
 c-bindings/src/region.cpp | 42 +++
 c-bindings/src/region.hpp |  4 ++
 netcore/NetCore.Test/RegionFactoryTest.cs |  8 
 netcore/NetCore/Region.cs | 67 +--
 5 files changed, 125 insertions(+), 3 deletions(-)

diff --git a/c-bindings/include/geode/region.h 
b/c-bindings/include/geode/region.h
index 7355d04..6c99232 100644
--- a/c-bindings/include/geode/region.h
+++ b/c-bindings/include/geode/region.h
@@ -42,12 +42,19 @@ APACHE_GEODE_C_EXPORT void apache_geode_Region_PutString(
 APACHE_GEODE_C_EXPORT void apache_geode_Region_PutByteArray(
 apache_geode_region_t* region, const char* key, const char* value, size_t 
size);
 
+APACHE_GEODE_C_EXPORT void apache_geode_Region_PutByteArrayForInt32Key(
+apache_geode_region_t* region, int32_t key, const char* value,
+size_t size);
+
 APACHE_GEODE_C_EXPORT const char* apache_geode_Region_GetString(
 apache_geode_region_t* region, const char* key);
 
 APACHE_GEODE_C_EXPORT void apache_geode_Region_GetByteArray(
 apache_geode_region_t* region, const char* key, char** value, size_t* 
size);
 
+APACHE_GEODE_C_EXPORT void apache_geode_Region_GetByteArrayForInt32Key(
+apache_geode_region_t* region, const int32_t key, char** value, size_t* 
size);
+
 APACHE_GEODE_C_EXPORT void apache_geode_Region_Remove(
 apache_geode_region_t* region, const char* key);
 
diff --git a/c-bindings/src/region.cpp b/c-bindings/src/region.cpp
index 500506b..707ed4f 100644
--- a/c-bindings/src/region.cpp
+++ b/c-bindings/src/region.cpp
@@ -55,6 +55,12 @@ void RegionWrapper::PutByteArray(const std::string& key, 
const char* value,
   region_->put(key, apache::geode::client::CacheableBytes::create(val));
 }
 
+void RegionWrapper::PutByteArray(const int32_t key, const char* value,
+ size_t size) {
+  std::vector val(value, value + size);
+  region_->put(key, apache::geode::client::CacheableBytes::create(val));
+}
+
 const char* RegionWrapper::GetString(const std::string& key) {
   auto value = region_->get(key);
   lastValue_ =
@@ -84,6 +90,27 @@ void RegionWrapper::GetByteArray(const std::string& key, 
char** value,
   }
 }
 
+void RegionWrapper::GetByteArray(const int32_t key, char** value,
+ size_t* size) {
+  std::shared_ptr val = region_->get(key);
+
+  if (val.get() == nullptr) return;
+
+  auto bytes =
+  std::dynamic_pointer_cast(val);
+  int valSize = val->objectSize();
+#if defined(_WIN32)
+  int8_t* byteArray = static_cast(CoTaskMemAlloc(valSize));
+#else
+  int8_t* byteArray = static_cast(malloc(valSize));
+#endif
+  if (bytes) {
+memcpy(byteArray, bytes->value().data(), valSize);
+*value = reinterpret_cast(byteArray);
+*size = valSize;
+  }
+}
+
 void RegionWrapper::Remove(const std::string& key) { region_->remove(key); }
 
 bool RegionWrapper::ContainsValueForKey(const std::string& key) {
@@ -108,6 +135,14 @@ void 
apache_geode_Region_PutByteArray(apache_geode_region_t* region,
   regionWrapper->PutByteArray(key, value, size);
 }
 
+void apache_geode_Region_PutByteArrayForInt32Key(apache_geode_region_t* region,
+ const int32_t key,
+ const char* value,
+ size_t size) {
+  RegionWrapper* regionWrapper = reinterpret_cast(region);
+  regionWrapper->PutByteArray(key, value, size);
+}
+
 const char* apache_geode_Region_GetString(apache_geode_region_t* region,
   const char* key) {
   RegionWrapper* regionWrapper = reinterpret_cast(region);
@@ -121,6 +156,13 @@ void 
apache_geode_Region_GetByteArray(apache_geode_region_t* region,
   return regionWrapper->GetByteArray(key, value, size);
 }
 
+void apache_geode_Region_GetByteArrayForInt32Key(apache_geode_region_t* region,
+ const int32_t key,
+ char** value, size_t* size) {
+  RegionWrapper* regionWrapper = reinterpret_cast(region);
+  return regionWrapper->GetByteArray(key, value, size);
+}
+
 void apache_geode_Region_Remove(apache_geode_region_t* region,
 const char* key) {
   RegionWrapper* regionWrapper = reinterpret_cast(region);
diff --git a/c-bindings/src/region.hpp b/c-bindings/src/region.hpp
index 603a2c7..b2e1392 100644
--- a/c-bindings/src/region.hpp
+++ b/c-bindings/src/region.hpp
@@ -37,10 +37,14 

[geode-native] 03/03: Support for 32-bit keys/values - includes signed and unsigned

2021-09-22 Thread mmartell
This is an automated email from the ASF dual-hosted git repository.

mmartell pushed a commit to branch wip-bytearray-for-values
in repository https://gitbox.apache.org/repos/asf/geode-native.git

commit 198ac47d176d70bab097aee984d264d62f17a224
Author: Mike Martell 
AuthorDate: Wed Sep 22 21:38:46 2021 -0700

Support for 32-bit keys/values
- includes signed and unsigned
---
 c-bindings/include/geode/region.h |  7 
 c-bindings/src/region.cpp | 42 +++
 c-bindings/src/region.hpp |  4 ++
 netcore/NetCore.Test/RegionFactoryTest.cs |  8 
 netcore/NetCore/Region.cs | 67 +--
 5 files changed, 125 insertions(+), 3 deletions(-)

diff --git a/c-bindings/include/geode/region.h 
b/c-bindings/include/geode/region.h
index 7355d04..6c99232 100644
--- a/c-bindings/include/geode/region.h
+++ b/c-bindings/include/geode/region.h
@@ -42,12 +42,19 @@ APACHE_GEODE_C_EXPORT void apache_geode_Region_PutString(
 APACHE_GEODE_C_EXPORT void apache_geode_Region_PutByteArray(
 apache_geode_region_t* region, const char* key, const char* value, size_t 
size);
 
+APACHE_GEODE_C_EXPORT void apache_geode_Region_PutByteArrayForInt32Key(
+apache_geode_region_t* region, int32_t key, const char* value,
+size_t size);
+
 APACHE_GEODE_C_EXPORT const char* apache_geode_Region_GetString(
 apache_geode_region_t* region, const char* key);
 
 APACHE_GEODE_C_EXPORT void apache_geode_Region_GetByteArray(
 apache_geode_region_t* region, const char* key, char** value, size_t* 
size);
 
+APACHE_GEODE_C_EXPORT void apache_geode_Region_GetByteArrayForInt32Key(
+apache_geode_region_t* region, const int32_t key, char** value, size_t* 
size);
+
 APACHE_GEODE_C_EXPORT void apache_geode_Region_Remove(
 apache_geode_region_t* region, const char* key);
 
diff --git a/c-bindings/src/region.cpp b/c-bindings/src/region.cpp
index 500506b..707ed4f 100644
--- a/c-bindings/src/region.cpp
+++ b/c-bindings/src/region.cpp
@@ -55,6 +55,12 @@ void RegionWrapper::PutByteArray(const std::string& key, 
const char* value,
   region_->put(key, apache::geode::client::CacheableBytes::create(val));
 }
 
+void RegionWrapper::PutByteArray(const int32_t key, const char* value,
+ size_t size) {
+  std::vector val(value, value + size);
+  region_->put(key, apache::geode::client::CacheableBytes::create(val));
+}
+
 const char* RegionWrapper::GetString(const std::string& key) {
   auto value = region_->get(key);
   lastValue_ =
@@ -84,6 +90,27 @@ void RegionWrapper::GetByteArray(const std::string& key, 
char** value,
   }
 }
 
+void RegionWrapper::GetByteArray(const int32_t key, char** value,
+ size_t* size) {
+  std::shared_ptr val = region_->get(key);
+
+  if (val.get() == nullptr) return;
+
+  auto bytes =
+  std::dynamic_pointer_cast(val);
+  int valSize = val->objectSize();
+#if defined(_WIN32)
+  int8_t* byteArray = static_cast(CoTaskMemAlloc(valSize));
+#else
+  int8_t* byteArray = static_cast(malloc(valSize));
+#endif
+  if (bytes) {
+memcpy(byteArray, bytes->value().data(), valSize);
+*value = reinterpret_cast(byteArray);
+*size = valSize;
+  }
+}
+
 void RegionWrapper::Remove(const std::string& key) { region_->remove(key); }
 
 bool RegionWrapper::ContainsValueForKey(const std::string& key) {
@@ -108,6 +135,14 @@ void 
apache_geode_Region_PutByteArray(apache_geode_region_t* region,
   regionWrapper->PutByteArray(key, value, size);
 }
 
+void apache_geode_Region_PutByteArrayForInt32Key(apache_geode_region_t* region,
+ const int32_t key,
+ const char* value,
+ size_t size) {
+  RegionWrapper* regionWrapper = reinterpret_cast(region);
+  regionWrapper->PutByteArray(key, value, size);
+}
+
 const char* apache_geode_Region_GetString(apache_geode_region_t* region,
   const char* key) {
   RegionWrapper* regionWrapper = reinterpret_cast(region);
@@ -121,6 +156,13 @@ void 
apache_geode_Region_GetByteArray(apache_geode_region_t* region,
   return regionWrapper->GetByteArray(key, value, size);
 }
 
+void apache_geode_Region_GetByteArrayForInt32Key(apache_geode_region_t* region,
+ const int32_t key,
+ char** value, size_t* size) {
+  RegionWrapper* regionWrapper = reinterpret_cast(region);
+  return regionWrapper->GetByteArray(key, value, size);
+}
+
 void apache_geode_Region_Remove(apache_geode_region_t* region,
 const char* key) {
   RegionWrapper* regionWrapper = reinterpret_cast(region);
diff --git a/c-bindings/src/region.hpp b/c-bindings/src/region.hpp
index 603a2c7..b2e1392 100644
--- a/c-bindings/src/region.hpp
+++ b/c-bindings/src/region.hpp
@@ -37,10 +37,14