Add array support to MetalClaw
This commit is contained in:
+3
-2
@@ -39,7 +39,7 @@ class MetalClawReader {
|
|||||||
int op(const char*, bool *val);
|
int op(const char*, bool *val);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int op(const char*, T **val, size_t len);
|
int op(const char*, T *val, size_t len);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int op(const char*, T *val);
|
int op(const char*, T *val);
|
||||||
@@ -111,7 +111,7 @@ int MetalClawReader::readInteger(I *val) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int MetalClawReader::op(const char*, T **val, size_t valLen) {
|
int MetalClawReader::op(const char*, T *val, size_t valLen) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
if (m_fieldPresence.get(m_field)) {
|
if (m_fieldPresence.get(m_field)) {
|
||||||
// read the length
|
// read the length
|
||||||
@@ -131,6 +131,7 @@ int MetalClawReader::op(const char*, T **val, size_t valLen) {
|
|||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
err |= reader.op("", &val[i]);
|
err |= reader.op("", &val[i]);
|
||||||
}
|
}
|
||||||
|
m_buffIt += reader.m_buffIt;
|
||||||
} else {
|
} else {
|
||||||
err = MC_OUTBUFFENDED;
|
err = MC_OUTBUFFENDED;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ struct TestStruct {
|
|||||||
bool Bool = false;
|
bool Bool = false;
|
||||||
int32_t Int = 0;
|
int32_t Int = 0;
|
||||||
bstring<32> String = "";
|
bstring<32> String = "";
|
||||||
|
int List[4] = {0, 0, 0 , 0};
|
||||||
TestStructNest Struct;
|
TestStructNest Struct;
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -47,6 +48,7 @@ int ioOp(T *io, TestStruct *obj) {
|
|||||||
err |= io->op("Bool", &obj->Bool);
|
err |= io->op("Bool", &obj->Bool);
|
||||||
err |= io->op("Int", &obj->Int);
|
err |= io->op("Int", &obj->Int);
|
||||||
err |= io->op("String", &obj->String);
|
err |= io->op("String", &obj->String);
|
||||||
|
err |= io->op("List", obj->List, 4);
|
||||||
err |= io->op("Struct", &obj->Struct);
|
err |= io->op("Struct", &obj->Struct);
|
||||||
return err;
|
return err;
|
||||||
}
|
}
|
||||||
@@ -81,6 +83,10 @@ map<string, int(*)(string)> tests = {
|
|||||||
testIn.Bool = true;
|
testIn.Bool = true;
|
||||||
testIn.Int = 42;
|
testIn.Int = 42;
|
||||||
testIn.String = "Test String 1";
|
testIn.String = "Test String 1";
|
||||||
|
testIn.List[0] = 1;
|
||||||
|
testIn.List[1] = 2;
|
||||||
|
testIn.List[2] = 3;
|
||||||
|
testIn.List[3] = 4;
|
||||||
testIn.Struct.Bool = false;
|
testIn.Struct.Bool = false;
|
||||||
testIn.Struct.Int = 300;
|
testIn.Struct.Int = 300;
|
||||||
testIn.Struct.String = "Test String 2";
|
testIn.Struct.String = "Test String 2";
|
||||||
@@ -91,6 +97,10 @@ map<string, int(*)(string)> tests = {
|
|||||||
err |= !(testIn.Bool == testOut.Bool);
|
err |= !(testIn.Bool == testOut.Bool);
|
||||||
err |= !(testIn.Int == testOut.Int);
|
err |= !(testIn.Int == testOut.Int);
|
||||||
err |= !(testIn.String == testOut.String);
|
err |= !(testIn.String == testOut.String);
|
||||||
|
err |= !(testIn.List[0] == testOut.List[0]);
|
||||||
|
err |= !(testIn.List[1] == testOut.List[1]);
|
||||||
|
err |= !(testIn.List[2] == testOut.List[2]);
|
||||||
|
err |= !(testIn.List[3] == testOut.List[3]);
|
||||||
err |= !(testIn.Struct.Bool == testOut.Struct.Bool);
|
err |= !(testIn.Struct.Bool == testOut.Struct.Bool);
|
||||||
err |= !(testIn.Struct.Int == testOut.Struct.Int);
|
err |= !(testIn.Struct.Int == testOut.Struct.Int);
|
||||||
err |= !(testIn.Struct.String == testOut.Struct.String);
|
err |= !(testIn.Struct.String == testOut.Struct.String);
|
||||||
|
|||||||
+7
-5
@@ -39,7 +39,7 @@ class MetalClawWriter {
|
|||||||
int op(const char*, bool *val);
|
int op(const char*, bool *val);
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int op(const char*, T **val, size_t len);
|
int op(const char*, T *val, size_t len);
|
||||||
|
|
||||||
template<size_t L>
|
template<size_t L>
|
||||||
int op(const char*, ox::bstring<L> *val);
|
int op(const char*, ox::bstring<L> *val);
|
||||||
@@ -106,11 +106,9 @@ int MetalClawWriter::appendInteger(I val) {
|
|||||||
};
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
int MetalClawWriter::op(const char *fieldName, T **val, size_t len) {
|
int MetalClawWriter::op(const char*, T *val, size_t len) {
|
||||||
int err = 0;
|
int err = 0;
|
||||||
bool fieldSet = false;
|
bool fieldSet = false;
|
||||||
MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt);
|
|
||||||
writer.setFields(len);
|
|
||||||
|
|
||||||
// write the length
|
// write the length
|
||||||
typedef uint32_t ArrayLength;
|
typedef uint32_t ArrayLength;
|
||||||
@@ -121,11 +119,15 @@ int MetalClawWriter::op(const char *fieldName, T **val, size_t len) {
|
|||||||
err = MC_BUFFENDED;
|
err = MC_BUFFENDED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MetalClawWriter writer(m_buff + m_buffIt, m_buffLen - m_buffIt);
|
||||||
|
writer.setFields(len);
|
||||||
|
|
||||||
// write the string
|
// write the string
|
||||||
for (size_t i = 0; i < len; i++) {
|
for (size_t i = 0; i < len; i++) {
|
||||||
err |= writer.op("", val[i]);
|
err |= writer.op("", &val[i]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_buffIt += writer.m_buffIt;
|
||||||
fieldSet = true;
|
fieldSet = true;
|
||||||
|
|
||||||
err |= m_fieldPresence.set(m_field, fieldSet);
|
err |= m_fieldPresence.set(m_field, fieldSet);
|
||||||
|
|||||||
Reference in New Issue
Block a user