Skip to content
This repository was archived by the owner on Jan 21, 2025. It is now read-only.

Commit 8a4b01b

Browse files
committed
Doc update
1 parent 50b0e36 commit 8a4b01b

File tree

2 files changed

+74
-2
lines changed

2 files changed

+74
-2
lines changed

README.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,41 @@ This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and in
1616
- CI
1717
- Only supports ESP32
1818

19-
Usage and API stays the same as the original library.
19+
## Documentation
20+
21+
Usage and API stays the same as the original library.
2022
Please look at the original libraries for more examples and documentation.
23+
24+
[https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer)
25+
26+
## Pitfalls
27+
28+
The fork from yubox introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
29+
Thanks to this fork, you can handle them by using `ASYNCWEBSERVER_FORK_mathieucarbou`.
30+
31+
Here is an example for serializing a Json document in a websocket message buffer directly.
32+
This code is compatible with both forks.
33+
34+
```cpp
35+
void send(JsonDocument& doc) {
36+
const size_t len = measureJson(doc);
37+
38+
#if defined(ASYNCWEBSERVER_FORK_mathieucarbou)
39+
40+
// this fork (originally from yubox-node-org), uses another API with shared pointer that better support concurrent use cases then the original project
41+
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
42+
assert(buffer); // up to you to keep or remove this
43+
serializeJson(doc, buffer->data(), len);
44+
_ws->textAll(std::move(buffer));
45+
46+
#else
47+
48+
// original API from me-no-dev
49+
AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len);
50+
assert(buffer); // up to you to keep or remove this
51+
serializeJson(doc, buffer->get(), len);
52+
_ws->textAll(buffer);
53+
54+
#endif
55+
}
56+
```

docs/index.md

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,41 @@ This fork is based on https://github.com/yubox-node-org/ESPAsyncWebServer and in
1616
- CI
1717
- Only supports ESP32
1818

19-
Usage and API stays the same as the original library.
19+
## Documentation
20+
21+
Usage and API stays the same as the original library.
2022
Please look at the original libraries for more examples and documentation.
23+
24+
[https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer)
25+
26+
## Pitfalls
27+
28+
The fork from yubox introduces some breaking API changes compared to the original library, especially regarding the use of `std::shared_ptr<std::vector<uint8_t>>` for WebSocket.
29+
Thanks to this fork, you can handle them by using `ASYNCWEBSERVER_FORK_mathieucarbou`.
30+
31+
Here is an example for serializing a Json document in a websocket message buffer directly.
32+
This code is compatible with both forks.
33+
34+
```cpp
35+
void send(JsonDocument& doc) {
36+
const size_t len = measureJson(doc);
37+
38+
#if defined(ASYNCWEBSERVER_FORK_mathieucarbou)
39+
40+
// this fork (originally from yubox-node-org), uses another API with shared pointer that better support concurrent use cases then the original project
41+
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
42+
assert(buffer); // up to you to keep or remove this
43+
serializeJson(doc, buffer->data(), len);
44+
_ws->textAll(std::move(buffer));
45+
46+
#else
47+
48+
// original API from me-no-dev
49+
AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len);
50+
assert(buffer); // up to you to keep or remove this
51+
serializeJson(doc, buffer->get(), len);
52+
_ws->textAll(buffer);
53+
54+
#endif
55+
}
56+
```

0 commit comments

Comments
 (0)