Remove majority of JsonObject::get_raw()
usage.
#51137
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Summary
Infrastructure "Remove usage of get_raw() from read_from_json_string, generic_typed_reader, activity_actor"
Purpose of change
#50143 changes how json is loaded from a text based representation to a 'pre-parsed' binary based representation. A streaming interface made sense when the data could be physically streamed, but it is a foreign concept to the binary representation. Implementing a streaming interface on top of it proved challenging, and instead eliminating the need for a streaming API was the more successful path. To do that, we have to eliminate all usage of
JsonObject::get_raw
in the codebase, which drops us out of the object oriented parsing model back into the streaming model.read_from_json_string
,generic_typed_reader
, andactivity_actor
are all broad surfaces that either directly or indirectly depend onget_raw
. All three required touching large chunks of code to atomically refactor them, but between them represent most usage ofget_raw
in the code and the hardest ones to eliminate. Thus, they get a separate PR to deal with them.Since I have to extend the Json APIs to support this PR, I threw in a couple more minor changes to them that will be needed later.
Describe the solution
read_from_json_string
uses the raw JsonIn api just to throw an error at a particular offset. We extend the existing object oriented json APIs to accept an offset parameter to their throw_error api. Then we refactor the implementation to essentially type erase the input type so we can accept eitherJsonIn
orJsonValue
from the callsite, as required. Then just remove all theget_raw
calls feeding into it. There are still places that directly pass in JsonIn without usingget_raw
so we have to keep support for that.generic_typed_reader
supports a reader class hierarchy with some standard overloaded functions, one of which accepts JsonIn. It was easy to refactor the hierarchy to support usingJsonValue
instead and avoid the rootget_raw
call.activity_actor
uses a map of string to deserializer function, so all the functions had to have the same type. Fortunately all but one were trivial to convert to JsonValue, and the one oddball just needed to test a JsonValue's type before deserializing appropriately.Describe alternatives you've considered
I tried implementing JsonIn on top of a flexbuffer but after a long struggle it just wasn't working out. JsonIn is 'very stateless' whereas a flexbuffer iterator needs to keep just enough state around that transitioning to and from the object api to the streaming api was too difficult to get right. Plus philosophically it didn't make sense to me to keep JsonIn around.
Testing
Build and create/load games.
Additional context
Required for #50143.