• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Copyright 2017 PDFium Authors. All rights reserved.
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 <stdint.h>
11 
12 #include "core/fxcrt/unowned_ptr.h"
13 #include "third_party/base/span.h"
14 
15 class CFX_BitStream {
16  public:
17   explicit CFX_BitStream(pdfium::span<const uint8_t> pData);
18   ~CFX_BitStream();
19 
20   void ByteAlign();
21 
IsEOF()22   bool IsEOF() const { return m_BitPos >= m_BitSize; }
GetPos()23   uint32_t GetPos() const { return m_BitPos; }
24   uint32_t GetBits(uint32_t nBits);
25 
SkipBits(uint32_t nBits)26   void SkipBits(uint32_t nBits) { m_BitPos += nBits; }
Rewind()27   void Rewind() { m_BitPos = 0; }
28 
BitsRemaining()29   uint32_t BitsRemaining() const {
30     return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0;
31   }
32 
33  private:
34   uint32_t m_BitPos;
35   uint32_t m_BitSize;
36   UnownedPtr<const uint8_t> m_pData;
37 };
38 
39 #endif  // CORE_FXCRT_CFX_BITSTREAM_H_
40