Updated Bag of Tricks (markdown)

Benoît Blanchon
2016-11-25 12:23:17 +01:00
parent 055a53f15c
commit 34a19df6ae

@@ -247,6 +247,49 @@ root.printTo(chunkPrint);
See issue [#206](https://github.com/bblanchon/ArduinoJson/issues/206). See issue [#206](https://github.com/bblanchon/ArduinoJson/issues/206).
## Compute hash of JSON output
Here is how you can compute the CRC32 hash of the JSON output without consuming a lot of memory.
This can be very handy to compare two JSON trees.
```c++
#include <FastCRC.h> // https://github.com/FrankBoesing/FastCRC
class HashPrint : public Print {
public:
HashPrint()
{
_hash = _hasher.crc32(NULL, 0);
}
virtual size_t write(uint8_t c)
{
_hash = _hasher.crc32_upd(&c, 1);
}
uint32_t hash() const
{
return _hash;
}
private:
FastCRC32 _hasher;
uint32_t _hash;
};
```
To use this in your code:
```c++
HashPrint hashPrint;
root.printTo(hashPrint);
Serial.println(hashPrint.hash());
```
See issue [#390](https://github.com/bblanchon/ArduinoJson/issues/390).
## Throw exception when JsonBuffer is too small ## Throw exception when JsonBuffer is too small
Here is a static decorator that will behave as the decorated `JsonBuffer`, except that it will throw an exception if the allocation fails: Here is a static decorator that will behave as the decorated `JsonBuffer`, except that it will throw an exception if the allocation fails: