mirror of
https://github.com/facebookincubator/mvfst.git
synced 2025-07-08 15:21:56 +03:00
Summary: This is an API break, but it should mostly be a manageable one. We want to be able to compile mvfst internally without exceptions, and folly::Optional is one dependency that makes this challenging. Additionally, we already have an imported secondary optional type for performance/struct size reasons, tiny-optional. This second optional interface is mostly compatible in an API sense (including the use of std::nullopt) with std::optional. Thus our approach is to remove the dependency on folly::Optional, and offer a quic::Optional instead. The next diff will properly vendor tiny-optional so that quic::Optional is an independent version of it. Reviewed By: sharmafb, kvtsoy Differential Revision: D74133131 fbshipit-source-id: 715f8bb5043ba3bb876cacfe54236887e0686b30
49 lines
1.6 KiB
C++
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) {
|
|
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, std::nullopt);
|
|
}
|
|
// 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
|