-
Notifications
You must be signed in to change notification settings - Fork 1.6k
ValueUtil changes for FieldValue migration #7991
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
schmidt-sebastian
merged 3 commits into
mrschmidt/mutabledocuments
from
mrschmidt/valueutil
May 14, 2021
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,8 +19,10 @@ | |
|
||
#include <ostream> | ||
#include <string> | ||
#include <vector> | ||
|
||
#include "Firestore/Protos/nanopb/google/firestore/v1/document.nanopb.h" | ||
#include "absl/types/optional.h" | ||
|
||
namespace firebase { | ||
namespace firestore { | ||
|
@@ -31,6 +33,9 @@ enum class ComparisonResult; | |
|
||
namespace model { | ||
|
||
class DocumentKey; | ||
class DatabaseId; | ||
|
||
/** | ||
* The order of types in Firestore. This order is based on the backend's | ||
* ordering, but modified to support server timestamps. | ||
|
@@ -58,14 +63,70 @@ util::ComparisonResult Compare(const google_firestore_v1_Value& left, | |
bool Equals(const google_firestore_v1_Value& left, | ||
const google_firestore_v1_Value& right); | ||
|
||
bool Equals(const google_firestore_v1_ArrayValue& left, | ||
const google_firestore_v1_ArrayValue& right); | ||
|
||
/** | ||
* Generate the canonical ID for the provided field value (as used in Target | ||
* Generates the canonical ID for the provided field value (as used in Target | ||
* serialization). | ||
*/ | ||
std::string CanonicalId(const google_firestore_v1_Value& value); | ||
|
||
/** | ||
* Generates the canonical ID for the provided array value (as used in Target | ||
* serialization). | ||
*/ | ||
std::string CanonicalId(const google_firestore_v1_ArrayValue& value); | ||
|
||
/** Returns true if the array value contains the specified element. */ | ||
bool Contains(google_firestore_v1_ArrayValue haystack, | ||
google_firestore_v1_Value needle); | ||
|
||
/** Returns a null Protobuf value. */ | ||
google_firestore_v1_Value NullValue(); | ||
|
||
/** Returns `true` if `value` is null in its Protobuf representation. */ | ||
bool IsNullValue(const google_firestore_v1_Value& value); | ||
|
||
/** Returns `NaN` in its Protobuf representation. */ | ||
google_firestore_v1_Value NaNValue(); | ||
|
||
/** Returns `true` if `value` is `NaN` in its Protobuf representation. */ | ||
bool IsNaNValue(const google_firestore_v1_Value& value); | ||
|
||
/** Returns a Protobuf reference value representing the given location. */ | ||
google_firestore_v1_Value RefValue(const DatabaseId& database_id, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please add comment. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
const DocumentKey& document_key); | ||
|
||
/** Creates a copy of the contents of the Value proto. */ | ||
google_firestore_v1_Value DeepClone(google_firestore_v1_Value source); | ||
google_firestore_v1_Value DeepClone(const google_firestore_v1_Value& source); | ||
|
||
/** Creates a copy of the contents of the ArrayValue proto. */ | ||
google_firestore_v1_ArrayValue DeepClone( | ||
const google_firestore_v1_ArrayValue& source); | ||
|
||
/** Returns true if `value` is a INTEGER_VALUE. */ | ||
inline bool IsInteger(const absl::optional<google_firestore_v1_Value>& value) { | ||
return value && | ||
value->which_value_type == google_firestore_v1_Value_integer_value_tag; | ||
} | ||
|
||
/** Returns true if `value` is a DOUBLE_VALUE. */ | ||
inline bool IsDouble(const absl::optional<google_firestore_v1_Value>& value) { | ||
return value && | ||
value->which_value_type == google_firestore_v1_Value_double_value_tag; | ||
} | ||
|
||
/** Returns true if `value` is either a INTEGER_VALUE or a DOUBLE_VALUE. */ | ||
inline bool IsNumber(const absl::optional<google_firestore_v1_Value>& value) { | ||
return IsInteger(value) || IsDouble(value); | ||
} | ||
|
||
/** Returns true if `value` is an ARRAY_VALUE. */ | ||
inline bool IsArray(const absl::optional<google_firestore_v1_Value>& value) { | ||
return value && | ||
value->which_value_type == google_firestore_v1_Value_array_value_tag; | ||
} | ||
|
||
} // namespace model | ||
|
||
|
@@ -79,6 +140,16 @@ inline bool operator!=(const google_firestore_v1_Value& lhs, | |
return !model::Equals(lhs, rhs); | ||
} | ||
|
||
inline bool operator==(const google_firestore_v1_ArrayValue& lhs, | ||
const google_firestore_v1_ArrayValue& rhs) { | ||
return model::Equals(lhs, rhs); | ||
} | ||
|
||
inline bool operator!=(const google_firestore_v1_ArrayValue& lhs, | ||
const google_firestore_v1_ArrayValue& rhs) { | ||
return !model::Equals(lhs, rhs); | ||
} | ||
|
||
inline std::ostream& operator<<(std::ostream& out, | ||
const google_firestore_v1_Value& value) { | ||
return out << model::CanonicalId(value); | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Question: this seems to be a behavior change from below? Can you explain why? Not that I am against..
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.
This is not meant to be a behavior change but rather a bug fix. When we create an empty bytes array directly with NanoPB, it uses
nullptr
and does not actually allocate memory. When we receive documents from the backend, these empty byte arrays are represented using a zero-length array, but one with an actual address in memory. We need these two representations to yield the same comparison behavior so our users don't see any behavior change.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.
Sounds good, thanks.