256 int array offset in uint

45 views
Skip to first unread message

Carl Keifer

unread,
Mar 28, 2017, 11:30:08 AM3/28/17
to FlatBuffers
So I have a schema comprised of a table with two entries.

table sometable
{
       someVal:[ubyte];
       iterator:[uint];
}

the builder works fine and compiles ok. verifier passes at both ends I fill the loop by reading a different type of table it gets someVal from the table and inserts it. iterator is assigned to the column using a counter. then I verify and check the table the data looks like it is correct, then we write out the binary buffer. 

flatbuffers::FlatBufferBuilder builder;
std::vector<uint8_t> vals;
std::vector<uint32_t> indices;


int tCount = object->GetTableCount();
uint32_t iCount = 0;

std::cout << "Evaluating " << tCount << " Tables" << std::endl;
// evaluate every table
for (int p = 0; p < tCount; p++)
{
int nVals = table->GetObjectsInTable(t);
// now evaluate all values in the table
for (int v = 0; v < nVals; v++)
{
// Get the index for the vert
int vIndex = table->GetTableEntry(p, v);

// now get all the elements of the table for export.
Vector4 tableCol = cTable[vIndex];


float vT1 = (float)tableCol[0];
auto T1 = reinterpret_cast<const uint8_t*>(&vT1);
verts.insert(verts.end(), T1, T1 + sizeof(float));
float vT2 = (float)tableCol[1];
auto T2 = reinterpret_cast<const uint8_t*>(&vT2);
verts.insert(verts.end(), T2, T2 + sizeof(float));
float T3 = (float)tableCol[2];
auto T3 = reinterpret_cast<const uint8_t*>(&vT3);
verts.insert(verts.end(), T3, T3 + sizeof(float));

indices.push_back(vCount);
}
vCount++;
}

auto indexVec = builder.CreateVector(indices);
auto valsVec = builder.CreateVector(vals);

auto table = evr::CreateTable(builder, indexVec, valsVec);
builder.Finish(table);

When I read back in to verify the someVal array evaluates correctly. but iterator does not. it stores the first 10 values 0-9 then skips ahead to 2573. which is offset from the expected value which is 10 the next value is 2816 offset from the previous value by 243. every subsequent value is offset by 256. Any ideas what I might have done wrong.

Wouter van Oortmerssen

unread,
Mar 29, 2017, 5:32:16 PM3/29/17
to Carl Keifer, FlatBuffers
Sorry, I don't understand how the code above relates to the program you're describing. Can you reduce the problem to the minimal program that builds a FlatBuffer of said schema, and then one that reads it?

--
You received this message because you are subscribed to the Google Groups "FlatBuffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flatbuffers+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages