5#include "core/fxcodec/cfx_codec_memory.h"
9#include "core/fxcrt/span_util.h"
11CFX_CodecMemory::CFX_CodecMemory(size_t buffer_size)
12 : buffer_(FX_Alloc(uint8_t, buffer_size)), size_(buffer_size) {}
16bool CFX_CodecMemory::
Seek(size_t pos) {
28 size_t bytes_to_read = std::min(buffer.size(), size_ - pos_);
29 fxcrt::spancpy(buffer, GetBufferSpan().subspan(pos_, bytes_to_read));
30 pos_ += bytes_to_read;
34bool CFX_CodecMemory::
TryResize(size_t new_buffer_size) {
35 uint8_t* pOldBuf = buffer_.release();
36 uint8_t* pNewBuf = FX_TryRealloc(uint8_t, pOldBuf, new_buffer_size);
37 if (new_buffer_size && !pNewBuf) {
38 buffer_.reset(pOldBuf);
41 buffer_.reset(pNewBuf);
42 size_ = new_buffer_size;
46void CFX_CodecMemory::
Consume(size_t consumed) {
47 fxcrt::spanmove(GetBufferSpan(), GetBufferSpan().subspan(consumed));
bool TryResize(size_t new_buffer_size)
~CFX_CodecMemory() override
size_t ReadBlock(pdfium::span< uint8_t > buffer)
void Consume(size_t consumed)