-
Notifications
You must be signed in to change notification settings - Fork 9.7k
Extend StandardMessageCodec for Cloud Firestore #429
Conversation
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[' |
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.
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)."
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.
LGTM
|
||
* Add GeoPoint class | ||
* Allow for reading and writing DocumentReference, DateTime, and GeoPoint | ||
values to and from Documents. |
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.
from and to, I guess
} else if (value instanceof GeoPoint) { | ||
stream.write(GEO_POINT); | ||
writeValue(stream, ((GeoPoint) value).getLatitude()); | ||
writeValue(stream, ((GeoPoint) value).getLongitude()); |
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.
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()); |
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.
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); |
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.
You might be able to simplify this using a suitable hard-coded value rather than DateTime.now()
.
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.
LGTM
case DOCUMENT_REFERENCE: | ||
return FirebaseFirestore.getInstance().document((String) readValue(buffer)); | ||
final byte[] bytes = readBytes(buffer); | ||
String path = new String(bytes, UTF8); |
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.
[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); |
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.
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); |
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.
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.
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.
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.
@Skylled You need to rebase your changes to tip of tree to avoid the ObjC compilation errors. |
Any update on when this will be working? |
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. |
Not sure why my CLAs got messed with, but that should do it there. |
@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 |
I'm not a git wizard
Was I half-asleep when I wrote this?
cfd81cf
to
65dd8d3
Compare
CLAs look good, thanks! |
Thanks for the advice. My git-fu is very weak. |
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.
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()); |
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.
writeAlignment
missing
Thank you for the assistance @mravn-google. Java and ObjC are not my forte. I'm so glad to see this project done. |
@Skylled Me too :-) Thanks for your contribution and your patience. |
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