mirror of
https://github.com/bblanchon/ArduinoJson.git
synced 2025-08-13 17:44:49 +02:00
Updated Bag of Tricks (markdown)
@@ -41,3 +41,37 @@ root.printTo(BufferedPrint<256>(Serial));
|
||||
|
||||
See issue [#166](https://github.com/bblanchon/ArduinoJson/issues/166).
|
||||
|
||||
## Chunked output
|
||||
|
||||
Here is a proxy that allow to get only part of the output:
|
||||
|
||||
```c++
|
||||
class ChunkPrint : public Print {
|
||||
public:
|
||||
ChunkPrint(Print& destination, size_t from, size_t to)
|
||||
: _destination(destination), _to_skip(from), _to_write(to - from) {}
|
||||
|
||||
virtual size_t write(uint8_t c) {
|
||||
if (_to_skip > 0) {
|
||||
_to_skip--;
|
||||
} else if (_to_write > 0) {
|
||||
_to_write--;
|
||||
return _destination.write(c);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
private:
|
||||
Print& _destination;
|
||||
size_t _to_skip;
|
||||
size_t _to_write;
|
||||
};
|
||||
```
|
||||
|
||||
To use this in your code:
|
||||
|
||||
```c++
|
||||
root.printTo(ChunkPrint(Serial,10,20)); // print only range [10,20[
|
||||
```
|
||||
|
||||
See issue [#206](https://github.com/bblanchon/ArduinoJson/issues/206).
|
Reference in New Issue
Block a user