This is an automated email from the ASF dual-hosted git repository.
bbender pushed a commit to branch develop
in repository https://gitbox.apache.org/repos/asf/geode-native.git
The following commit(s) were added to refs/heads/develop by this push:
new 2cb71e6 GEODE-4338: Add C++ Continuous Query Example (#352)
2cb71e6 is described below
commit 2cb71e6eb7670dd439989048bb6616d7244e1755
Author: Blake Bender <[email protected]>
AuthorDate: Mon Sep 17 07:50:16 2018 -0700
GEODE-4338: Add C++ Continuous Query Example (#352)
- Remove meaningless doc comment
- Remove tabs from c++ examples CMakeLists.txt
- Change types of members in custom PDX object to avoid casting
- Check for nullptr in event handler
- Declare variables of type auto rather than use explicit typing
Co-authored-by: Ivan Godwin <[email protected]>
Co-authored-by: Jacob Barrett <[email protected]>
---
cppcache/include/geode/CqListener.hpp | 9 +-
examples/cpp/CMakeLists.txt | 14 ++-
examples/cpp/CMakeLists.txt.in | 1 +
.../CMakeLists.txt} | 24 ++--
.../cpp/{remotequery => continuousquery}/Order.cpp | 10 +-
.../cpp/{remotequery => continuousquery}/Order.hpp | 18 +--
examples/cpp/continuousquery/README.md | 61 +++++++++
examples/cpp/continuousquery/main.cpp | 136 +++++++++++++++++++++
.../startserver.sh} | 21 ++--
.../stopserver.sh} | 21 ++--
examples/cpp/pdxserializable/Order.cpp | 17 ++-
examples/cpp/pdxserializable/Order.hpp | 10 +-
examples/cpp/pdxserializable/main.cpp | 2 +-
examples/cpp/remotequery/Order.cpp | 8 +-
examples/cpp/remotequery/Order.hpp | 8 +-
15 files changed, 290 insertions(+), 70 deletions(-)
diff --git a/cppcache/include/geode/CqListener.hpp
b/cppcache/include/geode/CqListener.hpp
index bd3a190..9f5fac0 100644
--- a/cppcache/include/geode/CqListener.hpp
+++ b/cppcache/include/geode/CqListener.hpp
@@ -40,7 +40,10 @@ class CacheListener;
class APACHE_GEODE_EXPORT CqListener {
public:
virtual ~CqListener() noexcept = default;
+
+ CqListener();
CqListener(const CacheListener& other) = delete;
+
void operator=(const CqListener& other) = delete;
/**
@@ -79,12 +82,6 @@ class APACHE_GEODE_EXPORT CqListener {
*/
virtual void close();
- protected:
- /**
- * @brief constructors
- */
- CqListener();
-
};
} // namespace client
} // namespace geode
diff --git a/examples/cpp/CMakeLists.txt b/examples/cpp/CMakeLists.txt
index fa54531..5b4efd5 100644
--- a/examples/cpp/CMakeLists.txt
+++ b/examples/cpp/CMakeLists.txt
@@ -47,17 +47,21 @@ function(add_example)
DESTINATION examples/cpp/${ADD_EXAMPLE_NAME})
endfunction()
+add_example(NAME continuousquery
+ SOURCE main.cpp Order.cpp Order.hpp)
+
add_example(NAME dataserializable
- SOURCE main.cpp Order.cpp Order.hpp)
+ SOURCE main.cpp Order.cpp Order.hpp)
add_example(NAME pdxserializable
- SOURCE main.cpp Order.cpp Order.hpp)
+ SOURCE main.cpp Order.cpp Order.hpp)
add_example(NAME pdxserializer
- SOURCE main.cpp Order.cpp Order.hpp OrderSerializer.cpp
OrderSerializer.hpp)
+ SOURCE main.cpp Order.cpp Order.hpp OrderSerializer.cpp
OrderSerializer.hpp)
add_example(NAME put-get-remove
- SOURCE main.cpp)
+ SOURCE main.cpp)
add_example(NAME remotequery
- SOURCE main.cpp Order.cpp Order.hpp)
+ SOURCE main.cpp Order.cpp Order.hpp)
+
diff --git a/examples/cpp/CMakeLists.txt.in b/examples/cpp/CMakeLists.txt.in
index 5bde343..e176810 100644
--- a/examples/cpp/CMakeLists.txt.in
+++ b/examples/cpp/CMakeLists.txt.in
@@ -17,6 +17,7 @@ cmake_minimum_required(VERSION 3.10)
project(@[email protected] LANGUAGES NONE)
+add_subdirectory(continuousquery)
add_subdirectory(dataserializable)
add_subdirectory(pdxserializable)
add_subdirectory(pdxserializer)
diff --git a/examples/cpp/CMakeLists.txt.in
b/examples/cpp/continuousquery/CMakeLists.txt
similarity index 61%
copy from examples/cpp/CMakeLists.txt.in
copy to examples/cpp/continuousquery/CMakeLists.txt
index 5bde343..bf0b415 100644
--- a/examples/cpp/CMakeLists.txt.in
+++ b/examples/cpp/continuousquery/CMakeLists.txt
@@ -13,12 +13,22 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.10)
+cmake_minimum_required(VERSION 3.5)
-project(@[email protected] LANGUAGES NONE)
+project(continuousquery LANGUAGES CXX)
-add_subdirectory(dataserializable)
-add_subdirectory(pdxserializable)
-add_subdirectory(pdxserializer)
-add_subdirectory(put-get-remove)
-add_subdirectory(remotequery)
+set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/../../cmake)
+set(CMAKE_CXX_STANDARD 11)
+
+if(CMAKE_CXX_COMPILER_ID STREQUAL "SunPro")
+ add_compile_options(-m64)
+ set(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -m64")
+endif()
+
+find_package(GeodeNative REQUIRED COMPONENTS cpp)
+
+add_executable(${PROJECT_NAME} main.cpp;Order.cpp;Order.hpp)
+
+target_link_libraries(${PROJECT_NAME}
+ PUBLIC
+ GeodeNative::cpp)
diff --git a/examples/cpp/remotequery/Order.cpp
b/examples/cpp/continuousquery/Order.cpp
similarity index 87%
copy from examples/cpp/remotequery/Order.cpp
copy to examples/cpp/continuousquery/Order.cpp
index 08a9c59..d1ef555 100644
--- a/examples/cpp/remotequery/Order.cpp
+++ b/examples/cpp/continuousquery/Order.cpp
@@ -20,22 +20,22 @@
#include <geode/PdxReader.hpp>
#include <geode/PdxWriter.hpp>
-namespace remotequery {
+namespace continuousquery {
void Order::fromData(PdxReader& pdxReader) {
- order_id_ = static_cast<uint32_t>(pdxReader.readLong(ORDER_ID_KEY_));
+ order_id_ = pdxReader.readInt(ORDER_ID_KEY_);
name_ = pdxReader.readString(NAME_KEY_);
- quantity_ = static_cast<uint16_t>(pdxReader.readInt(QUANTITY_KEY_));
+ quantity_ = pdxReader.readShort(QUANTITY_KEY_);
}
void Order::toData(PdxWriter& pdxWriter) const {
- pdxWriter.writeLong(ORDER_ID_KEY_, order_id_);
+ pdxWriter.writeInt(ORDER_ID_KEY_, order_id_);
pdxWriter.markIdentityField(ORDER_ID_KEY_);
pdxWriter.writeString(NAME_KEY_, name_);
pdxWriter.markIdentityField(NAME_KEY_);
- pdxWriter.writeInt(QUANTITY_KEY_, quantity_);
+ pdxWriter.writeShort(QUANTITY_KEY_, quantity_);
pdxWriter.markIdentityField(QUANTITY_KEY_);
}
diff --git a/examples/cpp/remotequery/Order.hpp
b/examples/cpp/continuousquery/Order.hpp
similarity index 84%
copy from examples/cpp/remotequery/Order.hpp
copy to examples/cpp/continuousquery/Order.hpp
index 4a28762..549d416 100644
--- a/examples/cpp/remotequery/Order.hpp
+++ b/examples/cpp/continuousquery/Order.hpp
@@ -17,14 +17,14 @@
#pragma once
-#ifndef REMOTEQUERY_ORDER_H
-#define REMOTEQUERY_ORDER_H
+#ifndef CONTINUOUSQUERY_ORDER_H
+#define CONTINUOUSQUERY_ORDER_H
#include <string>
#include <geode/PdxSerializable.hpp>
-namespace remotequery {
+namespace continuousquery {
using namespace apache::geode::client;
@@ -32,12 +32,12 @@ class Order : public PdxSerializable {
public:
inline Order() : Order(0, "", 0) {}
- inline Order(uint32_t order_id, std::string name, uint16_t quantity)
+ inline Order(int32_t order_id, std::string name, int16_t quantity)
: order_id_(order_id), name_(std::move(name)), quantity_(quantity) {}
~Order() override = default;
- inline uint32_t getOrderId() const { return order_id_; }
+ inline int32_t getOrderId() const { return order_id_; }
inline const std::string& getName() const { return name_; }
@@ -62,11 +62,11 @@ class Order : public PdxSerializable {
static const std::string NAME_KEY_;
static const std::string QUANTITY_KEY_;
- uint32_t order_id_;
+ int32_t order_id_;
std::string name_;
- uint16_t quantity_;
+ int16_t quantity_;
};
-} // namespace remotequery
+} // namespace continuousquery
-#endif // REMOTEQUERY_ORDER_H
+#endif // CONTINUOUSQUERY_ORDER_H
diff --git a/examples/cpp/continuousquery/README.md
b/examples/cpp/continuousquery/README.md
new file mode 100644
index 0000000..729d135
--- /dev/null
+++ b/examples/cpp/continuousquery/README.md
@@ -0,0 +1,61 @@
+# Continuous Query Example
+This is a simple example showing how to create a continuous query.
+
+## Prerequisites
+* An installation of Apache Geode.
+* Apache Geode Native, built and installed.
+* Apache Geode Native examples, built.
+* A `GEODE_HOME` environment variable set to the location of the Apache Geode
installation.
+
+## Running
+1. Set the current directory to the `continuousquery` directory in your
installed example workspace.
+
+ ```
+ $ cd workspace/examples/cpp/continuousquery
+ ```
+
+1. Run the `startserver.sh` script to start the Geode locator, server, and
create a region.
+
+ ```
+ $ sh ./startserver.sh
+ /Users/user/geode/bin/gfsh
+
+ (1) Executing - start locator --name=locator
+ ...
+ (2) Executing - start server --name=server
+ ...
+ (3) Executing - create region --name=custom_orders --type=PARTITION
+
+ Member | Status
+ ------ | -------------------------------------------
+ server | Region "/custom_orders" created on "server"
+ ```
+
+1. Execute `continuousquery`:
+
+ ```
+ $ build/continuousquery
+ Executing continuous query
+ Create orders
+ Storing initial orders in the region
+ MyCqListener::OnEvent called with CREATE, key[Order2], value(2, product y,
37)
+ MyCqListener::OnEvent called with CREATE, key[Order4], value(4, product z,
102)
+ Making changes to existing order
+ MyCqListener::OnEvent called with CREATE, key[Order6], value(6, product z,
42)
+ MyCqListener::OnEvent called with UPDATE, key[Order2], value(2, product y,
45)
+ MyCqListener::OnEvent called with DESTROY, key[Order2], value(2, product y,
29)
+ MyCqListener::close called
+ ```
+
+1. Stop the server
+
+ ```
+ $ sh ./stopserver.sh
+ /Users/user/geode/bin/gfsh
+ (1) Executing - connect
+ ...
+ (2) Executing - stop server --name=server
+ ...
+ (3) Executing - stop locator --name=locator
+ ....
+ ```
diff --git a/examples/cpp/continuousquery/main.cpp
b/examples/cpp/continuousquery/main.cpp
new file mode 100644
index 0000000..93924ef
--- /dev/null
+++ b/examples/cpp/continuousquery/main.cpp
@@ -0,0 +1,136 @@
+/*
+ * 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 <iostream>
+#include <thread>
+
+#include <geode/CacheFactory.hpp>
+#include <geode/CqAttributesFactory.hpp>
+#include <geode/PoolManager.hpp>
+#include <geode/QueryService.hpp>
+#include <geode/RegionFactory.hpp>
+#include <geode/RegionShortcut.hpp>
+#include <geode/Struct.hpp>
+#include <geode/TypeRegistry.hpp>
+
+#include "Order.hpp"
+
+using namespace apache::geode::client;
+using namespace continuousquery;
+
+class MyCqListener : public CqListener {
+public:
+ void onEvent(const CqEvent& cqEvent) override {
+ auto opStr = "Default";
+
+ auto order = dynamic_cast<Order *>(cqEvent.getNewValue().get());
+ auto key(dynamic_cast<CacheableString *>(cqEvent.getKey().get()));
+
+ switch (cqEvent.getQueryOperation()) {
+ case CqOperation::OP_TYPE_CREATE:
+ opStr = "CREATE";
+ break;
+ case CqOperation::OP_TYPE_UPDATE:
+ opStr = "UPDATE";
+ break;
+ case CqOperation::OP_TYPE_DESTROY:
+ opStr = "DESTROY";
+ break;
+ default:
+ break;
+ }
+
+ // On a destroy event, if value dropped out of query but is still in the
+ // region, it will be valid, but if it was removed altogether it will be
+ // nullptr
+ if (order) {
+ std::cout << "MyCqListener::OnEvent called with " << opStr << ", key["
+ << key->value().c_str() << "], value(" << order->getOrderId()
+ << ", " << order->getName().c_str() << ", "
+ << order->getQuantity() << ")" << std::endl;
+ } else {
+ std::cout << "MyCqListener::OnEvent called with " << opStr << ", key["
+ << key->value().c_str() << "], value is nullptr" << std::endl;
+ }
+ }
+
+ void onError(const CqEvent& cqEvent) override {
+ std::cout << __FUNCTION__ << " called" << std::endl;
+ }
+
+ void close() override { std::cout << __FUNCTION__ << " called" << std::endl;
}
+};
+
+int main(int argc, char** argv) {
+ auto cacheFactory = CacheFactory();
+ cacheFactory.set("log-level", "none");
+ auto cache = cacheFactory.create();
+ auto poolFactory = cache.getPoolManager().createFactory();
+ auto pool = poolFactory.addLocator("localhost", 10334)
+ .setSubscriptionEnabled(true)
+ .create("pool");
+
+ auto regionFactory = cache.createRegionFactory(RegionShortcut::PROXY);
+
+ auto region = regionFactory.setPoolName("pool").create("custom_orders");
+
+ cache.getTypeRegistry().registerPdxType(Order::createDeserializable);
+
+ auto queryService = pool->getQueryService();
+
+ CqAttributesFactory cqFactory;
+
+ auto cqListener = std::make_shared<MyCqListener>();
+
+ cqFactory.addCqListener(cqListener);
+ auto cqAttributes = cqFactory.create();
+
+ auto query = queryService->newCq(
+ "MyCq", "SELECT * FROM /custom_orders c WHERE c.quantity > 30",
+ cqAttributes);
+
+ std::cout << "Executing continuous query" << std::endl;
+ query->execute();
+
+ std::cout << "Create orders" << std::endl;
+ auto order1 = std::make_shared<Order>(1, "product x", 23);
+ auto order2 = std::make_shared<Order>(2, "product y", 37);
+ auto order3 = std::make_shared<Order>(3, "product z", 1);
+ auto order4 = std::make_shared<Order>(4, "product z", 102);
+ auto order5 = std::make_shared<Order>(5, "product x", 17);
+ auto order6 = std::make_shared<Order>(6, "product z", 42);
+
+ std::cout << "Putting and changing Order objects in the region" << std::endl;
+ region->put("Order1", order1);
+ region->put("Order2", order2);
+ region->put("Order3", order3);
+ region->put("Order4", order4);
+ region->put("Order5", order5);
+ region->put("Order6", order6);
+
+ region->put("Order2", std::make_shared<Order>(2, "product y", 45));
+ region->put("Order2", std::make_shared<Order>(2, "product y", 29));
+
+ region->remove("Order6");
+
+ std::this_thread::sleep_for(std::chrono::seconds(2));
+
+ query->stop();
+ query->close();
+
+ cache.close();
+}
diff --git a/examples/cpp/CMakeLists.txt.in
b/examples/cpp/continuousquery/startserver.sh
old mode 100644
new mode 100755
similarity index 63%
copy from examples/cpp/CMakeLists.txt.in
copy to examples/cpp/continuousquery/startserver.sh
index 5bde343..2c947ea
--- a/examples/cpp/CMakeLists.txt.in
+++ b/examples/cpp/continuousquery/startserver.sh
@@ -13,12 +13,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.10)
+#!/bin/env bash
+GFSH_PATH=""
+which gfsh 2> /dev/null
-project(@[email protected] LANGUAGES NONE)
+if [ $? -eq 0 ]; then
+ GFSH_PATH="gfsh"
+else
+if [ "$GEODE_HOME" == "" ]; then
+ echo "Could not find gfsh. Please set the GEODE_HOME path."
+ echo "e.g. export GEODE_HOME=<path to Geode>"
+ else
+ GFSH_PATH=$GEODE_HOME/bin/gfsh
+ fi
+fi
-add_subdirectory(dataserializable)
-add_subdirectory(pdxserializable)
-add_subdirectory(pdxserializer)
-add_subdirectory(put-get-remove)
-add_subdirectory(remotequery)
+$GFSH_PATH -e "start locator --name=locator" -e "start server --name=server"
-e "create region --name=custom_orders --type=PARTITION"
diff --git a/examples/cpp/CMakeLists.txt.in
b/examples/cpp/continuousquery/stopserver.sh
old mode 100644
new mode 100755
similarity index 65%
copy from examples/cpp/CMakeLists.txt.in
copy to examples/cpp/continuousquery/stopserver.sh
index 5bde343..f406a23
--- a/examples/cpp/CMakeLists.txt.in
+++ b/examples/cpp/continuousquery/stopserver.sh
@@ -13,12 +13,19 @@
# See the License for the specific language governing permissions and
# limitations under the License.
-cmake_minimum_required(VERSION 3.10)
+#!/bin/env bash
+GFSH_PATH=""
+which gfsh 2> /dev/null
-project(@[email protected] LANGUAGES NONE)
+if [ $? -eq 0 ]; then
+ GFSH_PATH="gfsh"
+else
+ if [ "$GEODE_HOME" == "" ]; then
+ echo "Could not find gfsh. Please set the GEODE_HOME path."
+ echo "e.g. export GEODE_HOME=<path to Geode>"
+ else
+ GFSH_PATH=$GEODE_HOME/bin/gfsh
+ fi
+fi
-add_subdirectory(dataserializable)
-add_subdirectory(pdxserializable)
-add_subdirectory(pdxserializer)
-add_subdirectory(put-get-remove)
-add_subdirectory(remotequery)
+$GFSH_PATH -e "connect" -e "stop server --name=server" -e "stop locator
--name=locator"
diff --git a/examples/cpp/pdxserializable/Order.cpp
b/examples/cpp/pdxserializable/Order.cpp
index af4e22d..cff2c2d 100644
--- a/examples/cpp/pdxserializable/Order.cpp
+++ b/examples/cpp/pdxserializable/Order.cpp
@@ -14,7 +14,6 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-#include <sstream>
#include "Order.hpp"
@@ -24,27 +23,25 @@
namespace customserializable {
void Order::fromData(PdxReader& pdxReader) {
- order_id_ = static_cast<uint32_t>(pdxReader.readLong(ORDER_ID_KEY_));
+ order_id_ = pdxReader.readInt(ORDER_ID_KEY_);
name_ = pdxReader.readString(NAME_KEY_);
- quantity_ = static_cast<uint16_t>(pdxReader.readInt(QUANTITY_KEY_));
+ quantity_ = pdxReader.readShort(QUANTITY_KEY_);
}
void Order::toData(PdxWriter& pdxWriter) const {
- pdxWriter.writeLong(ORDER_ID_KEY_, order_id_);
+ pdxWriter.writeInt(ORDER_ID_KEY_, order_id_);
pdxWriter.markIdentityField(ORDER_ID_KEY_);
pdxWriter.writeString(NAME_KEY_, name_);
pdxWriter.markIdentityField(NAME_KEY_);
- pdxWriter.writeInt(QUANTITY_KEY_, quantity_);
+ pdxWriter.writeShort(QUANTITY_KEY_, quantity_);
pdxWriter.markIdentityField(QUANTITY_KEY_);
}
std::string Order::toString() const {
- std::stringstream strm;
-
- strm << "OrderID: " << order_id_ << " Product Name: " << name_ << "
Quantity: " << quantity_;
- return strm.str();
+ return "OrderID: " + std::to_string(order_id_) + " Product Name: " + name_ +
+ " Quantity: " + std::to_string(quantity_);
}
const std::string& Order::getClassName() const {
@@ -52,7 +49,7 @@ const std::string& Order::getClassName() const {
return CLASS_NAME;
}
-std::shared_ptr<PdxSerializable> Order::create() {
+std::shared_ptr<PdxSerializable> Order::createDeserializable() {
return std::make_shared<Order>();
}
diff --git a/examples/cpp/pdxserializable/Order.hpp
b/examples/cpp/pdxserializable/Order.hpp
index fc17689..714b99c 100644
--- a/examples/cpp/pdxserializable/Order.hpp
+++ b/examples/cpp/pdxserializable/Order.hpp
@@ -32,12 +32,12 @@ class Order : public PdxSerializable {
public:
inline Order() : Order(0, "", 0) {}
- inline Order(uint32_t order_id, std::string name, uint16_t quantity)
+ inline Order(int32_t order_id, std::string name, int16_t quantity)
: order_id_(order_id), name_(std::move(name)), quantity_(quantity) {}
~Order() override = default;
- inline uint32_t getOrderId() const { return order_id_; }
+ inline int32_t getOrderId() const { return order_id_; }
inline const std::string& getName() const { return name_; }
@@ -55,16 +55,16 @@ class Order : public PdxSerializable {
const std::string& getClassName() const override;
- static std::shared_ptr<PdxSerializable> create();
+ static std::shared_ptr<PdxSerializable> createDeserializable();
private:
static const std::string ORDER_ID_KEY_;
static const std::string NAME_KEY_;
static const std::string QUANTITY_KEY_;
- uint32_t order_id_;
+ int32_t order_id_;
std::string name_;
- uint16_t quantity_;
+ int16_t quantity_;
};
} // namespace customserializable
diff --git a/examples/cpp/pdxserializable/main.cpp
b/examples/cpp/pdxserializable/main.cpp
index 420ba33..ec14839 100644
--- a/examples/cpp/pdxserializable/main.cpp
+++ b/examples/cpp/pdxserializable/main.cpp
@@ -41,7 +41,7 @@ int main(int argc, char** argv) {
auto regionFactory = cache.createRegionFactory(RegionShortcut::PROXY);
auto region = regionFactory.setPoolName("pool").create("custom_orders");
- cache.getTypeRegistry().registerPdxType(Order::create);
+ cache.getTypeRegistry().registerPdxType(Order::createDeserializable);
std::cout << "Create orders" << std::endl;
auto order1 = std::make_shared<Order>(1, "product x", 23);
diff --git a/examples/cpp/remotequery/Order.cpp
b/examples/cpp/remotequery/Order.cpp
index 08a9c59..c097346 100644
--- a/examples/cpp/remotequery/Order.cpp
+++ b/examples/cpp/remotequery/Order.cpp
@@ -23,19 +23,19 @@
namespace remotequery {
void Order::fromData(PdxReader& pdxReader) {
- order_id_ = static_cast<uint32_t>(pdxReader.readLong(ORDER_ID_KEY_));
+ order_id_ = pdxReader.readInt(ORDER_ID_KEY_);
name_ = pdxReader.readString(NAME_KEY_);
- quantity_ = static_cast<uint16_t>(pdxReader.readInt(QUANTITY_KEY_));
+ quantity_ = pdxReader.readShort(QUANTITY_KEY_);
}
void Order::toData(PdxWriter& pdxWriter) const {
- pdxWriter.writeLong(ORDER_ID_KEY_, order_id_);
+ pdxWriter.writeInt(ORDER_ID_KEY_, order_id_);
pdxWriter.markIdentityField(ORDER_ID_KEY_);
pdxWriter.writeString(NAME_KEY_, name_);
pdxWriter.markIdentityField(NAME_KEY_);
- pdxWriter.writeInt(QUANTITY_KEY_, quantity_);
+ pdxWriter.writeShort(QUANTITY_KEY_, quantity_);
pdxWriter.markIdentityField(QUANTITY_KEY_);
}
diff --git a/examples/cpp/remotequery/Order.hpp
b/examples/cpp/remotequery/Order.hpp
index 4a28762..d78c134 100644
--- a/examples/cpp/remotequery/Order.hpp
+++ b/examples/cpp/remotequery/Order.hpp
@@ -32,12 +32,12 @@ class Order : public PdxSerializable {
public:
inline Order() : Order(0, "", 0) {}
- inline Order(uint32_t order_id, std::string name, uint16_t quantity)
+ inline Order(int32_t order_id, std::string name, int16_t quantity)
: order_id_(order_id), name_(std::move(name)), quantity_(quantity) {}
~Order() override = default;
- inline uint32_t getOrderId() const { return order_id_; }
+ inline int32_t getOrderId() const { return order_id_; }
inline const std::string& getName() const { return name_; }
@@ -62,9 +62,9 @@ class Order : public PdxSerializable {
static const std::string NAME_KEY_;
static const std::string QUANTITY_KEY_;
- uint32_t order_id_;
+ int32_t order_id_;
std::string name_;
- uint16_t quantity_;
+ int16_t quantity_;
};
} // namespace remotequery