xref: /aosp_15_r20/external/pdfium/core/fxcrt/cfx_read_only_vector_stream.h (revision 3ac0a46f773bac49fa9476ec2b1cf3f8da5ec3a4)
1 // Copyright 2022 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 #ifndef CORE_FXCRT_CFX_READ_ONLY_VECTOR_STREAM_H_
6 #define CORE_FXCRT_CFX_READ_ONLY_VECTOR_STREAM_H_
7 
8 #include <stdint.h>
9 
10 #include "core/fxcrt/data_vector.h"
11 #include "core/fxcrt/fixed_uninit_data_vector.h"
12 #include "core/fxcrt/fx_stream.h"
13 #include "core/fxcrt/retain_ptr.h"
14 
15 class CFX_ReadOnlySpanStream;
16 
17 class CFX_ReadOnlyVectorStream final : public IFX_SeekableReadStream {
18  public:
19   CONSTRUCT_VIA_MAKE_RETAIN;
20 
21   // IFX_SeekableReadStream:
22   FX_FILESIZE GetSize() override;
23   bool ReadBlockAtOffset(pdfium::span<uint8_t> buffer,
24                          FX_FILESIZE offset) override;
25 
26  private:
27   explicit CFX_ReadOnlyVectorStream(DataVector<uint8_t> data);
28   explicit CFX_ReadOnlyVectorStream(FixedUninitDataVector<uint8_t> data);
29   ~CFX_ReadOnlyVectorStream() override;
30 
31   const DataVector<uint8_t> data_;
32   const FixedUninitDataVector<uint8_t> fixed_data_;
33   // Spans over either `data_` or `fixed_data_`.
34   const RetainPtr<CFX_ReadOnlySpanStream> stream_;
35 };
36 
37 #endif  // CORE_FXCRT_CFX_READ_ONLY_VECTOR_STREAM_H_
38