File indexing completed on 2024-11-24 04:54:34

0001 /*
0002     SPDX-License-Identifier: MPL-2.0
0003 */
0004 
0005 /* Copyright (c) 2015 Brian R. Bondy. Distributed under the MPL2 license.
0006  * This Source Code Form is subject to the terms of the Mozilla Public
0007  * License, v. 2.0. If a copy of the MPL was not distributed with this
0008  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
0009 
0010 #ifndef CONTEXT_DOMAIN_H_
0011 #define CONTEXT_DOMAIN_H_
0012 #define UNUSED(x) ( (void)(x) )
0013 
0014 #include <string.h>
0015 #include "./base.h"
0016 
0017 // This class must operate off of borrowed memory
0018 // Serialization and deserialization is not supported intentionally.
0019 class ContextDomain {
0020  public:
0021   uint64_t GetHash() const;
0022 
0023   ~ContextDomain() {
0024   }
0025 
0026   ContextDomain(const char* start, int len) {
0027     start_ = start;
0028     len_ = len;
0029   }
0030 
0031   ContextDomain(const ContextDomain &rhs) {
0032     start_ = rhs.start_;
0033     len_ = rhs.len_;
0034   }
0035 
0036   ContextDomain() : start_(nullptr), len_(0) {
0037   }
0038 
0039   bool operator==(const ContextDomain&rhs) const {
0040     if (!start_ || !rhs.start_) {
0041       return false;
0042     }
0043     if (len_ != rhs.len_) {
0044       return false;
0045     }
0046     return !memcmp(start_, rhs.start_, len_);
0047   }
0048 
0049   bool operator!=(const ContextDomain &rhs) const {
0050     return !(*this == rhs);
0051   }
0052 
0053   void Update(const ContextDomain &other) {
0054     // unused function
0055     UNUSED(other);
0056   }
0057 
0058   uint32_t Serialize(char* buffer) {
0059     UNUSED(buffer);
0060     return 0;
0061   }
0062 
0063   uint32_t Deserialize(char* buffer, uint32_t buffer_size) {
0064     UNUSED(buffer);
0065     UNUSED(buffer_size);
0066     return 0;
0067   }
0068 
0069  private:
0070   const char* start_;
0071   int len_;
0072 };
0073 
0074 #endif  // CONTEXT_DOMAIN_H_