Updated Bag of Tricks (markdown)

Benoît Blanchon
2016-01-24 16:10:31 +01:00
parent cf6a713e7a
commit 2d7b6ae598

@@ -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).