| 305 | }; |
| 306 | |
| 307 | void SetString(const reflection::Schema &schema, const std::string &val, |
| 308 | const String *str, std::vector<uint8_t> *flatbuf, |
| 309 | const reflection::Object *root_table) { |
| 310 | auto delta = static_cast<int>(val.size()) - static_cast<int>(str->size()); |
| 311 | auto str_start = static_cast<uoffset_t>( |
| 312 | reinterpret_cast<const uint8_t *>(str) - vector_data(*flatbuf)); |
| 313 | auto start = str_start + static_cast<uoffset_t>(sizeof(uoffset_t)); |
| 314 | if (delta) { |
| 315 | // Clear the old string, since we don't want parts of it remaining. |
| 316 | memset(vector_data(*flatbuf) + start, 0, str->size()); |
| 317 | // Different size, we must expand (or contract). |
| 318 | ResizeContext(schema, start, delta, flatbuf, root_table); |
| 319 | // Set the new length. |
| 320 | WriteScalar(vector_data(*flatbuf) + str_start, |
| 321 | static_cast<uoffset_t>(val.size())); |
| 322 | } |
| 323 | // Copy new data. Safe because we created the right amount of space. |
| 324 | memcpy(vector_data(*flatbuf) + start, val.c_str(), val.size() + 1); |
| 325 | } |
| 326 | |
| 327 | uint8_t *ResizeAnyVector(const reflection::Schema &schema, uoffset_t newsize, |
| 328 | const VectorOfAny *vec, uoffset_t num_elems, |
nothing calls this directly
no test coverage detected