2 * Copyright (c) Meta Platforms, Inc. and affiliates.
5 * This source code is licensed under both the BSD-style license (found in the
6 * LICENSE file in the root directory of this source tree) and the GPLv2 (found
7 * in the COPYING file in the root directory of this source tree).
9 #include "SkippableFrame.h"
11 #include "utils/Range.h"
15 using namespace pzstd;
17 SkippableFrame::SkippableFrame(std::uint32_t size) : frameSize_(size) {
18 MEM_writeLE32(data_.data(), kSkippableFrameMagicNumber);
19 MEM_writeLE32(data_.data() + 4, kFrameContentsSize);
20 MEM_writeLE32(data_.data() + 8, frameSize_);
23 /* static */ std::size_t SkippableFrame::tryRead(ByteRange bytes) {
24 if (bytes.size() < SkippableFrame::kSize ||
25 MEM_readLE32(bytes.begin()) != kSkippableFrameMagicNumber ||
26 MEM_readLE32(bytes.begin() + 4) != kFrameContentsSize) {
29 return MEM_readLE32(bytes.begin() + 8);