Debian Codegraph @

modules/lsp-runtime-lib/include/lsp-plug.in/fmt/lspc/ChunkReader.h

raw
1 /*
2 * Copyright (C) 2020 Linux Studio Plugins Project <https://lsp-plug.in/>
3 * (C) 2020 Vladimir Sadovnikov <[email protected]>
4 *
5 * This file is part of lsp-runtime-lib
6 * Created on: 14 янв. 2018 г.
7 *
8 * lsp-runtime-lib is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU Lesser General Public License as published by
10 * the Free Software Foundation, either version 3 of the License, or
11 * any later version.
12 *
13 * lsp-runtime-lib is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public License
19 * along with lsp-runtime-lib. If not, see <https://www.gnu.org/licenses/>.
20 */
21
22 #ifndef LSP_PLUG_IN_FMT_LSPC_CHUNKREADER_H_
23 #define LSP_PLUG_IN_FMT_LSPC_CHUNKREADER_H_
24
25 #include <lsp-plug.in/runtime/version.h>
26 #include <lsp-plug.in/fmt/lspc/ChunkAccessor.h>
27 #include <lsp-plug.in/fmt/lspc/ChunkReaderStream.h>
28
29 namespace lsp
30 {
31 namespace lspc
32 {
33 class ChunkReader: public ChunkAccessor
34 {
35 private:
36 ChunkReader & operator = (const ChunkReader &);
37
38 protected:
39 friend class File;
40
41 protected:
42 uint32_t nUnread; // Number of bytes still not read from chunk
43 size_t nBufTail; // Buffer tail
44 wsize_t nFileOff; // File read offset
45 wssize_t nPosition; // Actual read position
46 bool bLast; // Indicator of the last chunk
47 ChunkReaderStream sStream; // The stream interface
48
49 protected:
50 explicit ChunkReader(Resource *fd, uint32_t magic, uint32_t uid);
51
52 public:
53 virtual ~ChunkReader();
54
55 public:
56 /**
57 * Obtain access to chunk reader as a stream.
58 * @return pointer to the stream
59 */
60 inline io::IInStream *stream() { return &sStream; }
61
62 /**
63 * Get current read position in bytes
64 * @return actual position from the beginning of the chunk including header
65 */
66 inline wssize_t position() const { return nPosition; }
67
68 public:
69 /**
70 * Read chunk data header from LSPC chunk. Header should contain lspc_header_t at
71 * the beginning.
72 * @param hdr the header data to store
73 * @param size the size of header, should be at least sizeof(lspc_header_t)
74 * @return status of operation or error code (negative)
75 */
76 virtual ssize_t read_header(void *hdr, size_t size);
77
78 /**
79 * Read regular data from LSPC chunk.
80 * @param buf the pointer to store data
81 * @param count number of bytes to read
82 * @return number of bytes read or error code (negative)
83 */
84 virtual ssize_t read(void *buf, size_t count);
85
86 /**
87 * Skip some amount of data
88 * @param count amount of bytes to skip
89 * @return number of skipped bytes or error code (negative)
90 */
91 virtual ssize_t skip(size_t count);
92 };
93 }
94
95 } /* namespace lsp */
96
97 #endif /* LSP_PLUG_IN_FMT_LSPC_CHUNKREADER_H_ */