Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace hazelcast {

ClassDefinitionBuilder& addDoubleArrayField(const std::string& fieldName);

ClassDefinitionBuilder& addUTFArrayField(const std::string& fieldName);

ClassDefinitionBuilder& addFloatArrayField(const std::string& fieldName);

ClassDefinitionBuilder& addShortArrayField(const std::string& fieldName);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ namespace hazelcast {
*/
std::unique_ptr<std::vector<double> > readDoubleArray(const char *fieldName);


/**
* @param fieldName name of the field
* @return the utf string array value read
* @throws IOException
*/
std::unique_ptr<std::vector<std::string> > readUTFArray(const char *fieldName);

/**
* @param fieldName name of the field
* @return the float array value read
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,14 @@ namespace hazelcast {
void writeDoubleArray(const char *fieldName, const std::vector<double> *values);

/**
* @param fieldName name of the field
* @param values utf string array to be written
* @throws IOException
*/
void writeUTFArray(const char *fieldName, const std::vector<std::string> *values);


/**
* Internal api , should not be called by end user.
*/
void end();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,8 @@ namespace hazelcast {

void writeDoubleArray(const char *fieldName, const std::vector<double> *data);

void writeUTFArray(const char *fieldName, const std::vector<std::string> *data);

template<typename T>
void writeNullPortable(const char *fieldName) {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,8 @@ namespace hazelcast {

void writeDoubleArray(const char *fieldName, const std::vector<double> *data);

void writeUTFArray(const char *fieldName, const std::vector<std::string> *data);

void end();

template<typename T>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,8 @@ namespace hazelcast {

virtual std::unique_ptr<std::vector<double> > readDoubleArray(const char *fieldName);

virtual std::unique_ptr<std::vector<std::string> > readUTFArray(const char *fieldName);

virtual std::unique_ptr<std::vector<float> > readFloatArray(const char *fieldName);

virtual std::unique_ptr<std::vector<int16_t> > readShortArray(const char *fieldName);
Expand Down
31 changes: 31 additions & 0 deletions hazelcast/src/hazelcast/client/serialization.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,12 @@ namespace hazelcast {
return classDefinitionWriter->writeDoubleArray(fieldName, data);
}

void PortableWriter::writeUTFArray(const char *fieldName, const std::vector<std::string> *data) {
if (isDefaultWriter)
return defaultPortableWriter->writeUTFArray(fieldName, data);
return classDefinitionWriter->writeUTFArray(fieldName, data);
}

void PortableWriter::end() {
if (isDefaultWriter)
return defaultPortableWriter->end();
Expand Down Expand Up @@ -409,6 +415,11 @@ namespace hazelcast {
return *this;
}

ClassDefinitionBuilder &ClassDefinitionBuilder::addUTFArrayField(const std::string &fieldName) {
addField(fieldName, FieldTypes::TYPE_UTF_ARRAY);
return *this;
}

ClassDefinitionBuilder &ClassDefinitionBuilder::addFloatArrayField(const std::string &fieldName) {
addField(fieldName, FieldTypes::TYPE_FLOAT_ARRAY);
return *this;
Expand Down Expand Up @@ -1012,6 +1023,12 @@ namespace hazelcast {
return morphingPortableReader->readDoubleArray(fieldName);
}

std::unique_ptr<std::vector<std::string> > PortableReader::readUTFArray(const char *fieldName) {
if (isDefaultReader)
return defaultPortableReader->readUTFArray(fieldName);
return morphingPortableReader->readUTFArray(fieldName);
}

std::unique_ptr<std::vector<float> > PortableReader::readFloatArray(const char *fieldName) {
if (isDefaultReader)
return defaultPortableReader->readFloatArray(fieldName);
Expand Down Expand Up @@ -1213,6 +1230,10 @@ namespace hazelcast {
builder.addDoubleArrayField(fieldName);
}

void ClassDefinitionWriter::writeUTFArray(const char *fieldName, const std::vector<std::string> *values) {
builder.addUTFArrayField(fieldName);
}

void ClassDefinitionWriter::writeFloatArray(const char *fieldName, const std::vector<float> *values) {
builder.addFloatArrayField(fieldName);
}
Expand Down Expand Up @@ -1755,6 +1776,11 @@ namespace hazelcast {
dataOutput.writeFloatArray(data);
}

void DefaultPortableWriter::writeUTFArray(const char *fieldName, const std::vector<std::string> *data) {
setPosition(fieldName, FieldTypes::TYPE_UTF_ARRAY);
dataOutput.writeUTFArray(data);
}

void DefaultPortableWriter::writeDoubleArray(const char *fieldName, const std::vector<double> *data) {
setPosition(fieldName, FieldTypes::TYPE_DOUBLE_ARRAY);
dataOutput.writeDoubleArray(data);
Expand Down Expand Up @@ -2457,6 +2483,11 @@ namespace hazelcast {
return dataInput.readDoubleArray();
}

std::unique_ptr<std::vector<std::string> > PortableReaderBase::readUTFArray(const char *fieldName) {
setPosition(fieldName, FieldTypes::TYPE_UTF_ARRAY);
return dataInput.readUTFArray();
}

std::unique_ptr<std::vector<float> > PortableReaderBase::readFloatArray(const char *fieldName) {
setPosition(fieldName, FieldTypes::TYPE_FLOAT_ARRAY);
return dataInput.readFloatArray();
Expand Down
30 changes: 26 additions & 4 deletions hazelcast/test/src/HazelcastTests2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1411,6 +1411,10 @@ namespace hazelcast {
ff = std::vector<float>(floatArray, floatArray + 3);
double doubleArray[] = {456.456, 789.789, 321.321};
dd = std::vector<double>(doubleArray, doubleArray + 3);
std::string stringArray[] = {"イロハニホヘト", "チリヌルヲ", "ワカヨタレソ"};
for (int j = 0; j < 3; ++j) {
stringVector.push_back(stringArray[j]);
}
}

bool Employee::operator==(const Employee &rhs) const {
Expand Down Expand Up @@ -1451,6 +1455,7 @@ namespace hazelcast {
writer.writeIntArray("ii", &ii);
writer.writeFloatArray("ff", &ff);
writer.writeDoubleArray("dd", &dd);
writer.writeUTFArray("stringVector", &stringVector);

serialization::ObjectDataOutput &out = writer.getRawDataOutput();
out.writeObject<byte>(&by);
Expand Down Expand Up @@ -1486,6 +1491,7 @@ namespace hazelcast {
ii = *reader.readIntArray("ii");;
ff = *reader.readFloatArray("ff");;
dd = *reader.readDoubleArray("dd");;
stringVector = *reader.readUTFArray("stringVector");

serialization::ObjectDataInput &in = reader.getRawDataInput();
by = *in.readObject<byte>();
Expand Down Expand Up @@ -1953,8 +1959,10 @@ namespace hazelcast {
std::vector<int64_t> l,
std::vector<float> f,
std::vector<double> d,
std::vector<std::string> stringVector,
std::vector<TestNamedPortable> n) : ii(i), bb(b), ba(ba), cc(c), ss(s),
ll(l), ff(f), dd(d), nn(n) {
ll(l), ff(f), dd(d),
stringVector(std::move(stringVector)), nn(n) {
}

TestInnerPortable::~TestInnerPortable() {
Expand All @@ -1969,6 +1977,7 @@ namespace hazelcast {
ll = rhs.ll;
ff = rhs.ff;
dd = rhs.dd;
stringVector = rhs.stringVector;
nn = rhs.nn;
return (*this);
}
Expand All @@ -1990,6 +1999,7 @@ namespace hazelcast {
if (ll != m.ll) return false;
if (ff != m.ff) return false;
if (dd != m.dd) return false;
if (stringVector != m.stringVector) return false;
size_t size = nn.size();
for (size_t i = 0; i < size; i++)
if (nn[i] != m.nn[i])
Expand All @@ -2010,6 +2020,7 @@ namespace hazelcast {
writer.writeLongArray("l", &ll);
writer.writeFloatArray("f", &ff);
writer.writeDoubleArray("d", &dd);
writer.writeUTFArray("stringVector", &stringVector);
writer.writePortableArray("nn", &nn);
}

Expand All @@ -2022,6 +2033,7 @@ namespace hazelcast {
ll = *reader.readLongArray("l");
ff = *reader.readFloatArray("f");
dd = *reader.readDoubleArray("d");
stringVector = *reader.readUTFArray("stringVector");
nn = reader.readPortableArray<TestNamedPortable>("nn");
}

Expand Down Expand Up @@ -2458,14 +2470,18 @@ namespace hazelcast {
std::vector<float> ff(floatArray, floatArray + 3);
double doubleArray[] = {456.456, 789.789, 321.321};
std::vector<double> dd(doubleArray, doubleArray + 3);
std::string stringArray[] = {"イロハニホヘト", "チリヌルヲ", "ワカヨタレソ"};
std::vector<std::string> stringVector;
for (int i = 0; i < 3; i++)
stringVector.push_back(stringArray[i]);
TestNamedPortable portableArray[5];
for (int i = 0; i < 5; i++) {
portableArray[i].name = "named-portable-" + hazelcast::util::IOUtil::to_string(i);
portableArray[i].k = i;
}
std::vector<TestNamedPortable> nn(portableArray, portableArray + 5);

TestInnerPortable inner(bb, ba, cc, ss, ii, ll, ff, dd, nn);
TestInnerPortable inner(bb, ba, cc, ss, ii, ll, ff, dd, stringVector, nn);

data = serializationService.toData<TestInnerPortable>(&inner);

Expand Down Expand Up @@ -2517,6 +2533,7 @@ namespace hazelcast {
double *doubleArray;
doubleArray = new double[LARGE_ARRAY_SIZE];
std::vector<double> dd(doubleArray, doubleArray + LARGE_ARRAY_SIZE);
std::vector<std::string> stringVector(LARGE_ARRAY_SIZE);

TestNamedPortable portableArray[5];

Expand All @@ -2526,7 +2543,7 @@ namespace hazelcast {
}
std::vector<TestNamedPortable> nn(portableArray, portableArray + 5);

TestInnerPortable inner(bb, ba, cc, ss, ii, ll, ff, dd, nn);
TestInnerPortable inner(bb, ba, cc, ss, ii, ll, ff, dd, stringVector, nn);

data = serializationService.toData<TestInnerPortable>(&inner);

Expand Down Expand Up @@ -2589,14 +2606,19 @@ namespace hazelcast {
std::vector<float> ff(floatArray, floatArray + 3);
double doubleArray[] = {456.456, 789.789, 321.321};
std::vector<double> dd(doubleArray, doubleArray + 3);
std::string stringArray[] = {"イロハニホヘト", "チリヌルヲ", "ワカヨタレソ"};
std::vector<std::string> stringVector;
for (int i = 0; i < 3; ++i) {
stringVector.push_back(stringArray[i]);
}
TestNamedPortable portableArray[5];
for (int i = 0; i < 5; i++) {
portableArray[i].name = "named-portable-" + hazelcast::util::IOUtil::to_string(i);
portableArray[i].k = i;
}
std::vector<TestNamedPortable> nn(portableArray, portableArray + 5);

TestInnerPortable inner(bb, ba, cc, ss, ii, ll, ff, dd, nn);
TestInnerPortable inner(bb, ba, cc, ss, ii, ll, ff, dd, stringVector, nn);

data = serializationService.toData<TestInnerPortable>(&inner);

Expand Down
1 change: 1 addition & 0 deletions hazelcast/test/src/serialization/Employee.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ namespace hazelcast {
std::vector<int64_t > ll;
std::vector<float> ff;
std::vector<double> dd;
std::vector<std::string> stringVector;
};

// Compares based on the employee age
Expand Down
3 changes: 2 additions & 1 deletion hazelcast/test/src/serialization/TestInnerPortable.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ namespace hazelcast {

TestInnerPortable(std::vector<byte> b, std::vector<bool> ba, std::vector<char> c, std::vector<int16_t> s,
std::vector<int32_t> i, std::vector<int64_t> l, std::vector<float> f, std::vector<double> d,
std::vector<TestNamedPortable> n);
std::vector<std::string> stringVector, std::vector<TestNamedPortable> n);

TestInnerPortable& operator = (const TestInnerPortable& rhs);

Expand All @@ -66,6 +66,7 @@ namespace hazelcast {
std::vector<int64_t> ll;
std::vector<float> ff;
std::vector<double> dd;
std::vector<std::string> stringVector;
std::vector< TestNamedPortable > nn;

};
Expand Down