MCPcopy Create free account
hub / github.com/TombEngine/TombEngine / CreateSharedString

Function CreateSharedString

Libs/flatbuffers/flatbuffers.h:1683–1701  ·  view source on GitHub ↗

@brief Store a string in the buffer, which can contain any binary data. If a string with this exact contents has already been serialized before, instead simply returns the offset of the existing string. This uses a map stored on the heap, but only stores the numerical offsets. @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 b

Source from the content-addressed store, hash-verified

1681 /// @param[in] len The number of bytes that should be stored from `str`.
1682 /// @return Returns the offset in the buffer where the string starts.
1683 Offset<String> CreateSharedString(const char *str, size_t len) {
1684 FLATBUFFERS_ASSERT(FLATBUFFERS_GENERAL_HEAP_ALLOC_OK);
1685 if (!string_pool)
1686 string_pool = new StringOffsetMap(StringOffsetCompare(buf_));
1687 auto size_before_string = buf_.size();
1688 // Must first serialize the string, since the set is all offsets into
1689 // buffer.
1690 auto off = CreateString(str, len);
1691 auto it = string_pool->find(off);
1692 // If it exists we reuse existing serialized data!
1693 if (it != string_pool->end()) {
1694 // We can remove the string we serialized.
1695 buf_.pop(buf_.size() - size_before_string);
1696 return *it;
1697 }
1698 // Record this string for future use.
1699 string_pool->insert(off);
1700 return off;
1701 }
1702
1703#ifdef FLATBUFFERS_HAS_STRING_VIEW
1704 /// @brief Store a string in the buffer, which can contain any binary data.

Callers

nothing calls this directly

Calls 10

lengthMethod · 0.80
StringOffsetCompareClass · 0.70
CreateStringFunction · 0.70
sizeMethod · 0.45
findMethod · 0.45
endMethod · 0.45
popMethod · 0.45
insertMethod · 0.45
dataMethod · 0.45
c_strMethod · 0.45

Tested by

no test coverage detected