29 using std::unique_ptr;
44 Cursor rcursor(iobuf1.get());
67 Cursor cursor(iobuf1.get());
78 wcursor.reset(iobuf1.get());
112 Cursor cursor2 = start + 9;
116 cursor2 = cursor2 + 1;
124 Cursor rcursor(iobuf1.get());
186 str.append(reinterpret_cast<const char*>(b.data()), b.size());
187 cursor.
skip(b.size());
207 memset(buf, 0,
sizeof(buf));
208 Cursor(iobuf1.get()).pull(buf, 11);
211 memset(buf, 0,
sizeof(buf));
219 auto b = cursor.peekBytes();
221 cursor.skip(b.size());
222 b = cursor.peekBytes();
224 cursor.skip(b.size());
225 b = cursor.peekBytes();
227 cursor.skip(b.size());
235 auto b = cursor.peekBytes();
263 Cursor rcursor(iobuf1.get());
268 rcursor.reset(iobuf1.get());
277 wcursor2.
push(rcursor, 20);
280 EXPECT_THROW(wcursor2.push(rcursor, 20), std::out_of_range);
283 Cursor rcursor2(iobuf4.get());
311 cursor.gatherAtMost(10);
318 reinterpret_cast<const char*>(cursor.data()), cursor.length()));
345 std::unique_ptr<IOBuf> cloned;
347 Cursor(iobuf1.get()).clone(cloned, 3);
348 EXPECT_EQ(2, cloned->countChainElements());
349 EXPECT_EQ(3, cloned->computeChainDataLength());
352 EXPECT_EQ(3, cloned->countChainElements());
353 EXPECT_EQ(11, cloned->computeChainDataLength());
360 Cursor(iobuf1.get()).clone(cloned, 3);
361 EXPECT_EQ(2, cloned->countChainElements());
362 EXPECT_EQ(3, cloned->computeChainDataLength());
368 EXPECT_EQ(4, cursor.getCurrentPosition());
379 Cursor(iobuf1.get()).clone(cloned, 1);
380 EXPECT_EQ(1, cloned->countChainElements());
381 EXPECT_EQ(1, cloned->computeChainDataLength());
386 EXPECT_EQ(2, cursor.getCurrentPosition());
396 Cursor(iobuf1.get()).clone(cloned, 1);
397 EXPECT_EQ(1, cloned->countChainElements());
398 EXPECT_EQ(1, cloned->computeChainDataLength());
403 EXPECT_EQ(2, cursor.getCurrentPosition());
414 Cursor(iobuf1.get()).clone(cloned, 1);
415 EXPECT_EQ(1, cloned->countChainElements());
416 EXPECT_EQ(1, cloned->computeChainDataLength());
419 EXPECT_EQ(1, cursor.getCurrentPosition());
429 Cursor(iobuf1.get()).clone(cloned, 1);
430 EXPECT_EQ(1, cloned->countChainElements());
431 EXPECT_EQ(1, cloned->computeChainDataLength());
433 cursor.advanceToEnd();
434 EXPECT_EQ(17, cursor.getCurrentPosition());
436 EXPECT_EQ(18, cursor.getCurrentPosition());
452 auto iobuf =
empty->clone();
453 iobuf->prependChain(hel->clone());
454 iobuf->prependChain(lo->clone());
455 iobuf->prependChain(
empty->clone());
456 iobuf->prependChain(hel->clone());
457 iobuf->prependChain(lo->clone());
458 iobuf->prependChain(
empty->clone());
459 iobuf->prependChain(lo->clone());
460 iobuf->prependChain(hel->clone());
461 iobuf->prependChain(lo->clone());
462 iobuf->prependChain(lo->clone());
464 Cursor cursor(iobuf.get());
465 std::unique_ptr<IOBuf> cloned;
467 cursor.pull(&data, 3);
468 cursor.clone(cloned, 2);
469 EXPECT_EQ(1, cloned->countChainElements());
473 cursor.pull(&data, 3);
477 cursor.clone(cloned, 2);
481 cursor.clone(cloned, 2);
491 auto len1 = app.length();
495 app.ensure(len1 + 1);
514 "longer than our original allocation size,",
515 "and will therefore require a new allocation",
522 "test32this string is longer than our original " 523 "allocation size,and will therefore require a " 524 "new allocation 0x12345678",
532 format(
"{}",
"test")(app);
540 "longer than our original allocation size,",
541 "and will therefore require a new allocation",
545 "test32this string is longer than our original " 546 "allocation size,and will therefore require a " 547 "new allocation 0x12345678",
567 }
while (buf != queue.
front());
581 std::vector<uint8_t>
data;
583 std::iota(data.begin(), data.end(),
uint8_t(0));
585 appender.pushAtMost(data.data(), 100);
587 appender.pushAtMost(data.data() + 100, data.size() - 100);
588 const auto buf = queue.
front();
593 EXPECT_EQ(1000, buf->computeChainDataLength());
594 const StringPiece sp{(
const char*)data.data(), data.size()};
604 std::vector<uint8_t>
data;
606 std::iota(data.begin(), data.end(), 0);
611 const StringPiece sp{(
const char*)data.data(), data.size()};
620 appender.insert(buf);
622 appender.pushAtMost(&x, 1);
636 Cursor curs1(chain1.get());
646 Cursor curs2(chain1.get());
656 std::unique_ptr<IOBuf> chain2 = chain1->
clone();
658 Cursor curs1(chain1.get());
659 Cursor curs2(chain2.get());
671 Cursor curs1(chain.get());
673 Cursor curs2(chain.get());
693 iobuf1->trimStart(5);
703 iobuf1->prev()->append(5);
713 chain->appendChain(chain->clone());
714 EXPECT_EQ(2, chain->countChainElements());
715 EXPECT_EQ(20, chain->computeChainDataLength());
718 for (
size_t i = 0;
i <= 20; ++
i) {
734 app.
push(reinterpret_cast<const uint8_t*>(
"hello\0world\0\x01"), 13);
737 EXPECT_STREQ(
"hello", curs.readTerminatedString().c_str());
738 EXPECT_STREQ(
"world", curs.readTerminatedString().c_str());
748 app.
push(reinterpret_cast<const uint8_t*>(
"hello world\0"), 12);
751 EXPECT_STREQ(
"hello world", curs.readTerminatedString().c_str());
761 rwc.
push(reinterpret_cast<const uint8_t*>(
"hello world\0"), 12);
764 EXPECT_STREQ(
"hello world", curs.readTerminatedString().c_str());
772 app.
push(reinterpret_cast<const uint8_t*>(
"hello world\0"), 12);
775 EXPECT_THROW(curs.readTerminatedString(
'\0', 5), std::length_error);
783 app.
push(reinterpret_cast<const uint8_t*>(
"hello\0"), 6);
788 EXPECT_STREQ(
"hello", curs.readTerminatedString().c_str());
796 app.
push(reinterpret_cast<const uint8_t*>(
"hello"), 5);
801 EXPECT_THROW(curs.readTerminatedString(), std::out_of_range);
808 app.
push(reinterpret_cast<const uint8_t*>(
"hello\0"), 6);
813 EXPECT_THROW(curs.readTerminatedString(
'\0', 3), std::length_error);
821 app.
push(reinterpret_cast<const uint8_t*>(
"helloworld\x01"), 11);
835 app.
push(reinterpret_cast<const uint8_t*>(
"hello world"), 11);
838 EXPECT_STREQ(
"hello world", curs.readFixedString(11).c_str());
848 rwc.
push(reinterpret_cast<const uint8_t*>(
"hello world"), 11);
851 EXPECT_STREQ(
"hello world", curs.readFixedString(11).c_str());
859 app.
push(reinterpret_cast<const uint8_t*>(
"hello"), 5);
870 return (
ch >=
'a' &&
ch <=
'z') || (
ch >=
'A' &&
ch <=
'Z');
872 auto isDigit = [](
uint8_t ch) {
return (
ch >=
'0' &&
ch <=
'9'); };
896 curs.skipWhile(isDigit);
897 curs.skipWhile(isAlpha);
905 std::unique_ptr<IOBuf> chain;
988 curs.reset(chain.get());
1008 curs.reset(chain.get());
1010 curs.reset(chain.get());
1012 curs.advanceToEnd();
1019 curs.reset(chain.get());
1020 curs.advanceToEnd();
1041 Cursor curs(chain.get());
1044 curs.reset(chain.get());
1046 curs.advanceToEnd();
1056 curs.advanceToEnd();
1065 Cursor curs(chain.get());
1070 curs.advanceToEnd();
1071 auto retreated = curs - 5;
1087 Cursor rcursor(iobuf1.get());
1119 const uint32_t expected = 0x01020304;
1133 const uint32_t expected = 0x01020304;
1168 wcursor.
push(emptyBytes);
1169 EXPECT_EQ(0, buf.computeChainDataLength());
1173 app.push(emptyBytes);
1174 EXPECT_EQ(0, buf.computeChainDataLength());
1184 Cursor cursor(iobuf1.get());
1186 EXPECT_EQ(0, cursor.getCurrentPosition());
1190 EXPECT_EQ(3, cursor.getCurrentPosition());
1195 EXPECT_EQ(7, cursor.getCurrentPosition());
1200 EXPECT_EQ(5, cursor.getCurrentPosition());
1204 cursor.advanceToEnd();
1205 EXPECT_EQ(30, cursor.getCurrentPosition());
1209 cursor.reset(iobuf1.get());
1210 EXPECT_EQ(0, cursor.getCurrentPosition());
#define EXPECT_LE(val1, val2)
const folly::IOBuf * front() const
folly::StringPiece toString(StateEnum state)
#define EXPECT_THROW(statement, expected_exception)
void printf(FOLLY_PRINTF_FORMAT const char *fmt,...) FOLLY_PRINTF_FORMAT_ATTR(2
static std::unique_ptr< IOBuf > create(std::size_t capacity)
static std::unique_ptr< IOBuf > wrapBuffer(const void *buf, std::size_t capacity)
std::enable_if< std::is_arithmetic< T >::value >::type write(T value)
#define EXPECT_EQ(val1, val2)
fbstring moveToFbString()
std::enable_if< std::is_arithmetic< T >::value, bool >::type tryRead(T &val)
void appendChain(std::unique_ptr< IOBuf > &&iobuf)
constexpr detail::Map< Move > move
const uint8_t * tail() const
void append(std::unique_ptr< IOBuf > &buf, StringPiece str)
constexpr size_type size() const
const uint8_t * data() const
void push(const uint8_t *buf, size_t len)
std::unique_ptr< IOBuf > clone() const
size_t countChainElements() const
detail::Skip skip(size_t count)
#define EXPECT_GE(val1, val2)
std::size_t capacity() const
std::size_t tailroom() const
#define EXPECT_STREQ(s1, s2)
constexpr auto empty(C const &c) -> decltype(c.empty())
constexpr Iter data() const
constexpr auto data(C &c) -> decltype(c.data())
std::size_t length() const
std::basic_string< E, T, A > toStdString() const
constexpr Range< Iter > range(Iter first, Iter last)
RWCursor< CursorAccess::PRIVATE > RWPrivateCursor
void prependChain(std::unique_ptr< IOBuf > &&iobuf)
std::size_t computeChainDataLength() const
#define EXPECT_TRUE(condition)
Range< const unsigned char * > ByteRange
#define EXPECT_NE(val1, val2)
Formatter< false, Args... > format(StringPiece fmt, Args &&...args)
void trimStart(std::size_t amount)
#define EXPECT_FALSE(condition)
Range< const char * > StringPiece
#define EXPECT_LT(val1, val2)
TEST(SequencedExecutor, CPUThreadPoolExecutor)
size_t totalLength() const
void append(std::size_t amount)