diff options
author | Alexander Gallego <gallego.alexx@gmail.com> | 2017-03-20 19:02:04 -0400 |
---|---|---|
committer | Wouter van Oortmerssen <aardappel@gmail.com> | 2017-03-20 16:02:04 -0700 |
commit | f2071e4f80bf7ccd924337c7bf1bf33c79e3fc3e (patch) | |
tree | c02e360d9671235d4051ed898d7d69ff1fecac21 /include | |
parent | 9c25ecdcd1e88dde8d7462d7844fe9da19f18a16 (diff) | |
download | flatbuffers-f2071e4f80bf7ccd924337c7bf1bf33c79e3fc3e.tar.gz flatbuffers-f2071e4f80bf7ccd924337c7bf1bf33c79e3fc3e.tar.bz2 flatbuffers-f2071e4f80bf7ccd924337c7bf1bf33c79e3fc3e.zip |
Add arbitrary string type to the native object API (#4218)
* Custom strings are very common for optimizations around small objects
or growth style optimizations, i.e.: grow at 1.57 times vs doubling vs..
A second common strategy is to cooperate w/ the memory allocator
see FBString[1] and seastar[2] string for examples.
[1] fbstring: https://github.com/facebook/folly/blob/master/folly/docs/FBString.md
[2] sstring: https://github.com/scylladb/seastar/blob/master/core/sstring.hh
Diffstat (limited to 'include')
-rw-r--r-- | include/flatbuffers/flatbuffers.h | 9 | ||||
-rw-r--r-- | include/flatbuffers/idl.h | 3 |
2 files changed, 11 insertions, 1 deletions
diff --git a/include/flatbuffers/flatbuffers.h b/include/flatbuffers/flatbuffers.h index ce657c04..ea78aeee 100644 --- a/include/flatbuffers/flatbuffers.h +++ b/include/flatbuffers/flatbuffers.h @@ -981,6 +981,15 @@ FLATBUFFERS_FINAL_CLASS } /// @brief Store a string in the buffer, which can contain any binary data. + /// @param[in] str A const reference to a std::string like type with support + /// of T::c_str() and T::length() to store in the buffer. + /// @return Returns the offset in the buffer where the string starts. + template<typename T> + Offset<String> CreateString(const T &str) { + return CreateString(str.c_str(), str.length()); + } + + /// @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. /// @param[in] str A const char pointer to the data to be stored as a string. diff --git a/include/flatbuffers/idl.h b/include/flatbuffers/idl.h index 5b7a72a3..d4d737d3 100644 --- a/include/flatbuffers/idl.h +++ b/include/flatbuffers/idl.h @@ -353,6 +353,7 @@ struct IDLOptions { bool escape_proto_identifiers; bool generate_object_based_api; std::string cpp_object_api_pointer_type; + std::string cpp_object_api_string_type; bool union_value_namespacing; bool allow_non_utf8; std::string include_prefix; @@ -479,6 +480,7 @@ class Parser : public ParserState { known_attributes_["idempotent"] = true; known_attributes_["cpp_type"] = true; known_attributes_["cpp_ptr_type"] = true; + known_attributes_["cpp_str_type"] = true; known_attributes_["native_inline"] = true; known_attributes_["native_type"] = true; known_attributes_["native_default"] = true; @@ -743,4 +745,3 @@ bool GenerateGoGRPC(const Parser &parser, } // namespace flatbuffers #endif // FLATBUFFERS_IDL_H_ - |