Closed alexshafranov closed 8 years ago
Thanks for this! I'm going to show this PR to some of the other users of the lib and make sure they are ok with it (I assume they will be of course). Give me a few days or so for them to comment :smile:
Awesome work!
Sure! Thanks for looking at the code
So I've had some feedback that for some of the users that this will effect their memory budgets too highly.
But, I've actually had an idea of how to implement what you want, while retaining that the 'default' approach doesn't contain this data. TL;DR I'm working on an alternative now watch this space! :smile:
Right, good to know you have an alternative plan in mind :)
Out of curiosity, are you maybe going to store json_value_s
contiguous in the allocated buffer, so that offsets can be accessed by an index?
That would be a much bigger change than I had in mind.
My current thought was just to have another struct json_value_ex_s - that contained the offset + line_no + row_no. Then have a parsing option for json_parse_ex that replaces all json_value_s' with json_value_ex_s' instead, and that way you would just need to cast the json_value_s -> json_value_ex_s to get the location information of any value.
Would that be sufficient for your use-case?
Cool, that will work for my use case, except that I also added offset information to object keys in json_object_element_s. Not sure how to handle that at the moment
Hmm. I'm guessing it is really useful to you to know where the key exactly is because that allows you to error when the key doesn't match your schema in some way?
Yes, that's how I wanted to use it.
But now I'm actually thinking that key offset is probably the only thing I need. Like if the value isn't of the expected format, then the corresponding key location is reported
So what if we just remove an offset field from json_value_s
and keep the one in json_object_element_s
? Would that be suitable for memory concerned users?
They basically don't want any extra memory for their normal use cases, that's why I've done #40 where you just cast the value -> value_ex, and the object name string -> string_ex to get what you need! :smile:
Awesome, *_ex
approach should work for me!
As discussed in #38 I'm adding line information to DOM objects.
json_value_s
stores a byte offset of the valuejson_object_element_s
stores a byte offset of the element namejson_parse_result_s
std::lower_bound