CatapultServer  v0.5.0.1 (Elephant)
CacheEntryInfo.h
Go to the documentation of this file.
1 
21 #pragma once
23 
24 namespace catapult { namespace model {
25 
26 #pragma pack(push, 1)
27 
29  template<typename TIdentifier>
30  struct CacheEntryInfo : public TrailingVariableDataLayout<CacheEntryInfo<TIdentifier>, uint8_t> {
31  private:
35 
36  public:
38  static constexpr uint32_t Max_Data_Size = 0x00FFFFFF;
39 
40  public:
42  TIdentifier Id;
43 
45  uint32_t DataSize;
46 
47  // followed by data if DataSize > 0
48 
49  public:
51  const uint8_t* DataPtr() const {
52  return DataSize ? ToTypedPointer(PayloadStart(*this)) : nullptr;
53  }
54 
56  uint8_t* DataPtr() {
57  return DataSize ? ToTypedPointer(PayloadStart(*this)) : nullptr;
58  }
59 
60  public:
62  bool HasData() const {
63  return DataSize > 0;
64  }
65 
67  bool IsTooLarge() const {
68  return DataSize >= Max_Data_Size;
69  }
70 
71  public:
73  static constexpr uint64_t CalculateRealSize(const CacheEntryInfo& cacheEntryInfo) noexcept {
74  return sizeof(CacheEntryInfo<TIdentifier>) + cacheEntryInfo.DataSize;
75  }
76  };
77 
78 #pragma pack(pop)
79 }}
catapult::model::TrailingVariableDataLayout< CacheEntryInfo< TIdentifier >, uint8_t >::PayloadStart
static auto PayloadStart(T &derived)
Gets the start of the variable data part of derived.
Definition: TrailingVariableDataLayout.h:39
catapult::model::CacheEntryInfo::DataSize
uint32_t DataSize
Size of the entry data.
Definition: CacheEntryInfo.h:45
catapult::model::CacheEntryInfo::CalculateRealSize
static constexpr uint64_t CalculateRealSize(const CacheEntryInfo &cacheEntryInfo) noexcept
Calculates the real size of cacheEntryInfo.
Definition: CacheEntryInfo.h:73
TrailingVariableDataLayout.h
catapult::model::CacheEntryInfo::Id
TIdentifier Id
Cache entry's id.
Definition: CacheEntryInfo.h:42
catapult::model::CacheEntryInfo::DataPtr
const uint8_t * DataPtr() const
Returns a const pointer to the first data byte in this cache entry info.
Definition: CacheEntryInfo.h:51
catapult::model::CacheEntryInfo::Max_Data_Size
static constexpr uint32_t Max_Data_Size
Definition: CacheEntryInfo.h:38
catapult
Definition: AddressExtractionExtension.cpp:28
catapult::model::TrailingVariableDataLayout< CacheEntryInfo< TIdentifier >, uint8_t >::ToTypedPointer
static const uint8_t * ToTypedPointer(const uint8_t *pData)
Gets a typed pointer to the variable data pData.
Definition: TrailingVariableDataLayout.h:44
catapult::model::CacheEntryInfo::DataPtr
uint8_t * DataPtr()
Returns a pointer to the first data byte in this cache entry info.
Definition: CacheEntryInfo.h:56
catapult::model::CacheEntryInfo::IsTooLarge
bool IsTooLarge() const
Returns true if the serialized cache entry is too large.
Definition: CacheEntryInfo.h:67
catapult::model::CacheEntryInfo::HasData
bool HasData() const
Returns true if data is available.
Definition: CacheEntryInfo.h:62
catapult::model::CacheEntryInfo
Cache entry info.
Definition: CacheEntryInfo.h:30
catapult::model::TrailingVariableDataLayout
Definition: TrailingVariableDataLayout.h:31