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
Firebase.readEvent() returns "type" instead "put" while getting data from Firebase #374
Conversation
Thanks for your pull request. It looks like this may be your first contribution to a Google open source project (if not, look below for help). Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA). 📝 Please visit https://cla.developers.google.com/ to sign. Once you've signed (or fixed any issues), please reply here (e.g. What to do if you already signed the CLAIndividual signers
Corporate signers
|
I signed it! |
CLAs look good, thanks! |
@proppy Any chance you could review / merge this PR ? |
@kptdobe sorry for the late reply, it seems that this change break the continuous integration (see the red cross near the travis logo). Maybe using https://arduinojson.org/v5/api/jsonobject/set/ with the arduino |
I tried multiple versions of the code but no way to make the test pass.
I really do not get why it runs fine with my local Arduino env and it does not in Travis. There is one thing different I cannot identify. I also tried to update the Travis tests to ArduinoJson v5.13.2 (latest v5 - current runs v5.11.2) but not better. |
Problem with Travis is that test environment uses different String definition and uses std::string underneath: |
@kotl Thanks, this helped me to fix the tests! Nasty issue. It seems that This repairs the Streaming and is test compliant! ;) |
|
|
src/FirebaseArduino.cpp
Outdated
// the only supported format for JsonObject#set (it does not like the std::string of the test env) | ||
char *cstr = new char[type.length() + 1]; | ||
strcpy(cstr, type.c_str()); | ||
obj.getJsonVariant().as<JsonObject&>().set("type", cstr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
- needs: delete [] cstr;
- change strcpy to strncpy
thank you very much for doing this. |
// the only supported format for JsonObject#set (it does not like the std::string of the test env) | ||
char *cstr = new char[type.length() + 1]; | ||
strncpy(cstr, type.c_str(), type.length() + 1); | ||
obj.getJsonVariant().as<JsonObject&>().set("type", cstr); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
wouldn't that leak?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ah missed the delete, I was thinking it might not be safe to delete if JsonVariant keep a ref on it.
But set() documentation seems to imply that it make a copy if you pass a char* https://arduinojson.org/v5/api/jsonobject/set/.
PR for #364
Silly memory issue.
Running:
will always assign
xyz
totype
even though the type in theJsonVariant
is correct at the end of thereadEvent
method!I am not a cpp expert but certainly something related with using pointers and memory allocation.
I do not know if this is the correct fix but at least it fixes the streaming issues...