Skip to content

Commit ef60e57

Browse files
committed
renamed project files
1 parent 3a3324a commit ef60e57

File tree

7 files changed

+166
-122
lines changed

7 files changed

+166
-122
lines changed

ReadMe.md

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,23 @@
1-
# esp32-yaml
1+
# ArduinoYaml
22

33
This library is based on [libyaml](https://github.com/yaml/libyaml).
44
It provides two ways to convert YAML strings to JSON (cJSON or ArduinoJson) objects.
55

6-
Fun fact: the yml parser from libyaml can also deserialize JSON.
6+
Supported platforms (some untested):
77

8-
Although there's obviously no use to have a JSON to JSON converter, it can offer a single endpoint for both types of inputs.
8+
- esp32
9+
- esp8266
10+
- samd
11+
- rp2040
912

10-
e.g. Provide either JSON or YML as input string, libyml understands both and will treat them as equal.
1113

1214
### Usage
1315

1416
#### cJSON
1517

1618
```cpp
17-
#include <cJSON.h> // built-in with esp32
18-
#include <esp32-yaml.hpp>
19+
#include <cJSON.h> // note: cJSON is built-in with esp32
20+
#include <ArduinoYaml.h>
1921

2022
// cJSON object to YAML string
2123
size_t serializeYml( cJSON* src_obj, String &dest_string );
@@ -36,7 +38,7 @@ e.g. Provide either JSON or YML as input string, libyml understands both and wil
3638
```cpp
3739
3840
#include <ArduinoJson.h>
39-
#include <esp32-yaml.hpp>
41+
#include <ArduinoYaml.h>
4042
4143
// ArduinoJSON object to YAML string
4244
size_t serializeYml( JsonVariant src_obj, String &dest_string );
@@ -48,6 +50,10 @@ e.g. Provide either JSON or YML as input string, libyml understands both and wil
4850
DeserializationError deserializeYml( JsonObject &dest_obj, const char* src_yaml_str );
4951
// Deserialize YAML stream to ArduinoJSON object
5052
DeserializationError deserializeYml( JsonObject &dest_obj, Stream &src_stream );
53+
// Deserialize YAML string to ArduinoJSON document
54+
DeserializationError deserializeYml( JsonDocument &dest_doc, Stream &src_stream );
55+
// Deserialize YAML string to ArduinoJSON document
56+
DeserializationError deserializeYml( JsonDocument &dest_doc, const char *src_yaml_str) ;
5157
5258
```
5359

examples/test/test.ino

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#include <ArduinoJson.h> // optional
22
//#include <cJSON.h> // implicit with esp32, otherwise optional
3-
#include <esp32-yaml.hpp>
3+
#include <ArduinoYaml.h>
44

55

66
// sorry about the notation, but it looks nicer than chunk-splitting+quoting
@@ -83,28 +83,29 @@ void setup()
8383
YAML_LOG_n("YAML=>JSON and JSON=>YAML using ArduinoJson\n\n");
8484

8585
{
86-
YAML_LOG_n( "[TEST #%d] YAML stream to JsonObject -> deserializeYml(json_obj, yaml_stream):", test_number++ );
87-
JsonObject json_obj;
86+
YAML_LOG_n( "[TEST #%d] YAML stream to JsonObject -> deserializeYml(json_doc, yaml_stream):", test_number++ );
87+
DynamicJsonDocument json_doc(yaml_str_size*2);
8888
String yaml_str = String( yaml_example_str );
8989
StringStream yaml_stream( yaml_str );
90-
auto err = deserializeYml( json_obj, yaml_stream ); // deserialize yaml stream to JsonObject
90+
auto err = deserializeYml( json_doc, yaml_stream ); // deserialize yaml stream to JsonDocument
9191
if( err ) {
9292
YAML_LOG_n("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
9393
return;
9494
}
95-
const size_t bytes_out = serializeJsonPretty( json_obj, Serial ); // print deserialized JsonObject
95+
const size_t bytes_out = serializeJsonPretty( json_doc, Serial ); // print deserialized JsonObject
9696
YAML_LOG_n("[YAML=>JsonObject] yaml bytes in=%d, json bytes out=%d\n\n", yaml_str_size, bytes_out);
9797
}
9898

9999

100100
{
101-
YAML_LOG_n( "[TEST #%d] YAML string to JsonObject -> deserializeYml(json_obj, yaml_example_str):", test_number++ );
102-
JsonObject json_obj;
103-
auto err = deserializeYml( json_obj, yaml_example_str ); // deserialize yaml string to JsonObject
101+
YAML_LOG_n( "[TEST #%d] YAML string to JsonObject -> deserializeYml(json_doc, yaml_example_str):", test_number++ );
102+
DynamicJsonDocument json_doc(yaml_str_size*2);
103+
auto err = deserializeYml( json_doc, yaml_example_str ); // deserialize yaml string to JsonDocument
104104
if( err ) {
105105
YAML_LOG_n("Unable to deserialize demo YAML to JsonObject: %s", err.c_str() );
106106
return;
107107
}
108+
JsonObject json_obj = json_doc.as<JsonObject>();
108109
const size_t bytes_out = serializeJsonPretty( json_obj, Serial ); // print deserialized JsonObject
109110
YAML_LOG_n("[YAML=>JsonObject] yaml bytes in=%d, json bytes out=%d\n\n", yaml_str_size, bytes_out);
110111
}
@@ -151,13 +152,15 @@ void setup()
151152
}
152153

153154

155+
#if defined USE_STREAM_TO_STREAM // stream to stream unavailable on esp8266 (not enough memory)
154156
{
155157
YAML_LOG_n( "[TEST #%d] JSON stream to JsonObject to YAML stream -> serializeYml(stream_in, Serial):", test_number++ );
156158
String str_json = String( json_example_str );
157159
StringStream stream_in( str_json );
158160
const size_t bytes_out = serializeYml( stream_in, Serial );
159161
YAML_LOG_n("[JSON=>JsonObject=>YAML] json bytes in=%d, yaml bytes out=%d\n", json_str_size, bytes_out);
160162
}
163+
#endif
161164

162165

163166
YAML_LOG_n("ArduinoJson tests complete");

0 commit comments

Comments
 (0)