| 1503 | |
| 1504 | template<typename T> |
| 1505 | size_t ScalarVector(const T *elems, size_t len, bool fixed) { |
| 1506 | auto vector_type = GetScalarType<T>(); |
| 1507 | auto byte_width = sizeof(T); |
| 1508 | auto bit_width = WidthB(byte_width); |
| 1509 | // If you get this assert, you're trying to write a vector with a size |
| 1510 | // field that is bigger than the scalars you're trying to write (e.g. a |
| 1511 | // byte vector > 255 elements). For such types, write a "blob" instead. |
| 1512 | // TODO: instead of asserting, could write vector with larger elements |
| 1513 | // instead, though that would be wasteful. |
| 1514 | FLATBUFFERS_ASSERT(WidthU(len) <= bit_width); |
| 1515 | Align(bit_width); |
| 1516 | if (!fixed) Write<uint64_t>(len, byte_width); |
| 1517 | auto vloc = buf_.size(); |
| 1518 | for (size_t i = 0; i < len; i++) Write(elems[i], byte_width); |
| 1519 | stack_.push_back(Value(static_cast<uint64_t>(vloc), |
| 1520 | ToTypedVector(vector_type, fixed ? len : 0), |
| 1521 | bit_width)); |
| 1522 | return vloc; |
| 1523 | } |
| 1524 | |
| 1525 | Value CreateVector(size_t start, size_t vec_len, size_t step, bool typed, |
| 1526 | bool fixed, const Value *keys = nullptr) { |