forked from hazelcast/hazelcast-cpp-client
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Backported fixes from master(hazelcast#37)
CHECK_NULL in SerializationService header moved to source file since MACRO's can collide with users MACRO when defined in header. A example code is provided for custom serialization. Related test codes are modified for custom serialization. For threads safety, instance of SerializationConstants is created in global space. ClassCastException for portable identified and custom serializable is added. These fixes are backported from hazelcast#37 Remove singleton usage of SerializationConstants to avoid thread safety issues.
- Loading branch information
sancar
committed
Feb 8, 2016
1 parent
95c56d1
commit b49dc42
Showing
18 changed files
with
258 additions
and
173 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,3 +15,4 @@ | |
# | ||
add_subdirectory(identified-data-serializable) | ||
add_subdirectory(portable) | ||
add_subdirectory(custom) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
# | ||
# Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. | ||
# | ||
# Licensed 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. | ||
# | ||
add_executable(custom ./main.cpp) | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
/* | ||
* Copyright (c) 2008-2015, Hazelcast, Inc. All Rights Reserved. | ||
* | ||
* Licensed 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 <hazelcast/client/HazelcastClient.h> | ||
#include <hazelcast/client/serialization/IdentifiedDataSerializable.h> | ||
#include <hazelcast/client/serialization/ObjectDataInput.h> | ||
#include <hazelcast/client/serialization/ObjectDataOutput.h> | ||
|
||
class Person { | ||
public: | ||
Person() { | ||
} | ||
|
||
Person(const std::string& n) : name(n) { | ||
} | ||
|
||
void setName(const std::string& n) { | ||
name = n; | ||
} | ||
|
||
|
||
const std::string& getName() const { | ||
return name; | ||
} | ||
|
||
int getTypeId() const{ | ||
return 666; | ||
} | ||
|
||
private: | ||
std::string name; | ||
}; | ||
|
||
|
||
|
||
class CustomSerializer : public hazelcast::client::serialization::Serializer<Person> { | ||
public: | ||
|
||
void write(hazelcast::client::serialization::ObjectDataOutput & out, const Person& object) { | ||
out.writeInt(666); | ||
out.writeUTF(&(object.getName())); | ||
out.writeInt(666); | ||
} | ||
|
||
void read(hazelcast::client::serialization::ObjectDataInput & in, Person& object) { | ||
int i = in.readInt(); | ||
assert(i == 666); | ||
object.setName(*(in.readUTF())); | ||
i = in.readInt(); | ||
assert(i == 666); | ||
} | ||
|
||
int getTypeId() const { | ||
return 666; | ||
}; | ||
}; | ||
|
||
std::ostream &operator<<(std::ostream &out, const Person &p) { | ||
const std::string & str = p.getName(); | ||
out << str; | ||
return out; | ||
} | ||
|
||
int main() { | ||
hazelcast::client::ClientConfig config; | ||
hazelcast::client::SerializationConfig serializationConfig; | ||
serializationConfig.registerSerializer(boost::shared_ptr<hazelcast::client::serialization::SerializerBase>(new CustomSerializer())); | ||
config.setSerializationConfig(serializationConfig); | ||
hazelcast::client::HazelcastClient hz(config); | ||
|
||
hazelcast::client::IMap<std::string, Person> map = hz.getMap<std::string, Person>("map"); | ||
Person testPerson("bar"); | ||
map.put("foo", testPerson); | ||
std::cout << *(map.get("foo")) << std::endl; | ||
std::cout << "Finished" << std::endl; | ||
|
||
return 0; | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.