@brief Store a string in the buffer, which can contain any binary data. @param[in] str A const char pointer to the data to be stored as a string. @param[in] len The number of bytes that should be stored from `str`. @return Returns the offset in the buffer where the string starts.
| 1618 | /// @param[in] len The number of bytes that should be stored from `str`. |
| 1619 | /// @return Returns the offset in the buffer where the string starts. |
| 1620 | Offset<String> CreateString(const char *str, size_t len) { |
| 1621 | NotNested(); |
| 1622 | PreAlign<uoffset_t>(len + 1); // Always 0-terminated. |
| 1623 | buf_.fill(1); |
| 1624 | PushBytes(reinterpret_cast<const uint8_t *>(str), len); |
| 1625 | PushElement(static_cast<uoffset_t>(len)); |
| 1626 | return Offset<String>(GetSize()); |
| 1627 | } |
| 1628 | |
| 1629 | /// @brief Store a string in the buffer, which is null-terminated. |
| 1630 | /// @param[in] str A const char pointer to a C-string to add to the buffer. |