Dan Sinclair | ccd5be0 | 2017-08-30 13:23:44 -0400 | [diff] [blame] | 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 | |
Dan Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 12 | #include "core/fxcrt/unowned_ptr.h" |
Tom Sepez | 5389439 | 2018-04-09 18:30:24 +0000 | [diff] [blame] | 13 | #include "third_party/base/span.h" |
Dan Sinclair | ccd5be0 | 2017-08-30 13:23:44 -0400 | [diff] [blame] | 14 | |
| 15 | class CFX_BitStream { |
| 16 | public: |
Tom Sepez | 5389439 | 2018-04-09 18:30:24 +0000 | [diff] [blame] | 17 | explicit CFX_BitStream(pdfium::span<const uint8_t> pData); |
Dan Sinclair | ccd5be0 | 2017-08-30 13:23:44 -0400 | [diff] [blame] | 18 | ~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 Sinclair | aee0db0 | 2017-09-21 16:53:58 -0400 | [diff] [blame] | 36 | UnownedPtr<const uint8_t> m_pData; |
Dan Sinclair | ccd5be0 | 2017-08-30 13:23:44 -0400 | [diff] [blame] | 37 | }; |
| 38 | |
| 39 | #endif // CORE_FXCRT_CFX_BITSTREAM_H_ |