Skip to content
This repository was archived by the owner on Feb 22, 2023. It is now read-only.

Conversation

Skylled
Copy link

@Skylled Skylled commented Mar 20, 2018

Redux of #343 with the new API courtesy of @mravn-google. Fixes flutter/flutter#13043 et al.

Currently testing on Android. Needs iOS testing.

cc @collinjackson @kroikie @mit-mit

api 'com.google.firebase:firebase-firestore:[11.4.0,12.0['
api 'com.google.firebase:firebase-core:[11.4.0,12.0['
api 'com.google.firebase:firebase-firestore:[11.6.0,12.0['
api 'com.google.firebase:firebase-core:[11.6.0,12.0['
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To any reviewers, please see the Firebase Release Notes for 11.6.

Key quote: "Added support for deserializing field types with wildcard generic parameters (e.g. kotlin.Map)."

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM


* Add GeoPoint class
* Allow for reading and writing DocumentReference, DateTime, and GeoPoint
values to and from Documents.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from and to, I guess

} else if (value instanceof GeoPoint) {
stream.write(GEO_POINT);
writeValue(stream, ((GeoPoint) value).getLatitude());
writeValue(stream, ((GeoPoint) value).getLongitude());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could use writeDouble here twice to avoid the redundant type discriminator byte you get with each call to writeValue. That would of course require changing the corresponding reader as well as the Dart and iOS sides too.

writeValue(stream, ((GeoPoint) value).getLongitude());
} else if (value instanceof DocumentReference) {
stream.write(DOCUMENT_REFERENCE);
writeValue(stream, ((DocumentReference) value).getPath());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Similarly, you could use writeBytes(stream, path.getBytes(UTF8)) here, unless the path can be null.

// Java is only precise to millisecond, Dart to microsecond.
// The mismatch between millisecond and microsecond precision will fail this test.
final DateTime testTime = new DateTime.fromMillisecondsSinceEpoch(
new DateTime.now().millisecondsSinceEpoch);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You might be able to simplify this using a suitable hard-coded value rather than DateTime.now().

@mravn-google mravn-google self-assigned this Mar 20, 2018
Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

case DOCUMENT_REFERENCE:
return FirebaseFirestore.getInstance().document((String) readValue(buffer));
final byte[] bytes = readBytes(buffer);
String path = new String(bytes, UTF8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nit] final String path = for consistency with the line above.

@@ -523,9 +525,12 @@ protected Object readValueOfType(byte type, ByteBuffer buffer) {
case DATE_TIME:
return new Date(buffer.getLong());
case GEO_POINT:
return new GeoPoint((Double) readValue(buffer), (Double) readValue(buffer));
readAlignment(buffer, 8);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch.

return Firestore.instance.document(readValue(buffer));
final int length = readSize(buffer);
final String path = utf8.decoder.convert(buffer.getUint8List(length));
return Firestore.instance.document(path);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looking at the changes you had to do to replace read/writeValue with directly typed alternatives, it becomes painfully clear to me that the standard codec APIs could be much more consistent across Dart, Java, and ObjC. flutter/flutter#15779

I don't think that should hold this PR back.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I already had the code that did not use read/writeValue from the original version of PR. I had switched to improve readability, but I hadn't considered the excess step of processing the type and the extra bytes in the buffer. This style with known types will be marginally faster.

@mravn-google
Copy link
Contributor

@Skylled You need to rebase your changes to tip of tree to avoid the ObjC compilation errors.

@mdanics
Copy link

mdanics commented Mar 21, 2018

Any update on when this will be working?

@googlebot
Copy link

We found a Contributor License Agreement for you (the sender of this pull request), but were unable to find agreements for the commit author(s). If you authored these, maybe you used a different email address in the git commits than was used to sign the CLA (login here to double check)? If these were authored by someone else, then they will need to sign a CLA as well, and confirm that they're okay with these being contributed to Google.
In order to pass this check, please resolve this problem and have the pull request author add another comment and the bot will run again. If the bot doesn't comment, it means it doesn't think anything has changed.

@Skylled
Copy link
Author

Skylled commented Mar 22, 2018

Not sure why my CLAs got messed with, but that should do it there.

@mravn-google
Copy link
Contributor

@Skylled Seems your rebase just pulled in a lot of commits made by other people. I guess that is why the CLA is no longer acceptable to the bot. You may have to undo that.

Can I ask you to do a git rebase upstream/master then git push -f origin or similar so that this PR involves only changes made by yourself?

@Skylled Skylled force-pushed the firestore_ext_codec branch from cfd81cf to 65dd8d3 Compare March 22, 2018 15:44
@googlebot
Copy link

CLAs look good, thanks!

@Skylled
Copy link
Author

Skylled commented Mar 22, 2018

Thanks for the advice. My git-fu is very weak.

Copy link
Contributor

@mravn-google mravn-google left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One small fix remaining, I think. Otherwise LGTM.

writeLong(stream, ((Date) value).getTime());
} else if (value instanceof GeoPoint) {
stream.write(GEO_POINT);
writeDouble(stream, ((GeoPoint) value).getLatitude());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

writeAlignment missing

@mravn-google mravn-google merged commit fbcf37f into flutter:master Mar 23, 2018
@Skylled Skylled deleted the firestore_ext_codec branch March 23, 2018 14:09
@Skylled
Copy link
Author

Skylled commented Mar 23, 2018

Thank you for the assistance @mravn-google. Java and ObjC are not my forte. I'm so glad to see this project done.

@mravn-google
Copy link
Contributor

@Skylled Me too :-) Thanks for your contribution and your patience.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants