]> git.proxmox.com Git - ceph.git/blob - ceph/src/zstd/contrib/pzstd/SkippableFrame.cpp
add subtree-ish sources for 12.0.3
[ceph.git] / ceph / src / zstd / contrib / pzstd / SkippableFrame.cpp
1 /**
2 * Copyright (c) 2016-present, Facebook, Inc.
3 * All rights reserved.
4 *
5 * This source code is licensed under the BSD-style license found in the
6 * LICENSE file in the root directory of this source tree. An additional grant
7 * of patent rights can be found in the PATENTS file in the same directory.
8 */
9 #include "SkippableFrame.h"
10 #include "mem.h"
11 #include "utils/Range.h"
12
13 #include <cstdio>
14
15 using namespace pzstd;
16
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_);
21 }
22
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) {
27 return 0;
28 }
29 return MEM_readLE32(bytes.begin() + 8);
30 }