Skip to content

Changes in the iOS API for FieldValue migration #8034

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

Merged

Conversation

schmidt-sebastian
Copy link
Contributor

This changes the code in the iOS API to directly read from and write to Protobuf.

@google-oss-bot
Copy link

1 Warning
⚠️ Did you forget to add a changelog entry? (Add #no-changelog to the PR description to silence this warning.)

Generated by 🚫 Danger


google_firestore_v1_ArrayValue components;
components.values_count = CheckedSize(order_bys.size());
components.values = MakeArray<google_firestore_v1_Value>(components.values_count);
Copy link
Contributor

Choose a reason for hiding this comment

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

Not related to this PR: what do you think about having a helper like

std::tie(components.values, components.values_count) = 
    MakeArray<google_firestore_v1_Value>(order_bys.size());

? Or I guess another alternative would be to create a bunch of helpers similar to FieldsArray that holds information on each array (it might be a lot of boilerplate, though). Usage could look something like this:

NanopbArray<ArrayValue>(components) = MakeArray<google_firestore_v1_Value>(order_bys.size());

or

MakeArray<ArrayValue, google_firestore_v1_Value>(components, order_bys.size());

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will consider this if there are more callsites where I can't use SetRepeatedField. I think this should be limited to the iOS Objective-C code, since it uses datastructures that are not compatible with the current method.

ThrowInvalidArgument("Invalid query. Expected a string for the document ID.");
}
const std::string &documentID = fieldValue.string_value();
std::string documentID = MakeString(fieldValue.string_value);
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional: can this be a string_view? (there is a ResourcePath::FromStringView function)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I recall correctly, you said that I am not able to use string_view APIs from iOS code. Is that correct?

Copy link
Contributor

Choose a reason for hiding this comment

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

You cannot use Abseil in the calls between our code from firebase-cpp-sdk (aka public C++) and firebase-ios-sdk (aka core C++) because they are compiled separately. In this case, all the code would be within the iOS SDK and compiled together, so it's not an issue. However, making it possible for the public iOS types to access those APIs while hiding them from public C++ sounds like more trouble than it's worth.

@@ -605,13 +626,14 @@ - (Bound)boundFromFieldValues:(NSArray<id> *)fieldValues isBefore:(BOOL)isBefore
path.CanonicalString());
}
DocumentKey key{path};
fieldValue = FieldValue::FromReference(self.firestore.databaseID, key);
FreeNanopbMessage(google_firestore_v1_Value_fields, &fieldValue);
fieldValue = RefValue(self.firestore.databaseID, key);
Copy link
Contributor

Choose a reason for hiding this comment

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

Question: can you use Message to avoid manually freeing? (Note that it has a release method)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done

@schmidt-sebastian schmidt-sebastian merged commit cd1fd22 into mrschmidt/mutabledocuments May 5, 2021
@schmidt-sebastian schmidt-sebastian deleted the mrschmidt/iosapichanges branch May 5, 2021 15:22
components.values[idx] = RefValue(self.firestore.databaseID, key);
} else {
fieldValue.release();
components.values[idx] = *fieldValue;
Copy link
Contributor

Choose a reason for hiding this comment

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

Optional nit: release returns a pointer, so this could be

components.values[idx] = *fieldValue.release();

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will fix this in the main PR.

@firebase firebase locked and limited conversation to collaborators Jun 5, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants