Open RandyGaul opened 5 years ago
Cool thx. I think this topic is a interesting addition! I also have small msgpack and json/json5 parsers/writers lying around! :D
Oh great. I've been interested in JSON parsers lately. The more the better. It's nice to see a wide variety of styles to get ideas from. In my own game I'm using something really similar to JSON and spent a lot of energy to make sure that code is easy to re-learn later when I need to modify it... Most parsers I've seen were not written with code maturation in mind.
I've extracted tinyjson5 from AVA engine. It is a JSON5/SJSON/JSON parser and JSON writer, which happens to be small and fast enough (parses 55 MiB JSON file at 230 ms in my computer). Hope it helps or serves as a good base :D Feedback welcome!
cl tinyjson5.c -DJSON5_C -DJSON5_BENCH /O2 /Oy /MT /DNDEBUG
cl tinyjson5.c -DJSON5_C -DJSON5_DEMO /O2 /Oy /MT /DNDEBUG
PS: Dunno if tinydixy or tinyini+ could also satisfy your needs. Is it for config files maybe?
That JSON parser does look pretty well written. Thanks! I'll be coming back in the future and probably referencing it :P
I took a look at ini, but actually have no idea how to use it. Can it save ini files? Can it add sections? Or is it only for loading ini files?
Personally I would look for something like ini_parse(buffer, sz)
, and then ini_get(key, &char_ptr)
and that sort of thing. Otherwise it looks complicated to figure out how to use.
tinyini only load files and provide a list of pairs {key:value}. The point is that it parses a superset of ini which includes a few more options to work with.
in the tinyini demo, rather than printf'ing pairs, you could add them to a map<string,string>
for further lookups and that would be enough for an end-user, I guess.
Here's one you might like! It's endian agnostic since it reads or writes one byte at the time. The underlying CPU architecture handles endianness within the bitshift operators. No need for byteswap stuff. I use these functions all the time. Very copy + pasteable.