1 /* 2 * Copyright (c) 2016-present, Facebook, Inc. 3 * All rights reserved. 4 * 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). 8 */ 9 #include "SkippableFrame.h" 10 #include "mem.h" 11 #include "utils/Range.h" 12 13 #include <cstdio> 14 15 using namespace pzstd; 16 SkippableFrame(std::uint32_t size)17SkippableFrame::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 tryRead(ByteRange bytes)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 } 31