@@ -39,6 +39,7 @@ namespace local {
3939namespace {
4040
4141const char * kVersionGlobalTable = " version" ;
42+ const char * kGlobalsTable = " globals" ;
4243const char * kMutationsTable = " mutation" ;
4344const char * kDocumentMutationsTable = " document_mutation" ;
4445const char * kMutationQueuesTable = " mutation_queue" ;
@@ -159,6 +160,11 @@ enum ComponentLabel {
159160 */
160161 DataMigrationName = 25 ,
161162
163+ /* *
164+ * The name of a global.
165+ */
166+ GlobalName = 26 ,
167+
162168 /* *
163169 * A path segment describes just a single segment in a resource path. Path
164170 * segments that occur sequentially in a key represent successive segments in
@@ -245,6 +251,10 @@ class Reader {
245251 return ReadLabeledString (ComponentLabel::BundleId);
246252 }
247253
254+ std::string ReadGlobalName () {
255+ return ReadLabeledString (ComponentLabel::GlobalName);
256+ }
257+
248258 std::string ReadQueryName () {
249259 return ReadLabeledString (ComponentLabel::QueryName);
250260 }
@@ -718,6 +728,10 @@ class Writer {
718728 WriteLabeledString (ComponentLabel::TableName, table_name);
719729 }
720730
731+ void WriteGlobalName (absl::string_view global_name) {
732+ WriteLabeledString (ComponentLabel::GlobalName, global_name);
733+ }
734+
721735 void WriteBatchId (model::BatchId batch_id) {
722736 WriteLabeledInt32 (ComponentLabel::BatchId, batch_id);
723737 }
@@ -1206,6 +1220,28 @@ bool LevelDbRemoteDocumentReadTimeKey::Decode(absl::string_view key) {
12061220 return reader.ok ();
12071221}
12081222
1223+ std::string LevelDbGlobalKey::KeyPrefix () {
1224+ Writer writer;
1225+ writer.WriteTableName (kGlobalsTable );
1226+ return writer.result ();
1227+ }
1228+
1229+ std::string LevelDbGlobalKey::Key (absl::string_view global_name) {
1230+ Writer writer;
1231+ writer.WriteTableName (kGlobalsTable );
1232+ writer.WriteGlobalName (global_name);
1233+ writer.WriteTerminator ();
1234+ return writer.result ();
1235+ }
1236+
1237+ bool LevelDbGlobalKey::Decode (absl::string_view key) {
1238+ Reader reader{key};
1239+ reader.ReadTableNameMatching (kGlobalsTable );
1240+ global_name_ = reader.ReadGlobalName ();
1241+ reader.ReadTerminator ();
1242+ return reader.ok ();
1243+ }
1244+
12091245std::string LevelDbBundleKey::KeyPrefix () {
12101246 Writer writer;
12111247 writer.WriteTableName (kBundlesTable );
0 commit comments