ParsingBuffer.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_PARSINGBUFFER_H
10 #define SQUID_SRC_STORE_PARSINGBUFFER_H
11 
12 #include "sbuf/SBuf.h"
13 #include "StoreIOBuffer.h"
14 
15 #include <optional>
16 
17 namespace Store
18 {
19 
36 {
37 public:
39  ParsingBuffer() = default;
40 
42  explicit ParsingBuffer(StoreIOBuffer &);
43 
45  const char *c_str() { terminate(); return memory(); }
46 
48  SBuf toSBuf() const;
49 
51  size_t contentSize() const;
52 
54  size_t spaceSize() const;
55 
57  size_t capacity() const;
58 
64  StoreIOBuffer content() const;
65 
72 
77  StoreIOBuffer makeSpace(size_t pageSize);
78 
85 
87  void appended(const char *, size_t);
88 
90  void consume(size_t);
91 
97 
99  void print(std::ostream &) const;
100 
101 private:
102  const char *memory() const;
103  void terminate();
104  void growSpace(size_t);
105 
106 private:
109 
112 
115  std::optional<SBuf> extraMemory_;
116 };
117 
118 inline std::ostream &
119 operator <<(std::ostream &os, const ParsingBuffer &b)
120 {
121  b.print(os);
122  return os;
123 }
124 
125 } // namespace Store
126 
127 #endif /* SQUID_SRC_STORE_PARSINGBUFFER_H */
128 
StoreIOBuffer makeSpace(size_t pageSize)
Definition: SBuf.h:93
size_t capacity() const
the maximum number of bytes we can store without allocating more space
const char * c_str()
a NUL-terminated version of content(); same lifetime as content()
Definition: ParsingBuffer.h:45
StoreIOBuffer readerSuppliedMemory_
externally allocated buffer we were seeded with (or a zero-size one)
void consume(size_t)
get rid of previously appended() prefix of a given size
void appended(const char *, size_t)
remember the new bytes received into the previously provided space()
void print(std::ostream &) const
summarizes object state (for debugging)
std::ostream & operator<<(std::ostream &os, const ParsingBuffer &b)
void growSpace(size_t)
makes sure we have the requested number of bytes, allocates enough memory if needed
StoreIOBuffer content() const
StoreIOBuffer makeInitialSpace()
Definition: ParsingBuffer.h:84
std::optional< SBuf > extraMemory_
SBuf toSBuf() const
export content() into SBuf, avoiding content copying when possible
StoreIOBuffer packBack()
size_t readerSuppliedMemoryContentSize_
append()ed to readerSuppliedMemory_ bytes that were not consume()d
const char * memory() const
a read-only content start (or nil for some zero-size buffers)
size_t spaceSize() const
the number of bytes in the space() buffer
ParsingBuffer()=default
creates buffer without any space or content
size_t contentSize() const
the total number of append()ed bytes that were not consume()d
StoreIOBuffer space()

 

Introduction

Documentation

Support

Miscellaneous