1 // Copyright 2017 The PDFium Authors 2 // Use of this source code is governed by a BSD-style license that can be 3 // found in the LICENSE file. 4 5 // Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com 6 7 #ifndef CORE_FXCRT_CFX_BITSTREAM_H_ 8 #define CORE_FXCRT_CFX_BITSTREAM_H_ 9 10 #include <stddef.h> 11 #include <stdint.h> 12 13 #include "core/fxcrt/raw_span.h" 14 #include "core/fxcrt/span.h" 15 16 class CFX_BitStream { 17 public: 18 explicit CFX_BitStream(pdfium::span<const uint8_t> pData); 19 ~CFX_BitStream(); 20 21 void ByteAlign(); 22 IsEOF()23 bool IsEOF() const { return m_BitPos >= m_BitSize; } GetPos()24 size_t GetPos() const { return m_BitPos; } 25 uint32_t GetBits(uint32_t nBits); 26 SkipBits(size_t nBits)27 void SkipBits(size_t nBits) { m_BitPos += nBits; } Rewind()28 void Rewind() { m_BitPos = 0; } 29 BitsRemaining()30 size_t BitsRemaining() const { 31 return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0; 32 } 33 34 private: 35 size_t m_BitPos = 0; 36 const size_t m_BitSize; 37 pdfium::raw_span<const uint8_t> const m_pData; 38 }; 39 40 #endif // CORE_FXCRT_CFX_BITSTREAM_H_ 41