[ox] Replace uint8_t* with char* as buffer type in MC, OC, and Model

This commit is contained in:
Gary Talent 2021-05-03 14:15:07 -04:00
parent c4c1979123
commit 4f2c0b2e30
5 changed files with 10 additions and 12 deletions

View File

@ -271,8 +271,8 @@ void MetalClawReader::setTypeInfo(const char*, int fields) {
}
template<typename T>
Error readMC(const uint8_t *buff, std::size_t buffLen, T *val) {
MetalClawReader reader(buff, buffLen);
Error readMC(const char *buff, std::size_t buffLen, T *val) {
MetalClawReader reader(bit_cast<uint8_t*>(buff), buffLen);
return model(&reader, val);
}

View File

@ -110,11 +110,9 @@ std::map<std::string, ox::Error(*)()> tests = {
// This test doesn't confirm much, but it does show that the writer
// doesn't segfault
constexpr size_t buffLen = 1024;
uint8_t buff[buffLen];
char buff[buffLen];
TestStruct ts;
oxReturnError(ox::writeMC(buff, buffLen, &ts));
return OxError(0);
}
},
@ -122,7 +120,7 @@ std::map<std::string, ox::Error(*)()> tests = {
"MetalClawReader",
[] {
constexpr size_t buffLen = 1024;
uint8_t buff[buffLen];
char buff[buffLen];
TestStruct testIn, testOut;
testIn.Bool = true;
@ -284,7 +282,7 @@ std::map<std::string, ox::Error(*)()> tests = {
//constexpr size_t descBuffLen = 1024;
//uint8_t descBuff[descBuffLen];
constexpr size_t dataBuffLen = 1024;
uint8_t dataBuff[dataBuffLen];
char dataBuff[dataBuffLen];
TestStruct testIn, testOut;
testIn.Bool = true;

View File

@ -232,8 +232,8 @@ Result<Vector<char>> writeMC(T *val) {
}
template<typename T>
Error writeMC(uint8_t *buff, std::size_t buffLen, T *val, std::size_t *sizeOut = nullptr) {
MetalClawWriter writer(buff, buffLen);
Error writeMC(char *buff, std::size_t buffLen, T *val, std::size_t *sizeOut = nullptr) {
MetalClawWriter writer(bit_cast<uint8_t*>(buff), buffLen);
auto err = model(&writer, val);
if (sizeOut) {
*sizeOut = writer.size();

View File

@ -145,9 +145,9 @@ Error model(Reader *rdr, DataWalker<Reader, FH> *walker) {
}
template<typename Reader, typename Handler>
Error walkModel(DescriptorType *type, uint8_t *data, std::size_t dataLen, Handler handler) {
Error walkModel(DescriptorType *type, char *data, std::size_t dataLen, Handler handler) {
DataWalker<Reader, Handler> walker(type, handler);
Reader rdr(data, dataLen);
Reader rdr(bit_cast<uint8_t*>(data), dataLen);
return model(&rdr, &walker);
}

View File

@ -199,7 +199,7 @@ const std::map<std::string_view, ox::Error(*)()> tests = {
oxAssert(ocErr, "Data generation failed");
auto type = ox::buildTypeDef(&testIn);
oxAssert(type.error, "Descriptor write failed");
oxReturnError(ox::walkModel<ox::OrganicClawReader>(type.value, ox::bit_cast<uint8_t*>(oc.data()), oc.size(),
oxReturnError(ox::walkModel<ox::OrganicClawReader>(type.value, oc.data(), oc.size(),
[](const ox::Vector<ox::FieldName>&, const ox::Vector<ox::TypeName>&, const ox::DescriptorField &f, ox::OrganicClawReader *rdr) -> ox::Error {
auto fieldName = f.fieldName.c_str();
switch (f.type->primitiveType) {