15 #ifndef ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_JSON_JSONGENERATOR_H_ 16 #define ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_JSON_JSONGENERATOR_H_ 20 #include <type_traits> 22 #include <rapidjson/stringbuffer.h> 23 #include <rapidjson/writer.h> 138 template <
typename CollectionT,
typename ValueT =
typename CollectionT::value_type>
152 template <
typename CollectionT,
typename ValueT =
typename CollectionT::value_type>
177 typename CollectionArrayT,
178 typename CollectionValueT =
typename CollectionArrayT::value_type,
179 typename ValueT =
typename CollectionValueT::value_type>
205 rapidjson::StringBuffer m_buffer;
208 rapidjson::Writer<rapidjson::StringBuffer> m_writer;
211 template <
typename CollectionT,
typename ValueT>
213 auto keyLength =
static_cast<rapidjson::SizeType
>(key.length());
214 if (!checkWriter() || !m_writer.Key(key.c_str(), keyLength)) {
217 m_writer.StartArray();
218 for (
const auto& value : collection) {
219 static_assert(std::is_same<ValueT, std::string>::value,
"We only support string collection.");
220 m_writer.String(value);
226 template <
typename CollectionT,
typename ValueT>
228 auto keyLength =
static_cast<rapidjson::SizeType
>(key.length());
229 if (!checkWriter() || !m_writer.Key(key.c_str(), keyLength)) {
232 m_writer.StartArray();
233 for (
const auto& value : collection) {
234 static_assert(std::is_same<ValueT, std::string>::value,
"We only support string collection.");
235 m_writer.RawValue(value.c_str(), value.length(), rapidjson::kStringType);
241 template <
typename CollectionArrayT,
typename CollectionValueT,
typename ValueT>
243 auto keyLength =
static_cast<rapidjson::SizeType
>(key.length());
244 if (!checkWriter() || !m_writer.Key(key.c_str(), keyLength)) {
247 m_writer.StartArray();
248 for (
const auto& stringArray : collection) {
249 m_writer.StartArray();
250 for (
const auto& value : stringArray) {
251 static_assert(std::is_same<ValueT, std::string>::value,
"We only support string collection.");
252 m_writer.String(value);
265 #endif // ALEXA_CLIENT_SDK_AVSCOMMON_UTILS_INCLUDE_AVSCOMMON_UTILS_JSON_JSONGENERATOR_H_
std::string toString(bool finalize=true)
bool addStringArray(const std::string &key, const CollectionT &collection)
Definition: JSONGenerator.h:212
::std::string string
Definition: gtest-port.h:1097
bool addCollectionOfStringArray(const std::string &key, const CollectionArrayT &collection)
Definition: JSONGenerator.h:242
Definition: JSONGenerator.h:47
bool startArray(const std::string &key)
bool startObject(const std::string &key)
Whether or not curl logs should be emitted.
Definition: AVSConnectionManager.h:36
bool finishArrayElement()
bool addMember(const std::string &key, const char *value)
bool addRawJsonMember(const std::string &key, const std::string &json, bool validate=true)
bool addMembersArray(const std::string &key, const CollectionT &collection)
Definition: JSONGenerator.h:227
static const std::string key
The database key to be used by the protocol given the METADATA object.
Definition: SharedAVSSettingProtocolTest.cpp:58