squix78 / json-streaming-parser

Arduino library for parsing potentially huge json streams on devices with scarce memory
MIT License
205 stars 88 forks source link

Allow changing buffer size #27

Open rabidaudio opened 5 years ago

rabidaudio commented 5 years ago

I have a pretty memory-tight application and the parser buffer size of 512 was way overkill for my use-case (the largest individual keys/values are around 20 chars). I'm apparently not the first to have this issue. #19

This PR allows you to override the buffer size, either through build flags or by defining the prop before the library is imported:

#define JSON_PARSER_BUFFER_MAX_LENGTH 128
#include <JsonStreamingParser.h>

I renamed the definition to reduce the chance of conflicts with definitions in other code.

ircmaxell commented 4 years ago

Note: you'll also need to modify increaseBufferPointer() in JsonStreamingParser.cpp, which also refers to BUFFER_MAX_LENGTH:

void JsonStreamingParser::increaseBufferPointer() {
  bufferPos = min(bufferPos + 1, BUFFER_MAX_LENGTH - 1);
}
rabidaudio commented 4 years ago

@ircmaxell thanks for the heads up, that function got changed: https://github.com/squix78/json-streaming-parser/pull/27/files#diff-5a1f311800a154b95827c7c76e82f0c1R205

mrcodetastic commented 1 year ago

Can you raise a pull request for

https://github.com/mrfaptastic/json-streaming-parser2

Because this library isn't maintained anymore it seems .