Remove mentions of the zero-copy mode

This commit is contained in:
Benoit Blanchon
2023-08-19 16:05:04 +02:00
parent 51c5f1a73a
commit 7bd2ea1072
7 changed files with 16 additions and 48 deletions

View File

@ -9,25 +9,18 @@
int main() {
// Allocate the JSON document
//
// Inside the parentheses, 200 is the RAM allocated to this document.
// Don't forget to change this value to match your requirement.
// Use https://arduinojson.org/v6/assistant to compute the capacity.
JsonDocument doc;
// Add values in the document
//
// Add values in the document.
doc["sensor"] = "gps";
doc["time"] = 1351824120;
// Add an array.
//
// Add an array
JsonArray data = doc["data"].to<JsonArray>();
data.add(48.756080);
data.add(2.302038);
// Generate the minified JSON and send it to STDOUT
//
serializeJson(doc, std::cout);
// The above line prints:
// {"sensor":"gps","time":1351824120,"data":[48.756080,2.302038]}
@ -36,7 +29,6 @@ int main() {
std::cout << std::endl;
// Generate the prettified JSON and send it to STDOUT
//
serializeJsonPretty(doc, std::cout);
// The above line prints:
// {

View File

@ -9,33 +9,22 @@
int main() {
// Allocate the JSON document
//
// Inside the parentheses, 200 is the capacity of the memory pool in bytes.
// Don't forget to change this value to match your JSON document.
// Use https://arduinojson.org/v6/assistant to compute the capacity.
JsonDocument doc;
// JSON input string.
//
// Using a char[], as shown here, enables the "zero-copy" mode. This mode uses
// the minimal amount of memory because the JsonDocument stores pointers to
// the input buffer.
// If you use another type of input, ArduinoJson must copy the strings from
// the input to the JsonDocument, so you need to increase the capacity of the
// JsonDocument.
char json[] =
// JSON input string
const char* json =
"{\"sensor\":\"gps\",\"time\":1351824120,\"data\":[48.756080,2.302038]}";
// Deserialize the JSON document
DeserializationError error = deserializeJson(doc, json);
// Test if parsing succeeds.
// Test if parsing succeeds
if (error) {
std::cerr << "deserializeJson() failed: " << error.c_str() << std::endl;
return 1;
}
// Fetch values.
// Fetch the values
//
// Most of the time, you can rely on the implicit casts.
// In other case, you can do doc["time"].as<long>();
@ -44,7 +33,7 @@ int main() {
double latitude = doc["data"][0];
double longitude = doc["data"][1];
// Print values.
// Print the values
std::cout << sensor << std::endl;
std::cout << time << std::endl;
std::cout << latitude << std::endl;

View File

@ -9,17 +9,9 @@
int main() {
// Allocate the JSON document
//
// Inside the parentheses, 300 is the size of the memory pool in bytes.
// Don't forget to change this value to match your JSON document.
// Use https://arduinojson.org/assistant to compute the capacity.
JsonDocument doc;
// MessagePack input string.
//
// It's better to use a char[] as shown here.
// If you use a const char* or a String, ArduinoJson will
// have to make a copy of the input in the JsonBuffer.
// The MessagePack input string
uint8_t input[] = {131, 166, 115, 101, 110, 115, 111, 114, 163, 103, 112, 115,
164, 116, 105, 109, 101, 206, 80, 147, 50, 248, 164, 100,
97, 116, 97, 146, 203, 64, 72, 96, 199, 58, 188, 148,
@ -31,20 +23,16 @@ int main() {
// "data": [48.75608, 2.302038]
// }
// doc of the object tree.
//
// It's a reference to the JsonObject, the actual bytes are inside the
// JsonBuffer with all the other nodes of the object tree.
// Memory is freed when jsonBuffer goes out of scope.
// Parse the input
DeserializationError error = deserializeMsgPack(doc, input);
// Test if parsing succeeds.
// Test if parsing succeeds
if (error) {
std::cerr << "deserializeMsgPack() failed: " << error.c_str() << std::endl;
return 1;
}
// Fetch values.
// Fetch the values
//
// Most of the time, you can rely on the implicit casts.
// In other case, you can do doc["time"].as<long>();
@ -53,7 +41,7 @@ int main() {
double latitude = doc["data"][0];
double longitude = doc["data"][1];
// Print values.
// Print the values
std::cout << sensor << std::endl;
std::cout << time << std::endl;
std::cout << latitude << std::endl;