Jimp field report and feedback
https://youtu.be/rcBVqcoQkuA?si=TSamomJ3941G6LUO&t=1372
If you ever feel the need to call any of these private functions, please drop me an issue
I hope it also applies to this repo.
Use case
I have an embedded system with about 80K RAM where I can't fit the entire JSON paylaod or the parsed tree into RAM. Sounds like the perfect use for jimp, right?
I refactored jimp to work with streams so I can pipe the network request into jimp character by character and never put the entire response text or parsed tree into RAM. I only want a small amount of data from the request, so I store that and ignore the rest.
Private functions
Because of the above quote, I'll start with the private functions that I call:
I found it useful to call jimp__get_token directly. I only use a small amount of the data like I said, so I found it useful to get the next token, no matter what it is, and ignore it.
Other feedback and alterations I made
- The biggest change is converting jimp to a stream API. Maybe
jimp_begincould take a function that returns the next char, which could be from a stream or from a buffer. I know this isn't necessary for everybody, so I understand if this just stays in my fork. - I added functions
jimp_skip_arrayandjimp_skip_objectto skip an entire array/object. Basically just reading tokens until I see as many closing brackets as opening brackets. - More generally, it would be cool to have a way to take only one value from an object and skip everything else, even if it includes nested objects and arrays. (edit: added here https://github.com/youdbetterrun/youdbetterrun-firmware/commit/89469186b88874ffc8f92b0f3cb92a90a3dce941)
- It would be cool to have some user data inside of the parser. For example, I build up a struct inside of one of the leaf parsers and then pass it to a function to conditionally add it to a list. I directly pass it to the function instead of building a dynamic array to save memory. I need to pass some arguments to this function, which I have to pass through all parsers. If the jimp struct had a
void*, I wouldn't have to. Now that I write this, I could have just done that in my fork.. (edit: added here https://github.com/youdbetterrun/youdbetterrun-firmware/commit/3b2b8fd0ee2f63c968d70f22cf7a9df7792c18f0)
Conclusion
To be clear, I'm happily using my copy-pasta version of jimp. This is not a feature request. I just thought it could be interesting or an idea for content, especially because you asked. Here's my jimplementation: https://github.com/youdbetterrun/youdbetterrun-firmware/commit/b84b4302fb3b3942ee5a8498710c14c7645ae4e9 Sorry if this is a bit rambly.