@@ -53,26 +53,6 @@ const char* kRawMaxValueFieldValue = "__max__";
5353pb_bytes_array_s* kMaxValueFieldValue =
5454 nanopb::MakeBytesArray (kRawMaxValueFieldValue );
5555
56- /* * The special map field value entry of a maximum proto value. */
57- google_firestore_v1_MapValue_FieldsEntry kMaxValueFieldEntry = {
58- .key = kMaxValueFieldKey ,
59- .value = {
60- .which_value_type = google_firestore_v1_Value_string_value_tag,
61- .string_value = const_cast <pb_bytes_array_t *>(kMaxValueFieldValue )}};
62-
63- /* * The special map value of a maximum proto value. */
64- _google_firestore_v1_MapValue kMaxValueMapValue = {
65- .fields_count = 1 , .fields = &kMaxValueFieldEntry };
66-
67- /* *
68- * A maximum value that is larger than any other Firestore values. Underlying it
69- * is a map value with a special map field that SDK user cannot possibly
70- * construct.
71- */
72- google_firestore_v1_Value kMaxValue = {
73- .which_value_type = google_firestore_v1_Value_map_value_tag,
74- .map_value = kMaxValueMapValue };
75-
7656} // namespace
7757
7858using nanopb::Message;
@@ -703,8 +683,32 @@ bool IsMinValue(const google_firestore_v1_Value& value) {
703683 return IsNullValue (value);
704684}
705685
686+ /* *
687+ * Creates and returns a maximum value that is larger than any other Firestore
688+ * values. Underlying it is a map value with a special map field that SDK user
689+ * cannot possibly construct.
690+ */
706691google_firestore_v1_Value MaxValue () {
707- return kMaxValue ;
692+ google_firestore_v1_Value value;
693+ value.which_value_type = google_firestore_v1_Value_string_value_tag;
694+ value.string_value = kMaxValueFieldValue ;
695+
696+ // Make `field_entry` static so that it has a memory address that outlives
697+ // this function's scope; otherwise, using its address in the `map_value`
698+ // variable below would be invalid by the time the caller accessed it.
699+ static google_firestore_v1_MapValue_FieldsEntry field_entry;
700+ field_entry.key = kMaxValueFieldKey ;
701+ field_entry.value = value;
702+
703+ google_firestore_v1_MapValue map_value;
704+ map_value.fields_count = 1 ;
705+ map_value.fields = &field_entry;
706+
707+ google_firestore_v1_Value max_value;
708+ max_value.which_value_type = google_firestore_v1_Value_map_value_tag;
709+ max_value.map_value = map_value;
710+
711+ return max_value;
708712}
709713
710714bool IsMaxValue (const google_firestore_v1_Value& value) {
0 commit comments