// SPDX-FileCopyrightText: 2010 Dominik Seichter <domseichter@web.de>
// SPDX-FileCopyrightText: 2020 Francesco Pretto <ceztko@gmail.com>
// SPDX-License-Identifier: LGPL-2.0-or-later OR MPL-2.0

#ifndef PDF_OBJECT_STREAM_PARSER_OBJECT_H
#define PDF_OBJECT_STREAM_PARSER_OBJECT_H

#include "PdfParserObject.h"

namespace PoDoFo {

class PdfEncrypt;
class PdfIndirectObjectList;

/// A utility class for PdfParser that can parse
/// an object stream object (PDF Reference 1.7 3.4.6 Object Streams)
///
/// It is mainly here to make PdfParser more modular.
class PdfObjectStreamParser
{
public:
    /// Create a new PdfObjectStreamParserObject from an existing
    /// PdfParserObject. The PdfParserObject will be removed and deleted.
    /// All objects from the object stream will be read into memory.
    ///
    /// @param parser PdfParserObject for an object stream
    /// @param objects add loaded objects to this vector of objects
    /// @param buffer use this allocated buffer for caching
    PdfObjectStreamParser(PdfParserObject& parser, PdfIndirectObjectList& objects, const std::shared_ptr<charbuff>& buffer);

    void Parse(const std::unordered_set<uint32_t>* objectList);

private:
    void readObjectsFromStream(char* buffer, size_t bufferLen,
        unsigned num, size_t first, const std::unordered_set<uint32_t>* objectList);

private:
    PdfParserObject* m_Parser;
    PdfIndirectObjectList* m_Objects;
    std::shared_ptr<charbuff> m_buffer;
};

};

#endif // PDF_OBJECT_STREAM_PARSER_OBJECT_H
