Grok  7.6.0
ChunkBuffer.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016-2020 Grok Image Compression Inc.
3  *
4  * This source code is free software: you can redistribute it and/or modify
5  * it under the terms of the GNU Affero General Public License, version 3,
6  * as published by the Free Software Foundation.
7  *
8  * This source code is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU Affero General Public License for more details.
12  *
13  * You should have received a copy of the GNU Affero General Public License
14  * along with this program. If not, see <http://www.gnu.org/licenses/>.
15  *
16  */
17 
18 #include <vector>
19 
20 #pragma once
21 namespace grk {
22 
23 /* ChunkBuffer
24 
25  Store a list of buffers, or chunks, which can be treated as one single
26  contiguous buffer.
27 
28  */
29 struct ChunkBuffer {
32 
33  /*
34  Wrap existing array and add to the back of the chunk buffer.
35  */
36  bool push_back(uint8_t *buf, size_t len);
37 
38  /*
39  Allocate array and add to the back of the chunk buffer
40  */
41  bool alloc_and_push_back(size_t len);
42 
43  /*
44  Increment offset of current chunk
45  */
46  void incr_cur_chunk_offset(size_t offset);
47 
48  /*
49  Get length of current chunk
50  */
51  size_t get_cur_chunk_len(void);
52 
53  /*
54  Get offset of current chunk
55  */
56  size_t get_cur_chunk_offset(void);
57 
58  /*
59  Treat segmented buffer as single contiguous buffer, and get current pointer
60  */
61  uint8_t* get_global_ptr(void);
62 
63  /*
64  Treat segmented buffer as single contiguous buffer, and get current offset
65  */
66  size_t get_global_offset(void);
67 
68  /*
69  Reset all offsets to zero, and set current chunk to beginning of list
70  */
71  void rewind(void);
72 
73  size_t skip(size_t nb_bytes);
74 
75  void increment(void);
76 
77  size_t read(void *p_buffer, size_t nb_bytes);
78 
79  grk_buf* add_chunk(uint8_t *buf, size_t len, bool ownsData);
80  void add_chunk(grk_buf *chunk);
81 
82  /*
83  Copy all chunks, in sequence, into contiguous array
84  */
85  bool copy_to_contiguous_buffer(uint8_t *buffer);
86 
87  /*
88  Clean up internal resources
89  */
90  void cleanup(void);
91 
92  /*
93  Return current pointer, stored in ptr variable, and advance chunk buffer
94  offset by chunk_len
95  */
96  bool zero_copy_read(uint8_t **ptr, size_t chunk_len);
97 
98  size_t data_len; /* total length of all chunks*/
99  size_t cur_chunk_id; /* current index into chunk vector */
100  std::vector<grk_buf*> chunks;
101 };
102 
103 }
grk::ChunkBuffer::cur_chunk_id
size_t cur_chunk_id
Definition: ChunkBuffer.h:99
grk::grk_buffer
Definition: util.h:209
grk::ChunkBuffer::cleanup
void cleanup(void)
grk::ChunkBuffer::read
size_t read(void *p_buffer, size_t nb_bytes)
grk::ChunkBuffer::get_cur_chunk_offset
size_t get_cur_chunk_offset(void)
grk::ChunkBuffer::chunks
std::vector< grk_buf * > chunks
Definition: ChunkBuffer.h:100
grk::ChunkBuffer::increment
void increment(void)
grk::ChunkBuffer::add_chunk
grk_buf * add_chunk(uint8_t *buf, size_t len, bool ownsData)
grk::ChunkBuffer::skip
size_t skip(size_t nb_bytes)
grk::ChunkBuffer::get_global_offset
size_t get_global_offset(void)
grk::ChunkBuffer::copy_to_contiguous_buffer
bool copy_to_contiguous_buffer(uint8_t *buffer)
grk::ChunkBuffer::data_len
size_t data_len
Definition: ChunkBuffer.h:98
grk
Copyright (C) 2016-2020 Grok Image Compression Inc.
Definition: BitIO.h:27
grk::ChunkBuffer::push_back
bool push_back(uint8_t *buf, size_t len)
grk::ChunkBuffer::alloc_and_push_back
bool alloc_and_push_back(size_t len)
grk::ChunkBuffer::~ChunkBuffer
~ChunkBuffer()
grk::ChunkBuffer::rewind
void rewind(void)
grk::ChunkBuffer::add_chunk
void add_chunk(grk_buf *chunk)
grk::ChunkBuffer::get_cur_chunk_len
size_t get_cur_chunk_len(void)
grk::ChunkBuffer
Definition: ChunkBuffer.h:29
grk::ChunkBuffer::get_global_ptr
uint8_t * get_global_ptr(void)
grk::ChunkBuffer::incr_cur_chunk_offset
void incr_cur_chunk_offset(size_t offset)
grk::ChunkBuffer::ChunkBuffer
ChunkBuffer()
grk::ChunkBuffer::zero_copy_read
bool zero_copy_read(uint8_t **ptr, size_t chunk_len)