grk::BufferedStream Struct Reference

`#include <BufferedStream.h>`

## Public Member Functions

| BufferedStream (uint8_t *buffer, size_t buffer_size, bool l_is_input)
grk_stream * | getWrapper (void)
void | setUserData (void *data, grk_stream_free_user_data_fn freeUserDataFun)
void * | getUserData (void)
void | setUserDataLength (uint64_t len)
uint32_t | getStatus (void)
void | setReadFunction (grk_stream_read_fn fn)
void | setZeroCopyReadFunction (grk_stream_zero_copy_read_fn fn)
void | setWriteFunction (grk_stream_write_fn fn)
void | setSeekFunction (grk_stream_seek_fn fn)
size_t | read (uint8_t *buffer, size_t p_size)
| Reads some bytes from the stream.
bool | writeShort (uint16_t value)
bool | write24 (uint32_t value)
bool | writeInt (uint32_t value)
bool | write64 (uint64_t value)
bool | writeByte (uint8_t value)
size_t | writeBytes (const uint8_t *buffer, size_t p_size)
| Write bytes to stream (no correction for endian!).
bool | flush ()
| Flush stream to disk.
bool | skip (int64_t p_size)
| Skip bytes in stream.
uint64_t | tell (void)
| Tells byte offset of stream (similar to ftell).
uint64_t | numBytesLeft (void)
| Get the number of bytes left before end of stream.
bool | seek (uint64_t offset)
| Seek bytes from the stream (absolute)
bool | hasSeek ()
| Check if stream is seekable.
bool | supportsZeroCopy ()
uint8_t * | getZeroCopyPtr ()
void | setFormat (GRK_CODEC_FORMAT format)
GRK_CODEC_FORMAT | getFormat (void)

## Static Public Member Functions

static BufferedStream * | getImpl (grk_stream *stream)

## Public Attributes

friend | GrkObjectWrapperImpl< BufferedStream >

## Private Member Functions

| ~BufferedStream ()
bool | write_skip (int64_t p_size)
| Skip bytes in write stream.
bool | read_skip (int64_t p_size)
| Skip bytes in read stream.
bool | read_seek (uint64_t offset)
| Absolute seek in read stream.
bool | write_seek (uint64_t offset)
| Absolute seek in write stream.
void | writeIncrement (size_t p_size)
template<typename TYPE >
bool | write (TYPE value, uint8_t numBytes)
void | invalidate_buffer ()
bool | isMemStream ()

## Private Attributes

grk_object | obj
void * | user_data_
| user data
grk_stream_free_user_data_fn | free_user_data_fn_
| Pointer to function to free user_data_ (nullptr at initialization) when destroying the stream.
uint64_t | user_data_length_
| User data length.
grk_stream_read_fn | read_fn_
| Pointer to actual read function (nullptr at initialization).
grk_stream_zero_copy_read_fn | zero_copy_read_fn_
| Pointer to actual zero copy read function (nullptr at initialization).
grk_stream_write_fn | write_fn_
| Pointer to actual write function (nullptr at initialization).
grk_stream_seek_fn | seek_fn_
| Pointer to actual seek function (if available).
uint32_t | status_
| Stream status flags.
grk_buf8 * | buf_
size_t | buffered_bytes_
size_t | read_bytes_seekable_
uint64_t | stream_offset_
GRK_CODEC_FORMAT | format_

## Constructor & Destructor Documentation

## BufferedStream()

grk::BufferedStream::BufferedStream | ( | uint8_t * | buffer,
|  | size_t | buffer_size,
|  | bool | l_is_input
| ) |  |

References buf_, grk::grk_read(), obj, and _grk_object::wrapper.

## ~BufferedStream()

grk::BufferedStream::~BufferedStream | ( |  | ) |

private

References buf_, free_user_data_fn_, and user_data_.

## Member Function Documentation

## flush()

bool grk::BufferedStream::flush | ( |  | ) |

Flush stream to disk.

Returns
  true if the data could be flushed, otherwise false.

References grk::grk_buf< T, A >::buf, buf_, buffered_bytes_, grk::grk_buf< T, A >::currPtr(), grk::GRK_ERROR(), grk::grk_read(), GROK_STREAM_STATUS_ERROR, grk::grk_buf< T, A >::incrementOffset(), isMemStream(), grk::grk_buf< T, A >::offset, read_bytes_seekable_, status_, user_data_, and write_fn_.

Referenced by write(), grk::CodeStreamCompress::write_eoc(), write_seek(), and writeBytes().

## getFormat()

GRK_CODEC_FORMAT grk::BufferedStream::getFormat | ( | void |  | ) |

References format_.

## getImpl()

BufferedStream * grk::BufferedStream::getImpl | ( | grk_stream * | stream | ) |

static

References _grk_object::wrapper.

Referenced by grk::get_mem_stream_offset(), grk_compress_create(), grk_decompress_create(), grk_stream_create_file_stream(), grk_stream_set_read_function(), grk_stream_set_seek_function(), grk_stream_set_user_data(), grk_stream_set_user_data_length(), grk_stream_set_write_function(), and grk::grk_stream_set_zero_copy_read_function().

## getStatus()

uint32_t grk::BufferedStream::getStatus | ( | void |  | ) |

References status_.

## getUserData()

void * grk::BufferedStream::getUserData | ( | void |  | ) |

References user_data_.

## getWrapper()

grk_stream * grk::BufferedStream::getWrapper | ( | void |  | ) |

References obj.

## getZeroCopyPtr()

uint8_t * grk::BufferedStream::getZeroCopyPtr | ( |  | ) |

References buf_, and grk::grk_buf< T, A >::currPtr().

Referenced by grk::TileProcessor::cacheTilePartPackets().

## hasSeek()

bool grk::BufferedStream::hasSeek | ( | void |  | ) |

Check if stream is seekable.

References seek_fn_.

## invalidate_buffer()

void grk::BufferedStream::invalidate_buffer | ( |  | ) |

private

References buf_, buffered_bytes_, GROK_STREAM_STATUS_INPUT, grk::grk_buf< T, A >::offset, read_bytes_seekable_, and status_.

Referenced by read(), read_seek(), and write_seek().

## isMemStream()

bool grk::BufferedStream::isMemStream | ( |  | ) |

private

References buf_, and grk::grk_buf< T, A >::owns_data.

Referenced by flush(), supportsZeroCopy(), write(), write_seek(), writeBytes(), and writeIncrement().

## numBytesLeft()

uint64_t grk::BufferedStream::numBytesLeft | ( | void |  | ) |

Get the number of bytes left before end of stream.

Returns
  Number of bytes left before the end of the stream.

References grk::grk_read(), stream_offset_, and user_data_length_.

Referenced by grk::TileProcessor::cacheTilePartPackets(), grk::CodeStreamDecompress::endOfCodeStream(), grk::CodeStreamDecompress::parseTileParts(), grk::CodeStreamDecompress::process_marker(), grk::FileFormatDecompress::read_box_hdr(), and grk::TileProcessor::setTilePartDataLength().

## read()

size_t grk::BufferedStream::read | ( | uint8_t * | buffer,
|  | size_t | p_size
| ) |  |

Reads some bytes from the stream.

Parameters

  buffer | pointer to the data buffer that will receive the data.
  p_size | number of bytes to read.

Returns
  the number of bytes read

References grk::grk_buf< T, A >::buf, buf_, buffered_bytes_, grk::grk_buf< T, A >::currPtr(), grk::GRK_ERROR(), grk::grk_read(), GROK_STREAM_STATUS_END, grk::grk_buf< T, A >::incrementOffset(), invalidate_buffer(), grk::grk_buf< T, A >::len, read_bytes_seekable_, read_fn_, status_, stream_offset_, supportsZeroCopy(), user_data_, and user_data_length_.

Referenced by grk::TileProcessor::cacheTilePartPackets(), grk::CodeStreamDecompress::process_marker(), grk::FileFormatDecompress::read_box_hdr(), grk::CodeStreamDecompress::read_short(), and grk::CodeStreamDecompress::read_soc().

## read_seek()

bool grk::BufferedStream::read_seek | ( | uint64_t | offset | ) |

private

Absolute seek in read stream.

Parameters

  offset | absolute offset

Returns
  true if successful, otherwise false

References grk::grk_buf< T, A >::buf, buf_, buffered_bytes_, grk::grk_buf< T, A >::currPtr(), grk::grk_read(), GROK_STREAM_STATUS_END, GROK_STREAM_STATUS_ERROR, grk::grk_buf< T, A >::incrementOffset(), invalidate_buffer(), read_bytes_seekable_, seek_fn_, status_, stream_offset_, user_data_, and user_data_length_.

Referenced by read_skip(), and seek().

## read_skip()

bool grk::BufferedStream::read_skip | ( | int64_t | p_size | ) |

private

Skip bytes in read stream.

Parameters

  p_size | the number of bytes to skip.

Returns
  true if successful, otherwise false

References grk::grk_read(), read_seek(), and stream_offset_.

Referenced by skip().

## seek()

bool grk::BufferedStream::seek | ( | uint64_t | offset | ) |

Seek bytes from the stream (absolute)

Parameters

  offset | the number of bytes to skip.

Returns
  true if successful, otherwise false

References GROK_STREAM_STATUS_INPUT, read_seek(), status_, and write_seek().

Referenced by grk::TileLengthMarkers::seek(), grk::CodeStreamInfo::seekFirstTilePart(), grk::SOTMarker::write_psot(), and grk::TileLengthMarkers::writeEnd().

## setFormat()

void grk::BufferedStream::setFormat | ( | GRK_CODEC_FORMAT | format | ) |

References format_.

## setReadFunction()

void grk::BufferedStream::setReadFunction | ( | grk_stream_read_fn | fn | ) |

References grk::grk_read(), and read_fn_.

## setSeekFunction()

void grk::BufferedStream::setSeekFunction | ( | grk_stream_seek_fn | fn | ) |

References grk::grk_read(), and seek_fn_.

## setUserData()

void grk::BufferedStream::setUserData | ( | void * | data,
|  | grk_stream_free_user_data_fn | freeUserDataFun
| ) |  |

References free_user_data_fn_, grk::grk_read(), and user_data_.

## setUserDataLength()

void grk::BufferedStream::setUserDataLength | ( | uint64_t | len | ) |

References user_data_length_.

## setWriteFunction()

void grk::BufferedStream::setWriteFunction | ( | grk_stream_write_fn | fn | ) |

References grk::grk_read(), and write_fn_.

## setZeroCopyReadFunction()

void grk::BufferedStream::setZeroCopyReadFunction | ( | grk_stream_zero_copy_read_fn | fn | ) |

References grk::grk_read(), and zero_copy_read_fn_.

## skip()

bool grk::BufferedStream::skip | ( | int64_t | p_size | ) |

Skip bytes in stream.

Parameters

  p_size | the number of bytes to skip.

Returns
  true if successful, otherwise false

References grk::grk_read(), GROK_STREAM_STATUS_INPUT, read_skip(), status_, and write_skip().

Referenced by grk::CodeStreamDecompress::parseTileParts(), and grk::TileLengthMarkers::writeBegin().

## supportsZeroCopy()

bool grk::BufferedStream::supportsZeroCopy | ( |  | ) |

References GROK_STREAM_STATUS_INPUT, isMemStream(), and status_.

Referenced by grk::TileProcessor::cacheTilePartPackets(), and read().

## tell()

uint64_t grk::BufferedStream::tell | ( | void |  | ) |

Tells byte offset of stream (similar to ftell).

Returns
  the current position of the stream.

References stream_offset_.

Referenced by grk::CodeStreamCompress::cacheEndOfHeader(), grk::TileProcessor::cacheTilePartPackets(), grk::T2Compress::compressPacket(), grk::CodeStreamDecompress::nextTLM(), grk::CodeStreamDecompress::parseTileParts(), grk::CodeStreamDecompress::read_soc(), grk::CodeStreamDecompress::read_unk(), grk::CodeStreamDecompress::readHeaderProcedureImpl(), grk::TileLengthMarkers::seek(), grk::CodeStreamCompress::updateRates(), grk::SOTMarker::write_psot(), grk::TileLengthMarkers::writeBegin(), grk::TileLengthMarkers::writeEnd(), and grk::CodeStreamCompress::writeTilePart().

## write()

template<typename TYPE >

bool grk::BufferedStream::write | ( | TYPE | value,
|  | uint8_t | numBytes
| ) |  |

private

References buf_, buffered_bytes_, grk::grk_buf< T, A >::currPtr(), flush(), grk::grk_read(), grk::grk_write(), GROK_STREAM_STATUS_ERROR, isMemStream(), grk::grk_buf< T, A >::len, seek_fn_, status_, stream_offset_, user_data_, and writeIncrement().

## write24()

bool grk::BufferedStream::write24 | ( | uint32_t | value | ) |

References grk::grk_read().

Referenced by grk::CodeStreamCompress::write_mcc_record().

## write64()

bool grk::BufferedStream::write64 | ( | uint64_t | value | ) |

References grk::grk_read().

## write_seek()

bool grk::BufferedStream::write_seek | ( | uint64_t | offset | ) |

private

Absolute seek in write stream.

Parameters

  offset | absolute offset

Returns
  true if successful, otherwise false

References buf_, flush(), GROK_STREAM_STATUS_ERROR, invalidate_buffer(), isMemStream(), grk::grk_buf< T, A >::offset, seek_fn_, status_, stream_offset_, and user_data_.

Referenced by seek(), and write_skip().

## write_skip()

bool grk::BufferedStream::write_skip | ( | int64_t | p_size | ) |

private

Skip bytes in write stream.

Parameters

  p_size | the number of bytes to skip.

Returns
  true if successful, otherwise false

References grk::grk_read(), stream_offset_, and write_seek().

Referenced by skip().

## writeByte()

bool grk::BufferedStream::writeByte | ( | uint8_t | value | ) |

References writeBytes().

Referenced by grk::T2Compress::compressPacket(), grk::SIZMarker::write(), grk::CodeStreamCompress::write_cbd(), grk::CodeStreamCompress::write_coc(), grk::CodeStreamCompress::write_cod(), grk::CodeStreamCompress::write_mcc_record(), grk::CodeStreamCompress::write_mco(), grk::CodeStreamCompress::write_qcc(), grk::CodeStreamCompress::write_rgn(), grk::CodeStreamCompress::write_SPCod_SPCoc(), grk::CodeStreamCompress::write_SQcd_SQcc(), grk::TileLengthMarkers::writeBegin(), grk::BitIO::writeByte(), and grk::CodeStreamCompress::writePoc().

## writeBytes()

size_t grk::BufferedStream::writeBytes | ( | const uint8_t * | buffer,
|  | size_t | p_size
| ) |  |

Write bytes to stream (no correction for endian!).

Parameters

  buffer | pointer to the data buffer holds the data to be written.
  p_size | number of bytes to write.

Returns
  the number of bytes written

References buf_, buffered_bytes_, grk::grk_buf< T, A >::currPtr(), flush(), grk::grk_read(), GROK_STREAM_STATUS_ERROR, isMemStream(), grk::grk_buf< T, A >::len, grk::grk_buf< T, A >::offset, status_, stream_offset_, user_data_, write_fn_, and writeIncrement().

Referenced by grk::T2Compress::compressPacket(), grk::PLMarkerMgr::write(), grk::CodeStreamCompress::write_com(), grk::CodeStreamCompress::write_mct_record(), and writeByte().

## writeIncrement()

void grk::BufferedStream::writeIncrement | ( | size_t | p_size | ) |

private

References buf_, buffered_bytes_, grk::grk_read(), grk::grk_buf< T, A >::incrementOffset(), isMemStream(), and stream_offset_.

Referenced by write(), and writeBytes().

## writeInt()

bool grk::BufferedStream::writeInt | ( | uint32_t | value | ) |

References grk::grk_read().

Referenced by grk::SIZMarker::write(), ojph::QuantizerOJPH::write(), openhtj2k::QuantizerOpenHTJ2K::write(), grk::SOTMarker::write_psot(), and grk::TileLengthMarkers::writeEnd().

## writeShort()

bool grk::BufferedStream::writeShort | ( | uint16_t | value | ) |

References grk::grk_read().

Referenced by grk::SIZMarker::write(), ojph::QuantizerOJPH::write(), openhtj2k::QuantizerOpenHTJ2K::write(), grk::PLMarkerMgr::write(), grk::CodeStreamCompress::write_cbd(), grk::CodeStreamCompress::write_coc(), grk::CodeStreamCompress::write_cod(), grk::CodeStreamCompress::write_com(), grk::CodeStreamCompress::write_eoc(), grk::CodeStreamCompress::write_mcc_record(), grk::CodeStreamCompress::write_mco(), grk::CodeStreamCompress::write_mct_record(), grk::CodeStreamCompress::write_qcc(), grk::CodeStreamCompress::write_qcd(), grk::CodeStreamCompress::write_rgn(), grk::CodeStreamCompress::write_soc(), grk::CodeStreamCompress::write_SQcd_SQcc(), grk::TileLengthMarkers::writeBegin(), grk::TileLengthMarkers::writeEnd(), grk::CodeStreamCompress::writePoc(), and grk::TileProcessor::writeTilePartT2().

## Member Data Documentation

## buf_

grk_buf8* grk::BufferedStream::buf_

private

Referenced by BufferedStream(), flush(), getZeroCopyPtr(), invalidate_buffer(), isMemStream(), read(), read_seek(), write(), write_seek(), writeBytes(), writeIncrement(), and ~BufferedStream().

## buffered_bytes_

size_t grk::BufferedStream::buffered_bytes_

private

Referenced by flush(), invalidate_buffer(), read(), read_seek(), write(), writeBytes(), and writeIncrement().

## format_

GRK_CODEC_FORMAT grk::BufferedStream::format_

private

Referenced by getFormat(), and setFormat().

## free_user_data_fn_

grk_stream_free_user_data_fn grk::BufferedStream::free_user_data_fn_

private

Pointer to function to free user_data_ (nullptr at initialization) when destroying the stream.

If pointer is nullptr the function is not called and the user_data_ is not freed (even if it isn't nullptr).

Referenced by setUserData(), and ~BufferedStream().

## GrkObjectWrapperImpl< BufferedStream >

friend grk::BufferedStream::GrkObjectWrapperImpl< BufferedStream >

## obj

grk_object grk::BufferedStream::obj

private

Referenced by BufferedStream(), and getWrapper().

## read_bytes_seekable_

size_t grk::BufferedStream::read_bytes_seekable_

private

Referenced by flush(), invalidate_buffer(), read(), and read_seek().

## read_fn_

grk_stream_read_fn grk::BufferedStream::read_fn_

private

Pointer to actual read function (nullptr at initialization).

Referenced by read(), and setReadFunction().

## seek_fn_

grk_stream_seek_fn grk::BufferedStream::seek_fn_

private

Pointer to actual seek function (if available).

Referenced by hasSeek(), read_seek(), setSeekFunction(), write(), and write_seek().

## status_

uint32_t grk::BufferedStream::status_

private

Stream status flags.

Referenced by flush(), getStatus(), invalidate_buffer(), read(), read_seek(), seek(), skip(), supportsZeroCopy(), write(), write_seek(), and writeBytes().

## stream_offset_

uint64_t grk::BufferedStream::stream_offset_

private

Referenced by numBytesLeft(), read(), read_seek(), read_skip(), tell(), write(), write_seek(), write_skip(), writeBytes(), and writeIncrement().

## user_data_

void* grk::BufferedStream::user_data_

private

user data

Referenced by flush(), getUserData(), read(), read_seek(), setUserData(), write(), write_seek(), writeBytes(), and ~BufferedStream().

## user_data_length_

uint64_t grk::BufferedStream::user_data_length_

private

User data length.

Currently set to size of file for file read stream, and size of buffer for buffer read/write stream

Referenced by numBytesLeft(), read(), read_seek(), and setUserDataLength().

## write_fn_

grk_stream_write_fn grk::BufferedStream::write_fn_

private

Pointer to actual write function (nullptr at initialization).

Referenced by flush(), setWriteFunction(), and writeBytes().

## zero_copy_read_fn_

grk_stream_zero_copy_read_fn grk::BufferedStream::zero_copy_read_fn_

private

Pointer to actual zero copy read function (nullptr at initialization).

Referenced by setZeroCopyReadFunction().

The documentation for this struct was generated from the following files:

- BufferedStream.h
- BufferedStream.cpp