summaryrefslogtreecommitdiff
path: root/core/fxcrt/cfx_bitstream.h
blob: 168760ddd83ad843276ec49e7e1c099ea5a3af22 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
// Copyright 2017 PDFium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// Original code copyright 2014 Foxit Software Inc. http://www.foxitsoftware.com

#ifndef CORE_FXCRT_CFX_BITSTREAM_H_
#define CORE_FXCRT_CFX_BITSTREAM_H_

#include <stdint.h>

#include "core/fxcrt/unowned_ptr.h"

class CFX_BitStream {
 public:
  CFX_BitStream(const uint8_t* pData, uint32_t dwSize);
  ~CFX_BitStream();

  void ByteAlign();

  bool IsEOF() const { return m_BitPos >= m_BitSize; }
  uint32_t GetPos() const { return m_BitPos; }
  uint32_t GetBits(uint32_t nBits);

  void SkipBits(uint32_t nBits) { m_BitPos += nBits; }
  void Rewind() { m_BitPos = 0; }

  uint32_t BitsRemaining() const {
    return m_BitSize >= m_BitPos ? m_BitSize - m_BitPos : 0;
  }

 private:
  uint32_t m_BitPos;
  uint32_t m_BitSize;
  UnownedPtr<const uint8_t> m_pData;
};

#endif  // CORE_FXCRT_CFX_BITSTREAM_H_