[ox] Make TypeStore own all type info

This commit is contained in:
2022-05-28 19:55:46 -05:00
parent 440d9c0a46
commit 9c3a46d144
18 changed files with 312 additions and 258 deletions

View File

@ -16,7 +16,6 @@
union TestUnion {
static constexpr auto TypeName = "TestUnion";
static constexpr auto Fields = 3;
bool Bool;
uint32_t Int = 5;
char CString[32];
@ -24,7 +23,6 @@ union TestUnion {
struct TestStructNest {
static constexpr auto TypeName = "TestStructNest";
static constexpr auto Fields = 3;
bool Bool = false;
uint32_t Int = 0;
ox::BString<32> BString = "";
@ -32,7 +30,6 @@ struct TestStructNest {
struct TestStruct {
static constexpr auto TypeName = "TestStruct";
static constexpr auto Fields = 16;
bool Bool = false;
int32_t Int = 0;
int32_t Int1 = 0;
@ -272,7 +269,7 @@ std::map<ox::String, ox::Error(*)()> tests = {
[] {
//constexpr size_t descBuffLen = 1024;
//uint8_t descBuff[descBuffLen];
static constexpr size_t dataBuffLen = 1024;
static constexpr size_t dataBuffLen = ox::units::MB;
char dataBuff[dataBuffLen];
TestStruct testIn, testOut;
testIn.Bool = true;
@ -286,10 +283,11 @@ std::map<ox::String, ox::Error(*)()> tests = {
testIn.Struct.Int = 300;
testIn.Struct.BString = "Test String 2";
oxAssert(ox::writeMC(dataBuff, dataBuffLen, &testIn), "Data generation failed");
auto type = ox::buildTypeDef(&testIn);
ox::TypeStore typeStore;
auto type = ox::buildTypeDef(&typeStore, &testIn);
oxAssert(type.error, "Descriptor write failed");
oxReturnError(ox::walkModel<ox::MetalClawReader>(type.value.get(), dataBuff, dataBuffLen,
[](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::TypeName>&, const ox::DescriptorField &f, ox::MetalClawReader *rdr) -> ox::Error {
oxReturnError(ox::walkModel<ox::MetalClawReader>(type.value, dataBuff, dataBuffLen,
[](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::String>&, const ox::DescriptorField &f, ox::MetalClawReader *rdr) -> ox::Error {
//std::cout << f.fieldName.c_str() << '\n';
auto fieldName = f.fieldName.c_str();
switch (f.type->primitiveType) {
@ -360,10 +358,10 @@ std::map<ox::String, ox::Error(*)()> tests = {
break;
}
case ox::PrimitiveType::String: {
ox::Vector<char> v(rdr->stringLength(fieldName) + 1);
ox::String s;
//std::cout << rdr->stringLength() << '\n';
oxAssert(rdr->field(fieldName, ox::SerStr(v.data(), v.size())), "Walking model failed.");
std::cout << fieldName << ":\t" << "string:\t\t" << v.data() << '\n';
oxAssert(rdr->field(fieldName, &s), "Walking model failed.");
oxOutf("{}:\tstring:\t\t{}\n", fieldName, s);
break;
}
case ox::PrimitiveType::Struct: