-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add JsonVariant::printTo(char[N])
#2136
Comments
This also fails to compile: inline void
jsUiManager::executeUiUpdates(const ArduinoJson::JsonDocument &doc) {
auto& self = instance();
typedef char CharBuff[1024];
CharBuff value = {0};
for (ArduinoJson::JsonPairConst kv :
doc.as<ArduinoJson::JsonObjectConst>()) {
int id = atoi(kv.key().c_str());
value = kv.value().as<CharBuff>();
// double loop to avoid copying the string
for (auto it = self.mComponents.begin(); it != self.mComponents.end();) {
if (auto component = it->lock()) {
++it;
if (component->id() == id) {
component->update(value);
}
} else {
it = self.mComponents.erase(it);
}
}
}
} You should at least make as<const char*> static_assert so we don't get a nullptr exception during runtime. |
Hi @zackees,
char buffer[1024];
serializeJson(kv.value(), buffer); I cannot exclude Please read the documentation. Best regards, |
It would be nice to have a comment in the source code. I dont' see why serializing to a static sized char buffer is an issue. |
I don't think something like |
Well then why not just inline a printTo function right into the JsonVariant? This would be obvious. Right now the solution is "read the documentation" which is claimed to be 700 pages long. This isn't even a corner case. Reading values out of a document in a tight loop is like the most mainstream use case imaginable. This seems like a one liner. Do I need to fork and submit a PR to move this forward? Users around the world would rejoice. |
Adding What's wrong with calling |
Just do ''' You don't have to support all overloads. Just give us the common path. |
JsonVariant::printTo(char[N])
This is with arduino json 7.2
I would like to NOT have to create a bunch of memory strings in a tight loop. I'd like to just have
JsonPairConst::value().printTo(charBuff)
;The text was updated successfully, but these errors were encountered: