Skip to content

Jimp field report and feedback #27

Description

@MarcelRobitaille

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_begin could 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_array and jimp_skip_object to 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 youdbetterrun/youdbetterrun-firmware@8946918)
  • 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 youdbetterrun/youdbetterrun-firmware@3b2b8fd)

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: youdbetterrun/youdbetterrun-firmware@b84b430
Sorry if this is a bit rambly.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions