table Person {
jobs: [Job];
}
table Job {
company: string;
wage: float;
companyInfo: CompanyInfo;
}
table CompanyInfo {
name: string;
address: string;
numOfStaffs: int;
}
std::vector<uint8_t> resizingbuf(flatbuf, flatbuf +flatbuf.size()); // With flatbuf is the whole FlatBuffer data of the Person record.
auto rroot = flatbuffers::piv(tableDataPtr, resizingbuf); // with tableDataPtr is a flatbuffers::Table* that was calculated as "Person.jobs[1]" previously. I can make sure that tableDataPtr is retrieve correctly, because I can update a scalar field correctly.
SetString(schema, "NEW ADDRESS!!!", GetFieldS(**rroot, fieldNeedToEdit), &resizingbuf, root_table); // with fieldNeedToEdit is field "address" inside table "CompanyInfo", root_table is table "CompanyInfo".
--
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...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
std::vector<uint8_t> resizingbuf(itemPtr->data.data(), itemPtr->data.data()+itemPtr->data.size()); // resizingbuf is now the WHOLE Flatbuf of Root table
// trace Field from outer to inner (Person --> Job --> CompanyInfo --> address)
if(field is Object) {
rroot = schema::piv(flatbuffer::GetFieldT(**rroot, *fieldToSelect), resizingbuf);
// update the field
} else if(field is Vector of Object) {
const flatbuffers::Table* tableVectorItem = schema::GetFieldV<flatbuffers::Offset<schema::Table>>(**rroot, *fieldToSelect)->Get(fieldIndex);
rroot = schema::piv(const_cast<flatbuffers::Table*>(tableVectorItem), resizingbuf); // I HAVE to cast to remove const qualifier here. AM I WRONG HERE????
// update the field
}
{
"custId": -3479823489239,
"custName": "Hello, it's me",
"interestingNumbers": [
132,-3422,111111,-4235,32,32,4321
],
"interestingQuotes": [
"Never forget what you are, the rest of the world will not. Wear it like armor, and it can never be used to hurt you",
"I am that I am",
"Hello, bye!"
],
"address": {
"home_number": 12341242,
"street": "Love boulevard"
},
"jobs": [
{
"company": "Viettel",
"wage": 50000000.123,
"title": "Department manager",
"companyInfo": {
"name": "Viettel",
"slogan": "Say it your way",
"stockPrice": 123434523,
"departments": [
{
"name": "Hoa Lac Palace",
"numOfStaffs": 2345
},
{
"name": "Giang Van Minh",
"numOfStaffs": 500
},
{
"name": "Viettel Head Quarter",
"numOfStaffs": 456
}
],
"headQuarter": {
"address": "No.1 Nguyen Huu Duc",
"managers": [
{
"name": "Nguyen Hoang Quan",
"age": 40,
"area": "General Mananager"
},
{
"name": "Nguyen Manh Hung",
"age": 77,
"area": "Associate"
},
{
"name": "Tong Viet Trung",
"age": 78,
"area": "Finance"
}
]
}
}
},
{
"company": "Freelancer",
"wage": 407840784078.23,
"title": "No title"
}
],
"inner1": {
"inner2": {
"inner3_arr": [
{
"inner4": "AAA"
},
{
"inner4": "BBB"
},
{
"inner4": "CCC"
}
],
"inner3": {
"inner4": "EEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEE"
}
}
}
}
"custName": NOK
"address.home_number": NOK
"address.street": NOK
"jobs[0].company": OK
"jobs[0].title": OK
"jobs[0].companyInfo.headQuarter.managers[1].age": OK
"jobs[0].companyInfo.headQuarter.address": OK
"jobs[0].companyInfo.headQuarter.managers[0].name": OK
"inner1.inner2.inner3.inner4": OK
"custName": NOK
"address.home_number": NOK
"jobs[0].company": NOK
"address.street": NOK
"jobs[0].title": OK
"jobs[0].companyInfo.headQuarter.managers[1].age": OK
"jobs[0].companyInfo.headQuarter.address": OK
"jobs[0].companyInfo.headQuarter.managers[0].name": OK
"inner1.inner2.inner3.inner4": OK
SetString(schema, "NEW ADDRESS!!!", GetFieldS(**rroot, fieldNeedToEdit), &resizingbuf, root_table); // with fieldNeedToEdit is field "address" inside table "CompanyInfo", root_table is table "CompanyInfo".
// If your FlatBuffer's root table is not the schema's root table, you should
// pass in your root_table type as well.
--
SetFieldT(*rroot, name_field, string_ptr);
flatbuffers::FlatBufferBuilder fbb;
fbb.Finish(fbb.CreateVector<uint32_t>(elements, vecSize)); // vector of uint32_t
auto newVecPtr = schema::AddFlatBuffer(resizingbuf, fbb.GetBufferPointer(), fbb.GetSize());
schema::SetFieldT(*rroot, fieldNeedToEdit, newVecPtr);
WriteScalar(data_ + field_offset, val - (data_ + field_offset));