mirror of
https://github.com/me-no-dev/ESPAsyncWebServer.git
synced 2025-08-03 20:54:39 +02:00
update doc
This commit is contained in:
24
README.md
24
README.md
@@ -36,7 +36,8 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
|
|||||||
Usage and API stays the same as the original library.
|
Usage and API stays the same as the original library.
|
||||||
Please look at the original libraries for more examples and documentation.
|
Please look at the original libraries for more examples and documentation.
|
||||||
|
|
||||||
[https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer)
|
- [https://github.com/me-no-dev/ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) (original library)
|
||||||
|
- [https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) (fork of the original library)
|
||||||
|
|
||||||
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
|
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
|
||||||
|
|
||||||
@@ -44,9 +45,8 @@ The fork from `yubox-node-org` introduces some breaking API changes compared to
|
|||||||
|
|
||||||
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
|
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
|
||||||
So you have the choice of which API to use.
|
So you have the choice of which API to use.
|
||||||
I strongly suggest to use the optimized API from `yubox-node-org` as it is much more efficient.
|
|
||||||
|
|
||||||
Here is an example for serializing a Json document in a websocket message buffer. This code is compatible with any forks, but not optimized:
|
Here are examples for serializing a Json document in a websocket message buffer:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
void send(JsonDocument& doc) {
|
void send(JsonDocument& doc) {
|
||||||
@@ -60,28 +60,16 @@ void send(JsonDocument& doc) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Here is an example for serializing a Json document in a more optimized way, and compatible with both forks:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
void send(JsonDocument& doc) {
|
void send(JsonDocument& doc) {
|
||||||
const size_t len = measureJson(doc);
|
const size_t len = measureJson(doc);
|
||||||
|
|
||||||
#if defined(ASYNCWEBSERVER_FORK_mathieucarbou)
|
// this fork (originally from yubox-node-org), uses another API with shared pointer
|
||||||
|
|
||||||
// this fork (originally from yubox-node-org), uses another API with shared pointer that better support concurrent use cases then the original project
|
|
||||||
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
|
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
|
||||||
assert(buffer); // up to you to keep or remove this
|
assert(buffer); // up to you to keep or remove this
|
||||||
serializeJson(doc, buffer->data(), len);
|
serializeJson(doc, buffer->data(), len);
|
||||||
_ws->textAll(std::move(buffer));
|
_ws->textAll(std::move(buffer));
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// original API from me-no-dev
|
|
||||||
AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len);
|
|
||||||
assert(buffer); // up to you to keep or remove this
|
|
||||||
serializeJson(doc, buffer->get(), len);
|
|
||||||
_ws->textAll(buffer);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
I recommend to use the official API `AsyncWebSocketMessageBuffer` to retain further compatibility.
|
||||||
|
@@ -36,7 +36,8 @@ This fork is based on [yubox-node-org/ESPAsyncWebServer](https://github.com/yubo
|
|||||||
Usage and API stays the same as the original library.
|
Usage and API stays the same as the original library.
|
||||||
Please look at the original libraries for more examples and documentation.
|
Please look at the original libraries for more examples and documentation.
|
||||||
|
|
||||||
[https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer)
|
- [https://github.com/me-no-dev/ESPAsyncWebServer](https://github.com/me-no-dev/ESPAsyncWebServer) (original library)
|
||||||
|
- [https://github.com/yubox-node-org/ESPAsyncWebServer](https://github.com/yubox-node-org/ESPAsyncWebServer) (fork of the original library)
|
||||||
|
|
||||||
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
|
## `AsyncWebSocketMessageBuffer` and `makeBuffer()`
|
||||||
|
|
||||||
@@ -44,9 +45,8 @@ The fork from `yubox-node-org` introduces some breaking API changes compared to
|
|||||||
|
|
||||||
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
|
This fork is compatible with the original library from `me-no-dev` regarding WebSocket, and wraps the optimizations done by `yubox-node-org` in the `AsyncWebSocketMessageBuffer` class.
|
||||||
So you have the choice of which API to use.
|
So you have the choice of which API to use.
|
||||||
I strongly suggest to use the optimized API from `yubox-node-org` as it is much more efficient.
|
|
||||||
|
|
||||||
Here is an example for serializing a Json document in a websocket message buffer. This code is compatible with any forks, but not optimized:
|
Here are examples for serializing a Json document in a websocket message buffer:
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
void send(JsonDocument& doc) {
|
void send(JsonDocument& doc) {
|
||||||
@@ -60,28 +60,16 @@ void send(JsonDocument& doc) {
|
|||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Here is an example for serializing a Json document in a more optimized way, and compatible with both forks:
|
|
||||||
|
|
||||||
```cpp
|
```cpp
|
||||||
void send(JsonDocument& doc) {
|
void send(JsonDocument& doc) {
|
||||||
const size_t len = measureJson(doc);
|
const size_t len = measureJson(doc);
|
||||||
|
|
||||||
#if defined(ASYNCWEBSERVER_FORK_mathieucarbou)
|
// this fork (originally from yubox-node-org), uses another API with shared pointer
|
||||||
|
|
||||||
// this fork (originally from yubox-node-org), uses another API with shared pointer that better support concurrent use cases then the original project
|
|
||||||
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
|
auto buffer = std::make_shared<std::vector<uint8_t>>(len);
|
||||||
assert(buffer); // up to you to keep or remove this
|
assert(buffer); // up to you to keep or remove this
|
||||||
serializeJson(doc, buffer->data(), len);
|
serializeJson(doc, buffer->data(), len);
|
||||||
_ws->textAll(std::move(buffer));
|
_ws->textAll(std::move(buffer));
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
// original API from me-no-dev
|
|
||||||
AsyncWebSocketMessageBuffer* buffer = _ws->makeBuffer(len);
|
|
||||||
assert(buffer); // up to you to keep or remove this
|
|
||||||
serializeJson(doc, buffer->get(), len);
|
|
||||||
_ws->textAll(buffer);
|
|
||||||
|
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
|
I recommend to use the official API `AsyncWebSocketMessageBuffer` to retain further compatibility.
|
||||||
|
Reference in New Issue
Block a user