blob: baa2a9f5443e32f21c873d48a47eb02dea60cebe [file] [log] [blame]
Dan Sinclairccd5be02017-08-30 13:23:44 -04001// 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
Dan Sinclairaee0db02017-09-21 16:53:58 -040012#include "core/fxcrt/unowned_ptr.h"
Tom Sepez53894392018-04-09 18:30:24 +000013#include "third_party/base/span.h"
Dan Sinclairccd5be02017-08-30 13:23:44 -040014
15class CFX_BitStream {
16 public:
Tom Sepez53894392018-04-09 18:30:24 +000017 explicit CFX_BitStream(pdfium::span<const uint8_t> pData);
Dan Sinclairccd5be02017-08-30 13:23:44 -040018 ~CFX_BitStream();
19
20 void ByteAlign();
21
22 bool IsEOF() const { return m_BitPos >= m_BitSize; }
23 uint32_t GetPos() const { return m_BitPos; }
24 uint32_t GetBits(uint32_t nBits);
25
26 void SkipBits(uint32_t nBits) { m_BitPos += nBits; }
27 void Rewind() { m_BitPos = 0; }
28
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;
Dan Sinclairaee0db02017-09-21 16:53:58 -040036 UnownedPtr<const uint8_t> m_pData;
Dan Sinclairccd5be02017-08-30 13:23:44 -040037};
38
39#endif // CORE_FXCRT_CFX_BITSTREAM_H_