Home | History | Annotate | Download | only in puffin
      1 // Copyright 2017 The Chromium OS Authors. All rights reserved.
      2 // Use of this source code is governed by a BSD-style license that can be
      3 // found in the LICENSE file.
      4 
      5 #ifndef SRC_INCLUDE_PUFFIN_COMMON_H_
      6 #define SRC_INCLUDE_PUFFIN_COMMON_H_
      7 
      8 #include <functional>
      9 #include <memory>
     10 #include <vector>
     11 
     12 #ifdef USE_BRILLO
     13 #include "base/macros.h"
     14 #include "brillo/brillo_export.h"
     15 #define PUFFIN_EXPORT BRILLO_EXPORT
     16 
     17 #else  // USE_BRILLO
     18 
     19 #ifndef DISALLOW_COPY_AND_ASSIGN
     20 #define DISALLOW_COPY_AND_ASSIGN(TypeName) \
     21   TypeName(const TypeName&) = delete;      \
     22   void operator=(const TypeName&) = delete
     23 #endif  // DISALLOW_COPY_AND_ASSIGN
     24 
     25 #ifndef PUFFIN_EXPORT
     26 #define PUFFIN_EXPORT __attribute__((__visibility__("default")))
     27 #endif  // PUFFIN_EXPORT
     28 
     29 #endif  // USE_BRILLO
     30 
     31 namespace puffin {
     32 
     33 using Buffer = std::vector<uint8_t>;
     34 using UniqueBufferPtr = std::unique_ptr<Buffer>;
     35 using SharedBufferPtr = std::shared_ptr<Buffer>;
     36 
     37 // This class is similar to the protobuf generated for |ProtoByteExtent|. We
     38 // defined an extra class so the users of puffin do not have to include
     39 // puffin.pb.h and deal with its use.
     40 struct PUFFIN_EXPORT ByteExtent {
     41   ByteExtent(uint64_t offset, uint64_t length)
     42       : offset(offset), length(length) {}
     43 
     44   bool operator==(const ByteExtent& other) const {
     45     return this->length == other.length && this->offset == other.offset;
     46   }
     47 
     48   uint64_t offset;
     49   uint64_t length;
     50 };
     51 
     52 struct PUFFIN_EXPORT BitExtent {
     53   BitExtent(uint64_t offset, uint64_t length)
     54       : offset(offset), length(length) {}
     55 
     56   bool operator==(const BitExtent& other) const {
     57     return this->length == other.length && this->offset == other.offset;
     58   }
     59 
     60   uint64_t offset;
     61   uint64_t length;
     62 };
     63 
     64 }  // namespace puffin
     65 
     66 #endif  // SRC_INCLUDE_PUFFIN_COMMON_H_
     67