1
0
mirror of https://github.com/facebookincubator/mvfst.git synced 2025-04-18 17:24:03 +03:00
mvfst/quic/codec/QuicHeaderCodec.cpp
Nicholas Ormrod 484898f61b facebook-unused-include-check in fbcode/quic
Summary:
Remove headers flagged by facebook-unused-include-check over fbcode.quic.

+ format and autodeps

This is a codemod. It was automatically generated and will be landed once it is approved and tests are passing in sandcastle.
You have been added as a reviewer by Sentinel or Butterfly.

Autodiff project: uiq
Autodiff partition: fbcode.quic
Autodiff bookmark: ad.uiq.fbcode.quic

Reviewed By: hanidamlaj

Differential Revision: D69864370

fbshipit-source-id: fb8f85599e1e12429f00dc2817dfc5ecf55bc482
2025-02-20 10:03:44 -08:00

49 lines
1.6 KiB
C++

/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
#include <quic/codec/QuicHeaderCodec.h>
#include <quic/codec/Decode.h>
namespace quic {
ParsedHeaderResult::ParsedHeaderResult(
bool isVersionNegotiationIn,
Optional<PacketHeader> parsedHeaderIn)
: isVersionNegotiation(isVersionNegotiationIn),
parsedHeader(std::move(parsedHeaderIn)) {
CHECK(isVersionNegotiation || parsedHeader);
}
folly::Expected<ParsedHeaderResult, TransportErrorCode> parseHeader(
const folly::IOBuf& data) {
folly::io::Cursor cursor(&data);
if (!cursor.canAdvance(sizeof(uint8_t))) {
return folly::makeUnexpected(TransportErrorCode::FRAME_ENCODING_ERROR);
}
uint8_t initialByte = cursor.readBE<uint8_t>();
if (getHeaderForm(initialByte) == HeaderForm::Long) {
return parseLongHeader(initialByte, cursor)
.then([](ParsedLongHeaderResult&& parsedLongHeaderResult) {
if (parsedLongHeaderResult.isVersionNegotiation) {
return ParsedHeaderResult(true, none);
}
// We compensate for the type byte length by adding it back.
DCHECK(parsedLongHeaderResult.parsedLongHeader);
return ParsedHeaderResult(
false,
PacketHeader(
std::move(parsedLongHeaderResult.parsedLongHeader->header)));
});
} else {
return parseShortHeader(initialByte, cursor).then([](ShortHeader&& header) {
return ParsedHeaderResult(false, PacketHeader(std::move(header)));
});
}
}
} // namespace quic