18 using namespace folly;
25 const uint32_t kMaxLiteralSize = 1 << 17;
35 decoder_(cursor_, 0, kMaxLiteralSize) {
41 releaseData(encoder_);
52 resetDecoder(buf_.get());
57 decoder_.reset(cursor_);
63 std::unique_ptr<IOBuf> buf_{
nullptr};
69 EXPECT_EQ(encoder_.encodeInteger(7, 192, 6), 1);
71 EXPECT_EQ(encoder_.encodeInteger(7, 192, 3), 2);
72 EXPECT_EQ(encoder_.encodeInteger(255, 0, 8), 2);
82 EXPECT_EQ(encoder_.encodeInteger(7, 192, 2), 2);
89 EXPECT_EQ(encoder_.encodeInteger(1337, 0, 5), 3);
98 string literal(
"accept-encoding");
99 EXPECT_EQ(encoder_.encodeLiteral(literal), 16);
103 for (
size_t i = 0;
i < literal.size();
i++) {
109 string literal(
"accept-encodin");
111 EXPECT_EQ(encoder_.encodeLiteral(0xE0, 4, literal), 15);
115 for (
size_t i = 0;
i < literal.size();
i++) {
121 string accept(
"accept-encoding");
125 releaseData(encoder);
132 string accept(
"accept-encoding");
136 releaseData(encoder);
144 uint8_t* wdata = buf_->writableData();
151 CHECK_EQ(integer, 67);
156 CHECK_EQ(integer, 3);
162 CHECK_EQ(integer, 67);
167 CHECK_EQ(integer, 195);
172 uint8_t* wdata = buf_->writableData();
180 CHECK_EQ(integer, 3);
181 CHECK_EQ(decoder_.cursor().length(), 0);
187 CHECK_EQ(integer, 130);
188 CHECK_EQ(decoder_.cursor().length(), 0);
196 CHECK_EQ(integer, 131);
197 CHECK_EQ(decoder_.cursor().length(), 0);
204 CHECK_EQ(integer, 1337);
205 CHECK_EQ(decoder_.cursor().length(), 0);
213 CHECK_EQ(decoder_.decodeInteger(5, integer), DecodeError::BUFFER_UNDERFLOW);
217 uint8_t* wdata = buf_->writableData();
221 CHECK_EQ(decoder_.decodeInteger(5, integer), DecodeError::BUFFER_UNDERFLOW);
227 uint8_t* wdata = buf_->writableData();
234 CHECK_EQ(decoder_.decodeLiteral(literal), DecodeError::BUFFER_UNDERFLOW);
241 EXPECT_EQ(decoder_.decodeLiteral(literal), DecodeError::BUFFER_UNDERFLOW);
250 uint32_t size = buf1->capacity() + buf2->capacity() - 10;
252 uint32_t sizeLen = encoder_.encodeInteger(size, 0, 7);
255 memcpy(buf1->writableData(), buf_->data(), sizeLen);
256 for (
size_t i = sizeLen;
i < buf1->capacity();
i++) {
257 buf1->writableData()[
i] =
'x';
259 buf1->append(buf1->capacity());
260 for (
size_t i = 0;
i < buf2->capacity() - 10 + sizeLen;
i++) {
261 buf2->writableData()[
i] =
'y';
263 buf2->append(buf2->capacity() - 10 + sizeLen);
266 resetDecoder(buf1.get());
271 EXPECT_EQ(literal[literal.size() - 1],
'y');
276 std::array<uint8_t, 3> gzip{0x9b, 0xd9, 0xab};
280 uint32_t size = buf1->capacity() + buf2->capacity() - 10;
285 uint32_t sizeLen = encoder_.encodeInteger(size, 128, 7);
288 memcpy(buf1->writableData(), buf_->data(), sizeLen);
291 for (
size_t i = sizeLen;
i < buf1->capacity();
i++) {
292 buf1->writableData()[
i] = gzip[hi];
295 buf1->append(buf1->capacity());
296 for (
size_t i = 0;
i < buf2->capacity() - 10 + sizeLen;
i++) {
297 buf2->writableData()[
i] = gzip[hi];
300 buf2->append(buf2->capacity() - 10 + sizeLen);
303 resetDecoder(buf1.get());
306 EXPECT_EQ(literal.size(), 4 * (size / 3));
308 EXPECT_EQ(literal.rfind(
"gzip"), literal.size() - 4);
313 std::array<uint8_t, 3> gzip{0x9b, 0xd9, 0xab};
317 encoder_.encodeInteger(size, 0x80 | 0x10, 4);
319 memcpy(buf_->writableData() + 1, gzip.data(),
size);
322 resetDecoder(buf_.get());
325 EXPECT_EQ(literal.size(), 4 * (size / 3));
327 EXPECT_EQ(literal.rfind(
"gzip"), literal.size() - 4);
334 uint8_t* wdata = buf_->writableData();
336 buf_->append(1 + gzip.size());
337 wdata[0] = gzip.size();
338 memcpy(wdata + 1, gzip.c_str(), gzip.size());
341 decoder_.decodeLiteral(literal);
342 CHECK_EQ(literal, gzip);
350 uint8_t* wdata = buf_->writableData();
352 buf_->append(1 + gzip.size());
353 wdata[0] = 0xE0 | gzip.size();
354 memcpy(wdata + 1, gzip.c_str(), gzip.size());
357 decoder_.decodeLiteral(4, literal);
358 CHECK_EQ(literal, gzip);
366 releaseData(encoder);
368 EXPECT_EQ(decoder_.cursor().length(), 4);
373 EXPECT_EQ(decoder_.cursor().length(), 0);
378 releaseData(encoder);
390 uint8_t *wdata = buf_->writableData();
407 EXPECT_EQ(decoder_.decodeInteger(8, integer), DecodeError::INTEGER_OVERFLOW);
423 EXPECT_EQ(decoder_.decodeInteger(8, integer), DecodeError::INTEGER_OVERFLOW);
432 for (
uint8_t bitprefix = 1; bitprefix <= 8; bitprefix++) {
459 Cursor cursor(first.get());
462 decoder.decodeLiteral(decoded);
471 uint32_t largeSize = 10 + kMaxLiteralSize;
474 largeLiteral.append(largeSize,
'x');
479 EXPECT_EQ(decoder_.decodeLiteral(decoded), DecodeError::LITERAL_TOO_LARGE);
void resetDecoder(IOBuf *buf)
uint32_t encodeLiteral(folly::StringPiece literal)
std::unique_ptr< folly::IOBuf > release()
static std::unique_ptr< IOBuf > create(std::size_t capacity)
#define EXPECT_EQ(val1, val2)
void appendChain(std::unique_ptr< IOBuf > &&iobuf)
constexpr detail::Map< Move > move
—— Concurrent Priority Queue Implementation ——
constexpr auto size(C const &c) -> decltype(c.size())
constexpr Iter data() const
std::size_t length() const
uint32_t encodeInteger(uint64_t value, uint8_t instruction, uint8_t nbit)
TEST_F(AsyncSSLSocketWriteTest, write_coalescing1)
HPACKEncodeBuffer encoder_
#define EXPECT_TRUE(condition)
uint64_t value(const typename LockFreeRingBuffer< T, Atom >::Cursor &rbcursor)
void releaseData(HPACKEncodeBuffer &encoder)
HPACKDecodeBuffer decoder_
constexpr detail::First first
NetworkSocket accept(NetworkSocket s, sockaddr *addr, socklen_t *addrlen)