proxygen
folly::io::QueueAppender Class Reference

#include <Cursor.h>

Inheritance diagram for folly::io::QueueAppender:
folly::io::detail::Writable< QueueAppender >

Public Member Functions

 QueueAppender (IOBufQueue *queue, std::size_t growth)
 
void reset (IOBufQueue *queue, std::size_t growth)
 
uint8_twritableData ()
 
size_t length ()
 
void append (size_t n)
 
void ensure (size_t n)
 
template<class T >
std::enable_if< std::is_arithmetic< T >::value >::type write (T value)
 
size_t pushAtMost (const uint8_t *buf, size_t len)
 
void insert (std::unique_ptr< folly::IOBuf > buf)
 
void insert (const folly::IOBuf &buf)
 
- Public Member Functions inherited from folly::io::detail::Writable< QueueAppender >
std::enable_if< std::is_arithmetic< T >::value >::type write (T value)
 
void writeBE (T value)
 
void writeLE (T value)
 
void push (const uint8_t *buf, size_t len)
 
void push (ByteRange buf)
 
void push (Cursor cursor, size_t len)
 
size_t pushAtMost (ByteRange buf)
 
size_t pushAtMost (Cursor cursor, size_t len)
 

Private Member Functions

FOLLY_NOINLINE void ensureSlow (size_t n)
 
template<class T >
std::enable_if< std::is_arithmetic< T >::value >::type FOLLY_NOINLINE writeSlow (T value)
 

Private Attributes

folly::IOBufQueue::WritableRangeCache queueCache_ {nullptr}
 
size_t growth_ {0}
 

Detailed Description

Definition at line 1101 of file Cursor.h.

Constructor & Destructor Documentation

folly::io::QueueAppender::QueueAppender ( IOBufQueue queue,
std::size_t  growth 
)
inline

Create an Appender that writes to a IOBufQueue. When we allocate space in the queue, we grow no more than growth bytes at once (unless you call ensure() with a bigger value yourself).

Definition at line 1108 of file Cursor.h.

1109  : queueCache_(queue), growth_(growth) {}
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180

Member Function Documentation

void folly::io::QueueAppender::append ( size_t  n)
inline

Definition at line 1124 of file Cursor.h.

Referenced by TEST_F().

1124  {
1125  queueCache_.append(n);
1126  }
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
void folly::io::QueueAppender::ensure ( size_t  n)
inline

Definition at line 1130 of file Cursor.h.

References folly::io::detail::CursorBase< Derived, BufType >::length().

Referenced by TEST_F().

1130  {
1131  if (length() < n) {
1132  ensureSlow(n);
1133  }
1134  }
FOLLY_NOINLINE void ensureSlow(size_t n)
Definition: Cursor.h:1183
FOLLY_NOINLINE void folly::io::QueueAppender::ensureSlow ( size_t  n)
inlineprivate

Definition at line 1183 of file Cursor.h.

References FOLLY_NOINLINE, type, and value.

1183  {
1186  }
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
Definition: IOBufQueue.h:356
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
void folly::io::QueueAppender::insert ( std::unique_ptr< folly::IOBuf buf)
inline

Definition at line 1169 of file Cursor.h.

References folly::gen::move.

Referenced by BENCHMARK(), and proxygen::compress::QPACKScheme::encode().

1169  {
1170  if (buf) {
1171  queueCache_.queue()->append(std::move(buf), true);
1172  }
1173  }
void append(std::unique_ptr< folly::IOBuf > &&buf, bool pack=false)
Definition: IOBufQueue.cpp:143
constexpr detail::Map< Move > move
Definition: Base-inl.h:2567
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
void folly::io::QueueAppender::insert ( const folly::IOBuf buf)
inline

Definition at line 1175 of file Cursor.h.

References folly::IOBuf::clone().

1175  {
1176  insert(buf.clone());
1177  }
std::unique_ptr< IOBuf > clone() const
Definition: IOBuf.cpp:527
void insert(std::unique_ptr< folly::IOBuf > buf)
Definition: Cursor.h:1169
size_t folly::io::QueueAppender::length ( )
inline

Definition at line 1120 of file Cursor.h.

Referenced by TEST_F().

1120  {
1121  return queueCache_.length();
1122  }
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
size_t folly::io::QueueAppender::pushAtMost ( const uint8_t buf,
size_t  len 
)
inline

Definition at line 1148 of file Cursor.h.

References folly::io::detail::CursorBase< Derived, BufType >::length(), and min.

1148  {
1149  // Fill the current buffer
1150  const size_t copyLength = std::min(len, length());
1151  if (copyLength != 0) {
1152  memcpy(writableData(), buf, copyLength);
1153  queueCache_.appendUnsafe(copyLength);
1154  buf += copyLength;
1155  }
1156  size_t remaining = len - copyLength;
1157  // Allocate more buffers as necessary
1158  while (remaining != 0) {
1159  auto p = queueCache_.queue()->preallocate(
1160  std::min(remaining, growth_), growth_, remaining);
1161  memcpy(p.first, buf, p.second);
1162  queueCache_.queue()->postallocate(p.second);
1163  buf += p.second;
1164  remaining -= p.second;
1165  }
1166  return len;
1167  }
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
Definition: IOBufQueue.h:356
LogLevel min
Definition: LogLevel.cpp:30
uint8_t * writableData()
Definition: Cursor.h:1116
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
void postallocate(std::size_t n)
Definition: IOBufQueue.h:380
void folly::io::QueueAppender::reset ( IOBufQueue queue,
std::size_t  growth 
)
inline

Definition at line 1111 of file Cursor.h.

1111  {
1112  queueCache_.reset(queue);
1113  growth_ = growth;
1114  }
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
uint8_t* folly::io::QueueAppender::writableData ( )
inline

Definition at line 1116 of file Cursor.h.

1116  {
1117  return queueCache_.writableData();
1118  }
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
template<class T >
std::enable_if<std::is_arithmetic<T>::value>::type folly::io::QueueAppender::write ( T  value)
inline

Definition at line 1137 of file Cursor.h.

References folly::io::detail::CursorBase< Derived, BufType >::length(), folly::storeUnaligned(), folly::T, and folly::value().

Referenced by folly::bser::bserEncode(), folly::bser::bserEncodeArray(), folly::bser::bserEncodeArraySimple(), folly::bser::bserEncodeInt(), folly::bser::bserEncodeObject(), folly::bser::bserEncodeString(), and runArithmeticBench().

1137  {
1138  // We can't fail.
1139  if (length() >= sizeof(T)) {
1141  queueCache_.appendUnsafe(sizeof(T));
1142  } else {
1143  writeSlow<T>(value);
1144  }
1145  }
folly::std T
void storeUnaligned(void *p, T value)
Definition: Bits.h:352
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
template<class T >
std::enable_if<std::is_arithmetic<T>::value>::type FOLLY_NOINLINE folly::io::QueueAppender::writeSlow ( T  value)
inlineprivate

Definition at line 1190 of file Cursor.h.

References folly::storeUnaligned(), folly::T, and folly::value().

1190  {
1191  queueCache_.queue()->preallocate(sizeof(T), growth_);
1193 
1195  queueCache_.appendUnsafe(sizeof(T));
1196  }
folly::std T
std::pair< void *, std::size_t > preallocate(std::size_t min, std::size_t newAllocationSize, std::size_t max=std::numeric_limits< std::size_t >::max())
Definition: IOBufQueue.h:356
void storeUnaligned(void *p, T value)
Definition: Bits.h:352
folly::IOBufQueue::WritableRangeCache queueCache_
Definition: Cursor.h:1180
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)

Member Data Documentation

size_t folly::io::QueueAppender::growth_ {0}
private

Definition at line 1181 of file Cursor.h.

folly::IOBufQueue::WritableRangeCache folly::io::QueueAppender::queueCache_ {nullptr}
private

Definition at line 1180 of file Cursor.h.


The documentation for this class was generated from the following file: