1 // Copyright (C) 2019 Google LLC 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, software 10 // distributed under the License is distributed on an "AS IS" BASIS, 11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 // See the License for the specific language governing permissions and 13 // limitations under the License. 14 15 #ifndef ICING_STORE_DOCUMENT_FILTER_DATA_H_ 16 #define ICING_STORE_DOCUMENT_FILTER_DATA_H_ 17 18 #include <cstdint> 19 #include <type_traits> 20 21 #include "icing/legacy/core/icing-packed-pod.h" 22 #include "icing/store/namespace-id.h" 23 24 namespace icing { 25 namespace lib { 26 27 using SchemaTypeId = int16_t; 28 inline constexpr SchemaTypeId kInvalidSchemaTypeId = -1; 29 30 class DocumentFilterData { 31 public: DocumentFilterData(NamespaceId namespace_id,SchemaTypeId schema_type_id,int64_t expiration_timestamp_ms)32 explicit DocumentFilterData(NamespaceId namespace_id, 33 SchemaTypeId schema_type_id, 34 int64_t expiration_timestamp_ms) 35 : expiration_timestamp_ms_(expiration_timestamp_ms), 36 namespace_id_(namespace_id), 37 schema_type_id_(schema_type_id) {} 38 39 bool operator==(const DocumentFilterData& other) const { 40 return namespace_id_ == other.namespace_id() && 41 schema_type_id_ == other.schema_type_id() && 42 expiration_timestamp_ms_ == other.expiration_timestamp_ms(); 43 } 44 namespace_id()45 NamespaceId namespace_id() const { return namespace_id_; } 46 schema_type_id()47 SchemaTypeId schema_type_id() const { return schema_type_id_; } set_schema_type_id(SchemaTypeId schema_type_id)48 void set_schema_type_id(SchemaTypeId schema_type_id) { 49 schema_type_id_ = schema_type_id; 50 } 51 expiration_timestamp_ms()52 int64_t expiration_timestamp_ms() const { return expiration_timestamp_ms_; } 53 54 private: 55 int64_t expiration_timestamp_ms_; 56 NamespaceId namespace_id_; 57 SchemaTypeId schema_type_id_; 58 } __attribute__((packed)); 59 60 static_assert(sizeof(DocumentFilterData) == 12, ""); 61 static_assert(icing_is_packed_pod<DocumentFilterData>::value, "go/icing-ubsan"); 62 63 } // namespace lib 64 } // namespace icing 65 66 #endif // ICING_STORE_DOCUMENT_FILTER_DATA_H_ 67