-
Notifications
You must be signed in to change notification settings - Fork 3.5k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changing the Handler interface to differentiate between key and string #132
Comments
But if you implement the new bool Key(const char* key, SizeType length, bool copy) { return String(key, length, copy); } (maybe possible via an |
An easy patch for existing consumers would be to provide a |
Haha, snap :) |
This has been asked in stackoverflow as well. I think the proposal is acceptable. |
It's a good practice to inherit from template<typename Encoding = rapidjson::UTF8<> >
struct NothingHandler
: rapidjson::BaseReaderHandler<Encoding, NothingHandler<Encoding> >
{
bool Default() { return false; } // reject everything
}; So one option would be to add the bool Key(const Ch* str, SizeType length, bool copy) {
return static_cast<Override&>(*this).String(str, length, copy);
} |
Introduce the new method `Key()` into the `Handler` concept. This method is used to process the keys of an object instead of the ambiguous and overloaded `String()` method.
For more details see: Tencent#132 This commit tries to minimize the required code changes and forwards the `Handler::Key()` calls to `Handler::String()` wherever possible in order to not break existing code; or at least not code deriving from `BaseReaderHandler` when implementing a custom `Handler`.
Fixed and merged to master in 5e03cbf |
Inherit from BaseReaderHandler<> to properly handle calls to the new `Key` function after updating RapidJSON to a current version (see Tencent/rapidjson#132, Tencent/rapidjson#134).
Would it be possible to introduce a slight interface breaking change to the
Handler
interface?Consider this example from the SAX documentation:
which creates the following calling sequence for a
Handler
:My problem with this is that the
String()
method is overloaded and used for two different purposes:string
property, andkey
for akay-value
-pair inside of the currently activeobject
.Writing your own
Handler
needs to keep track of the alternating calling sequence ofString()
andX
whereX
can beBool()
,UInt()
, ...BeginObject()
,BeginArray()
, and alsoString()
and this even for nested objects!This could be improved and solved by using another additional method for specifying the
key
of akey-value
-pair within an activeobject
, .e.g:The calling sequence from above would change to this:
This would allow to write much simpler
Handler
implementations.But I recognize that this would be a rather breaking API change...
The text was updated successfully, but these errors were encountered: