SwapMetaView.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 1996-2023 The Squid Software Foundation and contributors
3  *
4  * Squid software is distributed under GPLv2+ license and includes
5  * contributions from numerous individuals and organizations.
6  * Please see the COPYING and CONTRIBUTORS files for details.
7  */
8 
9 #ifndef SQUID_SRC_STORE_SWAPMETAVIEW_H
10 #define SQUID_SRC_STORE_SWAPMETAVIEW_H
11 
12 #include "base/TextException.h"
13 #include "store/SwapMeta.h"
14 
15 #include <iosfwd>
16 
17 namespace Store {
18 
21 {
22 public:
24  void checkExpectedLength(size_t) const;
25 
26 public:
30  const void *rawValue = nullptr;
31 
35  size_t rawLength = 0;
36 
40 
44 
45 private:
46  /*
47  * SwapMetaView objects should always be accessed through SwapMetaIterator
48  * or SwapMetaUnpacker for read-only access to the current view of metadata.
49  */
50  friend class SwapMetaIterator;
51 
52  SwapMetaView() = default;
53  SwapMetaView(const SwapMetaView &) = default;
54  SwapMetaView(SwapMetaView &&) = default;
55  SwapMetaView &operator =(const SwapMetaView &) = default;
56  SwapMetaView &operator =(SwapMetaView &&) = default;
57 
61  explicit SwapMetaView(const void *begin, const void * const end);
62 };
63 
66 template <typename Item>
67 void
68 SwapMetaExtract(Item &item, const char * &input, const void *end)
69 {
70  if (input + sizeof(item) > end)
71  throw TextException("truncated swap meta part", Here());
72  memcpy(&item, input, sizeof(item));
73  input += sizeof(item);
74 }
75 
77 std::ostream &operator <<(std::ostream &, const SwapMetaView &);
78 
79 } // namespace Store
80 
81 #endif /* SQUID_SRC_STORE_SWAPMETAVIEW_H */
82 
#define Here()
source code location of the caller
Definition: Here.h:15
SwapMetaType type
Definition: SwapMetaView.h:43
void checkExpectedLength(size_t) const
ensures that our fixed-size field value has the given expected length
Definition: SwapMetaView.cc:83
a swap metadata field inside the buffer given to SwapMetaUnpacker
Definition: SwapMetaView.h:20
char RawSwapMetaType
Definition: SwapMeta.h:95
void SwapMetaExtract(Item &item, const char *&input, const void *end)
Definition: SwapMetaView.h:68
std::ostream & operator<<(std::ostream &os, const ParsingBuffer &b)
SwapMetaView & operator=(const SwapMetaView &)=default
SwapMetaView()=default
@ STORE_META_VOID
Definition: SwapMeta.h:55
RawSwapMetaType rawType
Definition: SwapMetaView.h:39
an std::runtime_error with thrower location info
Definition: TextException.h:20
const RawSwapMetaType RawSwapMetaTypeBottom
Definition: SwapMeta.h:126
SwapMetaType
Definition: SwapMeta.h:52
iterates serialized swap meta fields loaded into a given buffer
Definition: SwapMetaIn.cc:26
const void * rawValue
Definition: SwapMetaView.h:30

 

Introduction

Documentation

Support

Miscellaneous